From 12e78af05502812b4f39e8c3f05193f6d4a6d60d Mon Sep 17 00:00:00 2001 From: Luca Prete Date: Thu, 7 Sep 2023 14:48:39 +0200 Subject: [PATCH] Fix project factory blueprint and fast stage (#1654) --- blueprints/factories/project-factory/README.md | 10 ++++++---- blueprints/factories/project-factory/factory.tf | 9 +++++++-- blueprints/factories/project-factory/variables.tf | 2 ++ .../dev/data/projects/project.yaml.sample | 2 +- .../factories/project_factory/examples/example.yaml | 4 ++-- .../s3_project_factory/data/projects/project.yaml | 2 +- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/blueprints/factories/project-factory/README.md b/blueprints/factories/project-factory/README.md index d144a11af5..74682ae935 100644 --- a/blueprints/factories/project-factory/README.md +++ b/blueprints/factories/project-factory/README.md @@ -55,6 +55,7 @@ billing_account: 012345-67890A-BCDEF0 labels: app: app-1 team: foo +parent: folders/12345678 service_encryption_key_ids: compute: - projects/kms-central-prj/locations/europe-west3/keyRings/my-keyring/cryptoKeys/europe3-gce @@ -71,6 +72,7 @@ service_accounts: labels: app: app-1 team: foo +parent: folders/12345678 service_accounts: app-2-be: {} @@ -81,10 +83,10 @@ service_accounts: | name | description | type | required | default | |---|---|:---:|:---:|:---:| -| [factory_data](variables.tf#L83) | Project data from either YAML files or externally parsed data. | object({…}) | ✓ | | -| [data_defaults](variables.tf#L17) | Optional default values used when corresponding project data from files are missing. | object({…}) | | {} | -| [data_merges](variables.tf#L44) | Optional values that will be merged with corresponding data from files. Combines with `data_defaults`, file data, and `data_overrides`. | object({…}) | | {} | -| [data_overrides](variables.tf#L63) | Optional values that override corresponding data from files. Takes precedence over file data and `data_defaults`. | object({…}) | | {} | +| [factory_data](variables.tf#L85) | Project data from either YAML files or externally parsed data. | object({…}) | ✓ | | +| [data_defaults](variables.tf#L17) | Optional default values used when corresponding project data from files are missing. | object({…}) | | {} | +| [data_merges](variables.tf#L45) | Optional values that will be merged with corresponding data from files. Combines with `data_defaults`, file data, and `data_overrides`. | object({…}) | | {} | +| [data_overrides](variables.tf#L64) | Optional values that override corresponding data from files. Takes precedence over file data and `data_defaults`. | object({…}) | | {} | ## Outputs diff --git a/blueprints/factories/project-factory/factory.tf b/blueprints/factories/project-factory/factory.tf index dac843dfc9..0390b0558d 100644 --- a/blueprints/factories/project-factory/factory.tf +++ b/blueprints/factories/project-factory/factory.tf @@ -28,11 +28,11 @@ locals { ) projects = { for k, v in local._data : k => merge(v, { - billing_account = coalesce( + billing_account = try(coalesce( var.data_overrides.billing_account, try(v.billing_account, null), var.data_defaults.billing_account - ) + ), null) contacts = coalesce( var.data_overrides.contacts, try(v.contacts, null), @@ -46,6 +46,11 @@ locals { try(v.metric_scopes, null), var.data_defaults.metric_scopes ) + parent = coalesce( + var.data_overrides.parent, + try(v.parent, null), + var.data_defaults.parent + ) prefix = coalesce( var.data_overrides.prefix, try(v.prefix, null), diff --git a/blueprints/factories/project-factory/variables.tf b/blueprints/factories/project-factory/variables.tf index 6791784686..d717647407 100644 --- a/blueprints/factories/project-factory/variables.tf +++ b/blueprints/factories/project-factory/variables.tf @@ -21,6 +21,7 @@ variable "data_defaults" { contacts = optional(map(list(string)), {}) labels = optional(map(string), {}) metric_scopes = optional(list(string), []) + parent = optional(string) prefix = optional(string) service_encryption_key_ids = optional(map(list(string)), {}) service_perimeter_bridges = optional(list(string), []) @@ -65,6 +66,7 @@ variable "data_overrides" { type = object({ billing_account = optional(string) contacts = optional(map(list(string))) + parent = optional(string) prefix = optional(string) service_encryption_key_ids = optional(map(list(string))) service_perimeter_bridges = optional(list(string)) diff --git a/fast/stages/3-project-factory/dev/data/projects/project.yaml.sample b/fast/stages/3-project-factory/dev/data/projects/project.yaml.sample index 5311019d82..cc35b4c569 100644 --- a/fast/stages/3-project-factory/dev/data/projects/project.yaml.sample +++ b/fast/stages/3-project-factory/dev/data/projects/project.yaml.sample @@ -23,7 +23,7 @@ essential_contacts: - team-a-contacts@example.com # Folder the project will be created as children of -folder_id: folders/012345678901 +parent: folders/012345678901 # [opt] Authoritative IAM bindings in group => [roles] format group_iam: diff --git a/tests/blueprints/factories/project_factory/examples/example.yaml b/tests/blueprints/factories/project_factory/examples/example.yaml index 5927caedfc..d1eb054eaf 100644 --- a/tests/blueprints/factories/project_factory/examples/example.yaml +++ b/tests/blueprints/factories/project_factory/examples/example.yaml @@ -30,7 +30,7 @@ values: module.project-factory.module.projects["prj-app-1"].google_project.project[0]: auto_create_network: false billing_account: 012345-67890A-BCDEF0 - folder_id: null + folder_id: "12345678" labels: app: app-1 team: foo @@ -61,7 +61,7 @@ values: module.project-factory.module.projects["prj-app-2"].google_project.project[0]: auto_create_network: false billing_account: 012345-67890A-ABCDEF - folder_id: null + folder_id: "12345678" labels: app: app-1 team: foo diff --git a/tests/fast/stages/s3_project_factory/data/projects/project.yaml b/tests/fast/stages/s3_project_factory/data/projects/project.yaml index 18b5cdb4a8..922b4044fe 100644 --- a/tests/fast/stages/s3_project_factory/data/projects/project.yaml +++ b/tests/fast/stages/s3_project_factory/data/projects/project.yaml @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -parent_id: folders/012345678901 +parent: folders/012345678901 services: - storage.googleapis.com - stackdriver.googleapis.com