- Write an exercise in Terraform to create the below resources in AWS.
1. Create VPC: A VPC named CloudIQ-Sample-VPC has been created with CIDR range 172.0.0.0/16
2. Private Subnets: 2 private subnets are created.
3. Public Subnets: 2 public subnets are created.
4. EC2 Instances: t2.micro instances created in all the subnets.
5. Internet Gateway: Since our public subnets have resources like EC2 instances, we will be allowing our resources to connect to the internet.
6. Route Table: Each subnet should be associated with a route table to control network traffic.
Step 1: terraform init:
- Initializes terraform environment and plugins
- A hidden folder called .terraform will be generated, it contains all the plugins for your platform
Step 2: terraform validate:
- To reformat your code and run some basic validations.
Step 3: terraform plan:
- The terraform plan command creates an execution plan, which lets you preview the changes that Terraform plans to make to your infrastructure.
Step 4: terraform apply
Step 5: terraform destroy
- This will destroy all the resources/objects created in the AWS console and will help tear down the environment.