How to select specific element/s from output.tf?
I am doing a home project of provisioning EC2 instances (2 DC, 2 App, 2 SQL and 2 Web servers) using Terraform. While all servers would be part of Pvt-Az A and B, App02 will be part of Az-C.
I have the instances provision and networking defined as modules and here is the networking/outputs.tf
output "private_subnets" {
value = aws_subnet.private_subnet.*.id
}
This lists subnets as:
us-east-1a
us-east-1b
us-east-1c
root/main.tf holds the server setup:
#Deploy App Servers
module "app_servers" {
source = "./app_servers"
keyname = module.domain_controllers.key_name
public_key_path = var.public_key_path
app_count = var.app_count
app_inst_type = var.app_inst_type
pvtsubnets = module.networking.private_subnets # <--Here lies the problem.
sql_fs_sg = module.networking.sql_fs_sg
perf_pvt_sg = module.networking.perf_pvt_sg
}
While using the same logic for other instances, all of them gets provisioned to Az-A and B, I am unable to get App02 provisioned to Az-C. It gets provisioned on Az-A and Az-B.
app_servers/main.tf
#App_servers
resource "aws_instance" "app" {
count = var.app_count
ami = data.aws_ami.server_ami.id
ebs_optimized = true
instance_type = var.app_inst_type
subnet_id = element(var.pvtsubnets, count.index)
vpc_security_group_ids = [
var.sql_fs_sg,
var.perf_pvt_sg
]
.
.
}