Hello
I create a list of vpc objets with a specific module for VPC
module "vpc" {
source = "../../../../modules/terraform-aws-vpc"
for_each = { for k, j in var.vpc_vars : k.vpc_name => j }
cidr = local.cidr[each.key]
create_database_subnet_group = false
secured_subnets = length(each.value.secured_subnets) == 0 ? local.secured_subnets[each.key] : each.value.secured_subnets
connectivity_subnets = length(each.value.connectivity_subnets) == 0 ? local.connectivity_subnets[each.key] : each.value.connectivity_subnets
private_subnets = length(each.value.private_subnets) == 0 ? local.private_subnets[each.key] : each.value.private_subnets
I use s3 backend remote state.
Now I need to get back attributes of a specific vpc from vpc outputs. Here is the terraform state :
vpc = {
"backend" = "s3"
"config" = {
"bucket" = "tf-remote-state20230512112122017100000002"
"key" = "toto-prod-vpc/terraform.tfstate"
"profile" = "toto-prod-adm"
"region" = "eu-west-3"
}
"defaults" = null
"outputs" = {
"vpc" = toset([
{
"appliance_mode_support" = true
"application" = "infra"
"cidr" = "192.168.0.0/24"
"connectivity_subnets" = tolist([])
"create_flow_log_cloudwatch_iam_role" = true
"create_flow_log_cloudwatch_log_group" = true
"create_igw" = true
"create_tgw_attachment" = false
"create_tgw_rt" = true
"enable_dns_hostnames" = true
"enable_dns_support" = true
"enable_flow_log" = true
"enable_nat_gateway" = false
"enable_vpn_gateway" = false
"flow_log_max_aggregation_interval" = 60
"private_subnets" = tolist([])
"secured_subnets" = tolist([])
"tgw_destination_cidr" = "10.0.0.0/8"
"type_vpc_subnets_attachment" = "private"
"vpc_name" = "services-partages"
},
])
"vpc_name" = tolist([
"services-partages",
])
}
"workspace" = tostring(null)
}
so I would like to get back all these attributes :
{
"appliance_mode_support" = true
"application" = "infra"
"cidr" = "192.168.0.0/24"
"connectivity_subnets" = tolist([])
"create_flow_log_cloudwatch_iam_role" = true
"create_flow_log_cloudwatch_log_group" = true
"create_igw" = true
"create_tgw_attachment" = false
"create_tgw_rt" = true
"enable_dns_hostnames" = true
"enable_dns_support" = true
"enable_flow_log" = true
"enable_nat_gateway" = false
"enable_vpn_gateway" = false
"flow_log_max_aggregation_interval" = 60
"private_subnets" = tolist([])
"secured_subnets" = tolist([])
"tgw_destination_cidr" = "10.0.0.0/8"
"type_vpc_subnets_attachment" = "private"
"vpc_name" = "services-partages"
},
How Can I do it ? the best way is to choose the right vpc output with the attribute “vpc_name”.
thanks in advance