cloud-foundation-fabric/fast/stages/00-bootstrap/outputs.tf

93 lines
2.9 KiB
Terraform
Raw Normal View History

/**
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
locals {
2022-02-15 15:03:10 -08:00
custom_roles = {
2022-02-10 10:12:07 -08:00
for k, v in var.custom_role_names :
k => module.organization.custom_role_id[v]
}
providers = {
"00-bootstrap" = templatefile("${path.module}/../../assets/templates/providers.tpl", {
bucket = module.automation-tf-bootstrap-gcs.name
name = "bootstrap"
sa = module.automation-tf-bootstrap-sa.email
})
"01-resman" = templatefile("${path.module}/../../assets/templates/providers.tpl", {
bucket = module.automation-tf-resman-gcs.name
name = "resman"
sa = module.automation-tf-resman-sa.email
})
}
2022-02-16 00:07:07 -08:00
tfvars = {
automation_project_id = module.automation-project.project_id
custom_roles = local.custom_roles
}
}
# optionally generate providers and tfvars files for subsequent stages
resource "local_file" "providers" {
2022-02-15 15:08:09 -08:00
for_each = var.outputs_location == null ? {} : local.providers
file_permission = "0644"
2022-02-15 15:14:49 -08:00
filename = "${pathexpand(var.outputs_location)}/providers/${each.key}-providers.tf"
2022-02-15 15:08:09 -08:00
content = each.value
}
resource "local_file" "tfvars" {
2022-02-15 15:08:09 -08:00
for_each = var.outputs_location == null ? {} : { 1 = 1 }
file_permission = "0644"
filename = "${pathexpand(var.outputs_location)}/tfvars/00-bootstrap.auto.tfvars.json"
2022-02-16 00:07:07 -08:00
content = jsonencode(local.tfvars)
}
# outputs
output "billing_dataset" {
description = "BigQuery dataset prepared for billing export."
value = try(module.billing-export-dataset.0.id, null)
}
2022-02-15 15:03:10 -08:00
output "custom_roles" {
description = "Organization-level custom roles."
value = local.custom_roles
}
output "project_ids" {
description = "Projects created by this stage."
value = {
automation = module.automation-project.project_id
billing-export = try(module.billing-export-project.0.project_id, null)
log-export = module.log-export-project.project_id
}
}
# ready to use provider configurations for subsequent stages when not using files
output "providers" {
# tfdoc:output:consumers stage-01
description = "Terraform provider files for this stage and dependent stages."
sensitive = true
value = local.providers
}
2022-02-15 15:35:44 -08:00
# ready to use variable values for subsequent stages
output "tfvars" {
description = "Terraform variable files for the following stages."
sensitive = true
2022-02-16 00:07:07 -08:00
value = local.tfvars
2022-02-15 15:35:44 -08:00
}