Use local for tfvar outputs

This commit is contained in:
Julio Castillo 2022-02-16 09:07:07 +01:00
parent 9015abfc80
commit 0544456462
5 changed files with 31 additions and 42 deletions

View File

@ -31,6 +31,10 @@ locals {
sa = module.automation-tf-resman-sa.email
})
}
tfvars = {
automation_project_id = module.automation-project.project_id
custom_roles = local.custom_roles
}
}
# optionally generate providers and tfvars files for subsequent stages
@ -46,10 +50,7 @@ resource "local_file" "tfvars" {
for_each = var.outputs_location == null ? {} : { 1 = 1 }
file_permission = "0644"
filename = "${pathexpand(var.outputs_location)}/tfvars/00-bootstrap.auto.tfvars.json"
content = jsonencode({
automation_project_id = module.automation-project.project_id
custom_roles = local.custom_roles
})
content = jsonencode(local.tfvars)
}
# outputs
@ -87,8 +88,5 @@ output "providers" {
output "tfvars" {
description = "Terraform variable files for the following stages."
sensitive = true
value = {
automation_project_id = module.automation-project.project_id
custom_roles = local.custom_roles
}
value = local.tfvars
}

View File

@ -74,6 +74,10 @@ locals {
for k, v in module.branch-teams-team-sa : "team-${k}" => v.id
},
)
tfvars = {
folder_ids = local.folder_ids
service_accounts = local.service_accounts
}
}
# optionally generate providers and tfvars files for subsequent stages
@ -89,10 +93,7 @@ resource "local_file" "tfvars" {
for_each = var.outputs_location == null ? {} : { 1 = 1 }
file_permission = "0644"
filename = "${pathexpand(var.outputs_location)}/tfvars/01-resman.auto.tfvars.json"
content = jsonencode({
folder_ids = local.folder_ids
service_accounts = local.service_accounts
})
content = jsonencode(local.tfvars)
}
# outputs
@ -165,8 +166,5 @@ output "teams" {
output "tfvars" {
description = "Terraform variable files for the following stages."
sensitive = true
value = {
folder_ids = local.folder_ids
service_accounts = local.service_accounts
}
value = local.tfvars
}

View File

@ -25,6 +25,11 @@ locals {
prod-landing = module.landing-project.number
prod-spoke-0 = module.prod-spoke-project.number
}
tfvars = {
host_project_ids = local.host_project_ids
host_project_numbers = local.host_project_numbers
vpc_self_links = local.vpc_self_links
}
vpc_self_links = {
prod-landing-trusted = module.landing-trusted-vpc.self_link
prod-landing-untrusted = module.landing-untrusted-vpc.self_link
@ -39,11 +44,7 @@ resource "local_file" "tfvars" {
for_each = var.outputs_location == null ? {} : { 1 = 1 }
file_permission = "0644"
filename = "${pathexpand(var.outputs_location)}/tfvars/02-networking.auto.tfvars.json"
content = jsonencode({
host_project_ids = local.host_project_ids
host_project_numbers = local.host_project_numbers
vpc_self_links = local.vpc_self_links
})
content = jsonencode(local.tfvars)
}
# outputs
@ -80,9 +81,5 @@ output "vpn_gateway_endpoints" {
output "tfvars" {
description = "Terraform variables file for the following stages."
sensitive = true
value = {
host_project_ids = local.host_project_ids
host_project_numbers = local.host_project_numbers
vpc_self_links = local.vpc_self_links
}
value = local.tfvars
}

View File

@ -25,6 +25,11 @@ locals {
prod-landing = module.landing-project.number
prod-spoke-0 = module.prod-spoke-project.number
}
tfvars = {
host_project_ids = local.host_project_ids
host_project_numbers = local.host_project_numbers
vpc_self_links = local.vpc_self_links
}
vpc_self_links = {
prod-landing = module.landing-vpc.self_link
dev-spoke-0 = module.dev-spoke-vpc.self_link
@ -38,11 +43,7 @@ resource "local_file" "tfvars" {
for_each = var.outputs_location == null ? {} : { 1 = 1 }
file_permission = "0644"
filename = "${pathexpand(var.outputs_location)}/tfvars/02-networking.auto.tfvars.json"
content = jsonencode({
host_project_ids = local.host_project_ids
host_project_numbers = local.host_project_numbers
vpc_self_links = local.vpc_self_links
})
content = jsonencode(loca.tfvars)
}
# outputs
@ -80,9 +81,5 @@ output "vpn_gateway_endpoints" {
output "tfvars" {
description = "Terraform variables file for the following stages."
sensitive = true
value = {
host_project_ids = local.host_project_ids
host_project_numbers = local.host_project_numbers
vpc_self_links = local.vpc_self_links
}
value = local.tfvars
}

View File

@ -34,6 +34,9 @@ locals {
])
)
output_kms_keys = { for k in local._output_kms_keys : k.key => k.id }
tfvars = {
kms_keys = local.output_kms_keys
}
}
# optionally generate files for subsequent stages
@ -42,9 +45,7 @@ resource "local_file" "tfvars" {
for_each = var.outputs_location == null ? {} : { 1 = 1 }
file_permission = "0644"
filename = "${pathexpand(var.outputs_location)}/tfvars/02-security.auto.tfvars.json"
content = jsonencode({
kms_keys = local.output_kms_keys
})
content = jsonencode(local.tfvars)
}
# outputs
@ -67,7 +68,5 @@ output "stage_perimeter_projects" {
output "tfvars" {
description = "Terraform variable files for the following stages."
sensitive = true
value = {
kms_keys = local.output_kms_keys
}
value = local.tfvars
}