Fast: use pathexpand for output location (#512)

* use pathexpand for output location

* tfdoc
This commit is contained in:
Ludovico Magnocavallo 2022-02-06 18:24:46 +01:00 committed by GitHub
parent 1aa5d5d93f
commit c4533503a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 40 additions and 33 deletions

View File

@ -324,9 +324,9 @@ Names used in internal references (e.g. `module.foo-prod.id`) are only used by T
| name | description | sensitive | consumers | | name | description | sensitive | consumers |
|---|---|:---:|---| |---|---|:---:|---|
| [billing_dataset](outputs.tf#L85) | BigQuery dataset prepared for billing export. | | | | [billing_dataset](outputs.tf#L86) | BigQuery dataset prepared for billing export. | | |
| [project_ids](outputs.tf#L90) | Projects created by this stage. | | | | [project_ids](outputs.tf#L91) | Projects created by this stage. | | |
| [providers](outputs.tf#L101) | Terraform provider files for this stage and dependent stages. | ✓ | <code>stage-01</code> | | [providers](outputs.tf#L102) | Terraform provider files for this stage and dependent stages. | ✓ | <code>stage-01</code> |
| [tfvars](outputs.tf#L110) | Terraform variable files for the following stages. | ✓ | | | [tfvars](outputs.tf#L111) | Terraform variable files for the following stages. | ✓ | |
<!-- END TFDOC --> <!-- END TFDOC -->

View File

@ -15,6 +15,7 @@
*/ */
locals { locals {
outputs_location = pathexpand(var.outputs_location)
providers = { providers = {
"00-bootstrap" = templatefile("${path.module}/../../assets/templates/providers.tpl", { "00-bootstrap" = templatefile("${path.module}/../../assets/templates/providers.tpl", {
bucket = module.automation-tf-bootstrap-gcs.name bucket = module.automation-tf-bootstrap-gcs.name
@ -70,13 +71,13 @@ locals {
resource "local_file" "providers" { resource "local_file" "providers" {
for_each = var.outputs_location == null ? {} : local.providers for_each = var.outputs_location == null ? {} : local.providers
filename = "${var.outputs_location}/${each.key}/providers.tf" filename = "${local.outputs_location}/${each.key}/providers.tf"
content = each.value content = each.value
} }
resource "local_file" "tfvars" { resource "local_file" "tfvars" {
for_each = var.outputs_location == null ? {} : local.tfvars for_each = var.outputs_location == null ? {} : local.tfvars
filename = "${var.outputs_location}/${each.key}/terraform-bootstrap.auto.tfvars.json" filename = "${local.outputs_location}/${each.key}/terraform-bootstrap.auto.tfvars.json"
content = each.value content = each.value
} }

View File

@ -177,12 +177,12 @@ Due to its simplicity, this stage lends itself easily to customizations: adding
| name | description | sensitive | consumers | | name | description | sensitive | consumers |
|---|---|:---:|---| |---|---|:---:|---|
| [networking](outputs.tf#L83) | Data for the networking stage. | | <code>02-networking</code> | | [networking](outputs.tf#L84) | Data for the networking stage. | | <code>02-networking</code> |
| [project_factories](outputs.tf#L93) | Data for the project factories stage. | | <code>xx-teams</code> | | [project_factories](outputs.tf#L94) | Data for the project factories stage. | | <code>xx-teams</code> |
| [providers](outputs.tf#L110) | Terraform provider files for this stage and dependent stages. | ✓ | <code>02-networking</code> · <code>02-security</code> · <code>xx-sandbox</code> · <code>xx-teams</code> | | [providers](outputs.tf#L111) | Terraform provider files for this stage and dependent stages. | ✓ | <code>02-networking</code> · <code>02-security</code> · <code>xx-sandbox</code> · <code>xx-teams</code> |
| [sandbox](outputs.tf#L117) | Data for the sandbox stage. | | <code>xx-sandbox</code> | | [sandbox](outputs.tf#L118) | Data for the sandbox stage. | | <code>xx-sandbox</code> |
| [security](outputs.tf#L127) | Data for the networking stage. | | <code>02-security</code> | | [security](outputs.tf#L128) | Data for the networking stage. | | <code>02-security</code> |
| [teams](outputs.tf#L137) | Data for the teams stage. | | | | [teams](outputs.tf#L138) | Data for the teams stage. | | |
| [tfvars](outputs.tf#L150) | Terraform variable files for the following stages. | ✓ | | | [tfvars](outputs.tf#L151) | Terraform variable files for the following stages. | ✓ | |
<!-- END TFDOC --> <!-- END TFDOC -->

View File

@ -19,6 +19,7 @@ locals {
dev = module.branch-teams-dev-projectfactory-sa.iam_email dev = module.branch-teams-dev-projectfactory-sa.iam_email
prod = module.branch-teams-prod-projectfactory-sa.iam_email prod = module.branch-teams-prod-projectfactory-sa.iam_email
} }
outputs_location = pathexpand(var.outputs_location)
providers = { providers = {
"02-networking" = templatefile("${path.module}/../../assets/templates/providers.tpl", { "02-networking" = templatefile("${path.module}/../../assets/templates/providers.tpl", {
bucket = module.branch-network-gcs.name bucket = module.branch-network-gcs.name
@ -68,13 +69,13 @@ locals {
resource "local_file" "providers" { resource "local_file" "providers" {
for_each = var.outputs_location == null ? {} : local.providers for_each = var.outputs_location == null ? {} : local.providers
filename = "${var.outputs_location}/${each.key}/providers.tf" filename = "${local.outputs_location}/${each.key}/providers.tf"
content = each.value content = each.value
} }
resource "local_file" "tfvars" { resource "local_file" "tfvars" {
for_each = var.outputs_location == null ? {} : local.tfvars for_each = var.outputs_location == null ? {} : local.tfvars
filename = "${var.outputs_location}/${each.key}/terraform-resman.auto.tfvars.json" filename = "${local.outputs_location}/${each.key}/terraform-resman.auto.tfvars.json"
content = each.value content = each.value
} }

View File

@ -340,11 +340,11 @@ Don't forget to add a peering zone in the landing project and point it to the ne
| name | description | sensitive | consumers | | name | description | sensitive | consumers |
|---|---|:---:|---| |---|---|:---:|---|
| [project_ids](outputs.tf#L42) | Network project ids. | | | | [project_ids](outputs.tf#L43) | Network project ids. | | |
| [project_numbers](outputs.tf#L51) | Network project numbers. | | | | [project_numbers](outputs.tf#L52) | Network project numbers. | | |
| [shared_vpc_host_projects](outputs.tf#L60) | Shared VPC host projects. | | | | [shared_vpc_host_projects](outputs.tf#L61) | Shared VPC host projects. | | |
| [shared_vpc_self_links](outputs.tf#L69) | Shared VPC host projects. | | | | [shared_vpc_self_links](outputs.tf#L70) | Shared VPC host projects. | | |
| [tfvars](outputs.tf#L93) | Network-related variables used in other stages. | ✓ | | | [tfvars](outputs.tf#L94) | Network-related variables used in other stages. | ✓ | |
| [vpn_gateway_endpoints](outputs.tf#L79) | External IP Addresses for the GCP VPN gateways. | | | | [vpn_gateway_endpoints](outputs.tf#L80) | External IP Addresses for the GCP VPN gateways. | | |
<!-- END TFDOC --> <!-- END TFDOC -->

View File

@ -17,6 +17,7 @@
# Optionally, generate providers and tfvars files for subsequent stages # Optionally, generate providers and tfvars files for subsequent stages
locals { locals {
outputs_location = pathexpand(var.outputs_location)
tfvars = { tfvars = {
"03-project-factory-dev" = jsonencode({ "03-project-factory-dev" = jsonencode({
environment_dns_zone = module.dev-dns-private-zone.domain environment_dns_zone = module.dev-dns-private-zone.domain
@ -33,7 +34,7 @@ locals {
resource "local_file" "tfvars" { resource "local_file" "tfvars" {
for_each = var.outputs_location == null ? {} : local.tfvars for_each = var.outputs_location == null ? {} : local.tfvars
filename = "${var.outputs_location}/${each.key}/terraform-networking.auto.tfvars.json" filename = "${local.outputs_location}/${each.key}/terraform-networking.auto.tfvars.json"
content = each.value content = each.value
} }

View File

@ -328,12 +328,12 @@ DNS configurations are centralised in the `dns.tf` file. Spokes delegate DNS res
| name | description | sensitive | consumers | | name | description | sensitive | consumers |
|---|---|:---:|---| |---|---|:---:|---|
| [cloud_dns_inbound_policy](outputs.tf#L41) | IP Addresses for Cloud DNS inbound policy. | | | | [cloud_dns_inbound_policy](outputs.tf#L42) | IP Addresses for Cloud DNS inbound policy. | | |
| [project_ids](outputs.tf#L46) | Network project ids. | | | | [project_ids](outputs.tf#L47) | Network project ids. | | |
| [project_numbers](outputs.tf#L55) | Network project numbers. | | | | [project_numbers](outputs.tf#L56) | Network project numbers. | | |
| [shared_vpc_host_projects](outputs.tf#L64) | Shared VPC host projects. | | | | [shared_vpc_host_projects](outputs.tf#L65) | Shared VPC host projects. | | |
| [shared_vpc_self_links](outputs.tf#L74) | Shared VPC host projects. | | | | [shared_vpc_self_links](outputs.tf#L75) | Shared VPC host projects. | | |
| [tfvars](outputs.tf#L91) | Network-related variables used in other stages. | ✓ | | | [tfvars](outputs.tf#L92) | Network-related variables used in other stages. | ✓ | |
| [vpn_gateway_endpoints](outputs.tf#L84) | External IP Addresses for the GCP VPN gateways. | | | | [vpn_gateway_endpoints](outputs.tf#L85) | External IP Addresses for the GCP VPN gateways. | | |
<!-- END TFDOC --> <!-- END TFDOC -->

View File

@ -16,6 +16,7 @@
# optionally generate providers and tfvars files for subsequent stages # optionally generate providers and tfvars files for subsequent stages
locals { locals {
outputs_location = pathexpand(var.outputs_location)
tfvars = { tfvars = {
"03-project-factory-dev" = jsonencode({ "03-project-factory-dev" = jsonencode({
environment_dns_zone = module.dev-dns-private-zone.domain environment_dns_zone = module.dev-dns-private-zone.domain
@ -32,7 +33,7 @@ locals {
resource "local_file" "tfvars" { resource "local_file" "tfvars" {
for_each = var.outputs_location == null ? {} : local.tfvars for_each = var.outputs_location == null ? {} : local.tfvars
filename = "${var.outputs_location}/${each.key}/terraform-networking.auto.tfvars.json" filename = "${local.outputs_location}/${each.key}/terraform-networking.auto.tfvars.json"
content = each.value content = each.value
} }

View File

@ -306,6 +306,6 @@ Some references that might be useful in setting up this stage:
| name | description | sensitive | consumers | | name | description | sensitive | consumers |
|---|---|:---:|---| |---|---|:---:|---|
| [stage_perimeter_projects](outputs.tf#L37) | Security project numbers. They can be added to perimeter resources. | | | | [stage_perimeter_projects](outputs.tf#L40) | Security project numbers. They can be added to perimeter resources. | | |
<!-- END TFDOC --> <!-- END TFDOC -->

View File

@ -15,10 +15,13 @@
*/ */
# optionally generate files for subsequent stages # optionally generate files for subsequent stages
locals {
outputs_location = pathexpand(var.outputs_location)
}
resource "local_file" "dev_sec_kms" { resource "local_file" "dev_sec_kms" {
for_each = var.outputs_location == null ? {} : { 1 = 1 } for_each = var.outputs_location == null ? {} : { 1 = 1 }
filename = "${var.outputs_location}/yamls/02-security-kms-dev-keys.yaml" filename = "${local.outputs_location}/yamls/02-security-kms-dev-keys.yaml"
content = yamlencode({ content = yamlencode({
for k, m in module.dev-sec-kms : k => m.key_ids for k, m in module.dev-sec-kms : k => m.key_ids
}) })
@ -26,7 +29,7 @@ resource "local_file" "dev_sec_kms" {
resource "local_file" "prod_sec_kms" { resource "local_file" "prod_sec_kms" {
for_each = var.outputs_location == null ? {} : { 1 = 1 } for_each = var.outputs_location == null ? {} : { 1 = 1 }
filename = "${var.outputs_location}/yamls/02-security-kms-prod-keys.yaml" filename = "${local.outputs_location}/yamls/02-security-kms-prod-keys.yaml"
content = yamlencode({ content = yamlencode({
for k, m in module.prod-sec-kms : k => m.key_ids for k, m in module.prod-sec-kms : k => m.key_ids
}) })