From 1c0533893743c8ab03b3872af3e5a68ac05f65ec Mon Sep 17 00:00:00 2001 From: Lei Jin Date: Tue, 4 Jun 2024 21:36:35 +0000 Subject: [PATCH] fix(GROW-2931): GCP default label should be attributes Signed-off-by: Lei Jin --- lwgenerate/gcp/gcp.go | 16 ++++------------ lwgenerate/gcp/gcp_test.go | 7 +++---- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/lwgenerate/gcp/gcp.go b/lwgenerate/gcp/gcp.go index 924238f06..a0c93d67f 100644 --- a/lwgenerate/gcp/gcp.go +++ b/lwgenerate/gcp/gcp.go @@ -589,20 +589,12 @@ func createGcpProvider( attrs["region"] = region } - modifiers := []lwgenerate.HclProviderModifier{ - lwgenerate.HclProviderWithAttributes(attrs), + if len(providerDefaultLabels) != 0 { + attrs["default_labels"] = providerDefaultLabels } - if len(providerDefaultLabels) != 0 { - defaultLabelsBlock, err := lwgenerate.HclCreateGenericBlock( - "default_labels", - nil, - providerDefaultLabels, - ) - if err != nil { - return nil, err - } - modifiers = append(modifiers, lwgenerate.HclProviderWithGenericBlocks(defaultLabelsBlock)) + modifiers := []lwgenerate.HclProviderModifier{ + lwgenerate.HclProviderWithAttributes(attrs), } provider, err := lwgenerate.NewProvider( diff --git a/lwgenerate/gcp/gcp_test.go b/lwgenerate/gcp/gcp_test.go index 82f0ad434..3a11539f4 100644 --- a/lwgenerate/gcp/gcp_test.go +++ b/lwgenerate/gcp/gcp_test.go @@ -921,13 +921,12 @@ var gcpProviderWithExtraArguments = `provider "google" { var gcpProviderWithDefaultLabels = `provider "google" { alias = "us-east1" credentials = "/path/to/credentials" - project = "project1" - region = "us-east1" - - default_labels { + default_labels = { LABEL_TEST = "foo" LABEL_TEST1 = "bar" } + project = "project1" + region = "us-east1" } `