Commands to run application:
- terraform init
- terraform apply -target="module.vpc"
- terraform apply
Commands explanation
- Init the directory andconfigurations
- Run VPC modul first so we are sure that the subnets are ready for next resources/modules
- Run rest of the code
Code:
- First we create VPC with three subnets with ip range 10.0.x.x
- Then we set up launch config for instances and add the to Auto scaling group, for which we also set up a schedule and add it to Target group
- then we set up a Network load balancer and it's listener on port 80 and also add it to Auto scaling group. For the NLB I set the create wait time to 10 minutes so the program has time to set it as it take a bit of time to finish.