This project "formacao-sre-ec2-iac" is about creating an EC2 instance infrastructure as code using Terraform, along with a security group and Elastic IP. The project also includes Ansible files for provisioning the instance and running Prometheus and Docker Compose with Wordpress. The project is structured into two main folders: "01-tf" for the Terraform code and "02-ansible" for the Ansible files. When the Terraform apply command is executed in the "01-tf" folder, the necessary files are dynamically generated with the information of the new EC2 instance created for the execution of Ansible and Docker Compose in the "02-ansible" folder.
The project contains two main folders, separating the terraform HCL source code that provisions the EC2 instance with the security group, Elastic Ip and ansible files:
- 01-tf
- 02-ansible
As soon as the terraform apply command is applied inside the 01-tf
folder, the necessary files are dynamically generated with the information of the new EC2 instance created for the execution of ansible and docker compose in the 02-ansible
folder (dynamic files generated in the 01-tf/local_files_ansible.tf
).
To run this example you need to execute:
$ cd 01-tf/
$ terraform init
$ terraform plan
$ terraform apply
To run this example you need to execute:
$ cd 02-ansible/
$ ansible-galaxy collection install community.general
$ ansible-galaxy collection install prometheus.prometheus
$ ansible-playbook playbook_wordpress.yaml
No requirements.
Name | Version |
---|---|
aws | 5.23.1 |
local | 2.4.0 |
tls | 4.0.4 |
Name | Source | Version |
---|---|---|
wordpress_ec2_instance | terraform-aws-modules/ec2-instance/aws | n/a |
Name | Type |
---|---|
aws_eip.wordpress_eip | resource |
aws_iam_instance_profile.wordpress_instance_profile | resource |
aws_iam_policy_attachment.example | resource |
aws_iam_role.wordpress_role | resource |
aws_key_pair.server | resource |
aws_security_group.allow_prometheus_port | resource |
aws_security_group.allow_ssh | resource |
aws_security_group.allow_wordpress_ports | resource |
local_file.ansible_docker_compose | resource |
local_file.ansible_hosts | resource |
local_file.ansible_vars_default | resource |
local_file.server_wordpress_key | resource |
tls_private_key.ssh | resource |
aws_ami.wordpress_ami | data source |
aws_secretsmanager_secret_version.wp_password_secret_version | data source |
aws_ssm_parameter.aws_secretsmanager_secret | data source |
aws_ssm_parameter.wp_db_url | data source |
aws_subnet.wordpress_public_subnet | data source |
aws_vpc.wordpress_vpc | data source |
Name | Description | Type | Default | Required |
---|---|---|---|---|
admin_user | n/a | string |
n/a | yes |
ami_name | n/a | list(string) |
n/a | yes |
ami_owner | n/a | list(string) |
n/a | yes |
docker_compose_project_path | n/a | string |
n/a | yes |
docker_compose_url | n/a | string |
n/a | yes |
docker_gpg_url | n/a | string |
n/a | yes |
docker_packages | n/a | list(string) |
n/a | yes |
docker_repo | n/a | string |
n/a | yes |
iam_instance_profile | n/a | string |
n/a | yes |
iam_role | n/a | string |
n/a | yes |
instance_type | n/a | string |
n/a | yes |
key_name | n/a | string |
n/a | yes |
monitoring | n/a | bool |
n/a | yes |
project_required_packages | n/a | list(string) |
n/a | yes |
prometheus_port | n/a | number |
n/a | yes |
prometheus_version | n/a | string |
n/a | yes |
python_docker_modules | n/a | list(string) |
n/a | yes |
server_wordpress_key_filename | n/a | string |
n/a | yes |
sg_cidr_blocks | n/a | list(string) |
n/a | yes |
vpc_name | n/a | list(string) |
n/a | yes |
vpc_public_subnet | n/a | list(string) |
n/a | yes |
wordpress_db_name | n/a | string |
n/a | yes |
wordpress_db_port | n/a | number |
n/a | yes |
wordpress_db_user | n/a | string |
n/a | yes |
wordpress_image | n/a | string |
n/a | yes |
wordpress_port | n/a | number |
n/a | yes |
Name | Description |
---|---|
prometheus_aws_elastic_ip | Public IP address of the prometheus port. Access with the HTTP protocol. Example: http://44.206.118.193:9090 |
wordpress_aws_elastic_ip | Public IP and PORT of the wordpress instance. Access with the HTTP protocol. Example: http://44.206.118.193:80 |