diff --git a/vpn-transit-gateway/vpn-config.tf b/vpn-transit-gateway/vpn-config.tf index 3275aad..4f9294b 100644 --- a/vpn-transit-gateway/vpn-config.tf +++ b/vpn-transit-gateway/vpn-config.tf @@ -44,9 +44,11 @@ locals { vpn_tunnel_sites = distinct([for k, v in local.vpn_tunnel_outputs : v.site]) # use tunnel secrets if needed # vpn_site_tunnel_outputs = { for s in local.vpn_tunnel_sites: s => flatten([ for k,v in local.vpn_tunnel_outputs: merge(v,local.vpn_tunnel_secrets[k]) if v.site=s ]) } - vpn_site_tunnel_outputs = { for s in local.vpn_tunnel_sites : s => flatten([for k, v in local.vpn_tunnel_outputs : v if v.site == s]) } + vpn_site_tunnel_outputs = { for s in local.vpn_tunnel_sites : s => flatten([for k, v in local.vpn_tunnel_outputs : v if v.site == s]) } + vpn_site_common_settings = ["account_alias", "account_id", "region", "region_short", "vpc_cidr_block", "vpc_name", "vpc_short_name", "vpn_environment"] } + resource "null_resource" "directory_setup" { triggers = { name = "vpn-configs" @@ -92,15 +94,16 @@ resource "local_sensitive_file" "vpn_details_yaml" { } resource "local_sensitive_file" "vpn_site_details_json" { - for_each = var.generate_json_files ? local.vpn_site_tunnel_outputs : {} - content = yamlencode({ version = local._module_version, site = each.key, vpns = each.value }) + for_each = var.generate_json_files ? local.vpn_site_tunnel_outputs : {} + # content = yamlencode({ version = local._module_version, site = each.key, vpns = each.value }) + content = yamlencode(merge({ version = local._module_version, site = each.key, vpns = each.value }, { for k in local.vpn_site_common_settings : k => each.value[0].k })) filename = format("%v/%v/site.%v.%v.%v.json", path.root, null_resource.directory_setup.triggers.name, local.account_id, local.region, each.key) file_permission = "0644" } resource "local_sensitive_file" "vpn_site_details_yaml" { for_each = var.generate_yaml_files ? local.vpn_site_tunnel_outputs : {} - content = yamlencode({ version = local._module_version, site = each.key, vpns = each.value }) + content = yamlencode(merge({ version = local._module_version, site = each.key, vpns = each.value }, { for k in local.vpn_site_common_settings : k => each.value[0].k })) filename = format("%v/%v/site.%v.%v.%v.yml", path.root, null_resource.directory_setup.triggers.name, local.account_id, local.region, each.key) file_permission = "0644" }