paulosobral / formacao-sre-ec2-iac

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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Formação SRE EC2 IaC

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.

project folder structure

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:

  1. 01-tf
  2. 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).

01-tf Project

Usage

To run this example you need to execute:

$ cd 01-tf/
$ terraform init
$ terraform plan
$ terraform apply

02-ansible

Usage

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

Requirements

No requirements.

Providers

Name Version
aws 5.23.1
local 2.4.0
tls 4.0.4

Modules

Name Source Version
wordpress_ec2_instance terraform-aws-modules/ec2-instance/aws n/a

Resources

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

Inputs

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

Outputs

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

image AWS Terraform Ansible Ubuntu Docker

About

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.


Languages

Language:HCL 100.0%