How to create 1 ALB external and 2 EC2 ECS-NGINX with Terraform

First let’s set up our provider:

We creates a new VPC:

We have the configuration for the Application Load Balancer:

We set the AMI that will update and launch configuration of the cluster:

Adding the configuration for our ECS cluster:

And the tpl file:

Adding our ECS service and task and Cloud Watch configurations:

Adding the IAM roles for the EC2 instances so they can communicate with the ECS service:

We can see that the load balancer is open to the world on tcp/80 and tcp/443 and the ECS EC2 instances have ports 32768 to 65535 open from the load balancer. This is because when we select the container port to 0 in the task definition AWS will randomly assign a port from this range to the container:

We have our variables file:

Also you can go to my personal GIT on Vasile Minica / Creating-1-ALB-external-and-2-EC2-ECS-NGINX-with-Terraform · GitLab