Adding multiple resources
- Terraform count meta argument helps in creating multiple number of resources Refer Here
- syntax
resource '...' '...' {
count = 5
....
}
- When you are accessing resources we need to use index
- Example
resource 'aws_subnet' 'subnets {
count = 3
}
# aws_subnets[0] => 1 subnet
# aws_subnets[2] => 3 subnet
- Refer Here for the changes to add multiple subnets
-
Aws has a concept of public and private subnets
Lets create private and public subnets
- To make subnet public:
- It should be associated with a route table which has route to internet gateway
-
To make subnet private:
- It should be associated with a route table which does not have a route to internet gateway
-
Exercise:
- Makes changes in the current terrform template which should support
- private subnets
- public subnets
- You need to create internet gateway
- you need to create two route tables
- For public route table create a route to internet gateway
- Associate public subets with public route table
- Associate private subnets with private route table.
- Makes changes in the current terrform template which should support
