Skip to content

Commit 0ac8343

Browse files
Enable goog-terraform-provisioned provider label (#11439) (#8004)
[upstream:0b62ec98517816a68148f8284a941b57ad21b4d4] Signed-off-by: Modular Magician <[email protected]>
1 parent 2059bb4 commit 0ac8343

File tree

37 files changed

+202
-22
lines changed

37 files changed

+202
-22
lines changed

.changelog/11439.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:breaking-change
2+
changed provider labels to add the `goog-terraform-provisioned: true` label by default.
3+
```

google-beta/acctest/test_utils.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ func CheckDataSourceStateMatchesResourceStateWithIgnores(dataSourceName, resourc
5050
if _, ok := ignoreFields[k]; ok {
5151
continue
5252
}
53-
if _, ok := ignoreFields["labels.%"]; ok && strings.HasPrefix(k, "labels.") {
54-
continue
55-
}
56-
if _, ok := ignoreFields["terraform_labels.%"]; ok && strings.HasPrefix(k, "terraform_labels.") {
53+
if strings.HasPrefix(k, "labels.") || strings.HasPrefix(k, "terraform_labels.") || strings.HasPrefix(k, "effective_labels.") {
5754
continue
5855
}
5956
if k == "%" {

google-beta/acctest/vcr_utils.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"path/filepath"
1717
"reflect"
1818
"regexp"
19+
"slices"
1920
"strconv"
2021
"strings"
2122
"sync"
@@ -149,6 +150,20 @@ func VcrTest(t *testing.T, c resource.TestCase) {
149150
} else if isReleaseDiffEnabled() {
150151
c = initializeReleaseDiffTest(c, t.Name())
151152
}
153+
154+
// terraform_labels is a computed field to which "goog-terraform-provisioned": "true" is always
155+
// added by the provider. ImportStateVerify "checks for strict equality and does not respect
156+
// DiffSuppressFunc or CustomizeDiff" so any test using ImportStateVerify must ignore
157+
// terraform_labels.
158+
var steps []resource.TestStep
159+
for _, s := range c.Steps {
160+
if s.ImportStateVerify && !slices.Contains(s.ImportStateVerifyIgnore, "terraform_labels") {
161+
s.ImportStateVerifyIgnore = append(s.ImportStateVerifyIgnore, "terraform_labels")
162+
}
163+
steps = append(steps, s)
164+
}
165+
c.Steps = steps
166+
152167
resource.Test(t, c)
153168
}
154169

google-beta/provider/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ func Provider() *schema.Provider {
136136
"add_terraform_attribution_label": {
137137
Type: schema.TypeBool,
138138
Optional: true,
139+
Default: true,
139140
},
140141

141142
"terraform_attribution_label_addition_strategy": {
@@ -991,7 +992,6 @@ func ProviderConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
991992
config.DefaultLabels[k] = v.(string)
992993
}
993994

994-
// Attribution label is opt-in; if unset, the default for AddTerraformAttributionLabel is false.
995995
config.AddTerraformAttributionLabel = d.Get("add_terraform_attribution_label").(bool)
996996
if config.AddTerraformAttributionLabel {
997997
config.TerraformAttributionLabelAdditionStrategy = transport_tpg.CreateOnlyAttributionStrategy

google-beta/services/artifactregistry/data_source_artifact_registry_docker_image_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
)
1414

1515
func TestAccDataSourceArtifactRegistryDockerImage(t *testing.T) {
16+
acctest.SkipIfVcr(t)
1617
t.Parallel()
1718

1819
resourceName := "data.google_artifact_registry_docker_image.test"

google-beta/services/bigquery/resource_bigquery_dataset_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func TestAccBigQueryDataset_withComputedLabels(t *testing.T) {
125125
resource.TestCheckResourceAttr("google_bigquery_dataset.test", "labels.env", "foo"),
126126
resource.TestCheckResourceAttr("google_bigquery_dataset.test", "labels.default_table_expiration_ms", "3600000"),
127127

128-
resource.TestCheckResourceAttr("google_bigquery_dataset.test", "effective_labels.%", "2"),
128+
resource.TestCheckResourceAttr("google_bigquery_dataset.test", "effective_labels.%", "3"),
129129
resource.TestCheckResourceAttr("google_bigquery_dataset.test", "effective_labels.env", "foo"),
130130
resource.TestCheckResourceAttr("google_bigquery_dataset.test", "effective_labels.default_table_expiration_ms", "3600000"),
131131
),
@@ -496,6 +496,10 @@ func addOutOfBandLabels(t *testing.T, datasetID string) resource.TestCheckFunc {
496496

497497
func testAccBigQueryDataset_withoutLabels(datasetID string) string {
498498
return fmt.Sprintf(`
499+
provider "google" {
500+
add_terraform_attribution_label = false
501+
}
502+
499503
resource "google_bigquery_dataset" "test" {
500504
dataset_id = "%s"
501505
friendly_name = "foo"

google-beta/services/bigquerydatatransfer/resource_bigquery_data_transfer_config_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ func TestAccBigqueryDataTransferConfig(t *testing.T) {
303303
"booleanParam": testAccBigqueryDataTransferConfig_copy_booleanParam,
304304
"update_params": testAccBigqueryDataTransferConfig_force_new_update_params,
305305
"update_service_account": testAccBigqueryDataTransferConfig_scheduledQuery_update_service_account,
306-
"salesforce": testAccBigqueryDataTransferConfig_salesforce_basic,
306+
// Multiple connector.authentication.* fields have been deprecated and return 400 errors
307+
// "salesforce": testAccBigqueryDataTransferConfig_salesforce_basic,
307308
}
308309

309310
for name, tc := range testCases {

google-beta/services/clouddeploy/resource_clouddeploy_target_test.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ provider "google" {
138138
default_labels = {
139139
default_key1 = "default_value1"
140140
}
141+
add_terraform_attribution_label = false
141142
}
142143
143144
resource "google_clouddeploy_target" "primary" {
@@ -177,6 +178,7 @@ provider "google" {
177178
default_labels = {
178179
default_key1 = "default_value1"
179180
}
181+
add_terraform_attribution_label = false
180182
}
181183
182184
resource "google_clouddeploy_target" "primary" {
@@ -218,6 +220,7 @@ provider "google" {
218220
default_key1 = "default_value1"
219221
my_second_label = "example-label-2"
220222
}
223+
add_terraform_attribution_label = false
221224
}
222225
223226
resource "google_clouddeploy_target" "primary" {
@@ -253,6 +256,10 @@ resource "google_clouddeploy_target" "primary" {
253256

254257
func testAccClouddeployTarget_withoutLabels(context map[string]interface{}) string {
255258
return acctest.Nprintf(`
259+
provider "google" {
260+
add_terraform_attribution_label = false
261+
}
262+
256263
resource "google_clouddeploy_target" "primary" {
257264
location = "%{region}"
258265
name = "tf-test-target%{random_suffix}"
@@ -279,6 +286,79 @@ resource "google_clouddeploy_target" "primary" {
279286
`, context)
280287
}
281288

289+
func TestAccClouddeployTarget_withAttributionDisabled(t *testing.T) {
290+
t.Parallel()
291+
292+
context := map[string]interface{}{
293+
"project_name": envvar.GetTestProjectFromEnv(),
294+
"region": envvar.GetTestRegionFromEnv(),
295+
"random_suffix": acctest.RandString(t, 10),
296+
"add_attribution": "false",
297+
"attribution_strategy": "CREATION_ONLY",
298+
}
299+
300+
acctest.VcrTest(t, resource.TestCase{
301+
PreCheck: func() { acctest.AccTestPreCheck(t) },
302+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
303+
CheckDestroy: testAccCheckClouddeployTargetDestroyProducer(t),
304+
Steps: []resource.TestStep{
305+
{
306+
Config: testAccClouddeployTarget_createWithAttribution(context),
307+
Check: resource.ComposeTestCheckFunc(
308+
resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "labels.%", "2"),
309+
resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "labels.my_first_label", "example-label-1"),
310+
resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "labels.my_second_label", "example-label-2"),
311+
312+
resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "terraform_labels.%", "3"),
313+
resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "terraform_labels.my_first_label", "example-label-1"),
314+
resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "terraform_labels.my_second_label", "example-label-2"),
315+
resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "terraform_labels.default_key1", "default_value1"),
316+
317+
resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "effective_labels.%", "3"),
318+
),
319+
},
320+
{
321+
ResourceName: "google_clouddeploy_target.primary",
322+
ImportState: true,
323+
ImportStateVerify: true,
324+
ImportStateVerifyIgnore: []string{"labels", "terraform_labels", "annotations"},
325+
},
326+
{
327+
Config: testAccClouddeployTarget_updateWithAttribution(context),
328+
Check: resource.ComposeTestCheckFunc(
329+
resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "labels.%", "2"),
330+
resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "labels.my_first_label", "example-label-updated-1"),
331+
resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "labels.my_second_label", "example-label-updated-2"),
332+
333+
resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "terraform_labels.%", "3"),
334+
resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "terraform_labels.my_first_label", "example-label-updated-1"),
335+
resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "terraform_labels.my_second_label", "example-label-updated-2"),
336+
resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "terraform_labels.default_key1", "default_value1"),
337+
338+
resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "effective_labels.%", "3"),
339+
),
340+
},
341+
{
342+
ResourceName: "google_clouddeploy_target.primary",
343+
ImportState: true,
344+
ImportStateVerify: true,
345+
ImportStateVerifyIgnore: []string{"labels", "terraform_labels", "annotations"},
346+
},
347+
{
348+
Config: testAccClouddeployTarget_clearWithAttribution(context),
349+
Check: resource.ComposeTestCheckFunc(
350+
resource.TestCheckNoResourceAttr("google_clouddeploy_target.primary", "labels.%"),
351+
352+
resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "terraform_labels.%", "1"),
353+
resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "terraform_labels.default_key1", "default_value1"),
354+
355+
resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "effective_labels.%", "1"),
356+
),
357+
},
358+
},
359+
})
360+
}
361+
282362
func TestAccClouddeployTarget_withCreationOnlyAttribution(t *testing.T) {
283363
t.Parallel()
284364

google-beta/services/cloudrun/resource_cloud_run_service_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ provider "google" {
631631
default_labels = {
632632
default_key1 = "default_value1"
633633
}
634+
add_terraform_attribution_label = false
634635
}
635636
636637
resource "google_cloud_run_service" "default" {
@@ -670,6 +671,7 @@ provider "google" {
670671
default_labels = {
671672
default_key1 = "default_value1"
672673
}
674+
add_terraform_attribution_label = false
673675
}
674676
675677
resource "google_cloud_run_service" "default" {
@@ -711,6 +713,7 @@ provider "google" {
711713
default_key1 = "default_value1"
712714
env = "foo"
713715
}
716+
add_terraform_attribution_label = false
714717
}
715718
716719
resource "google_cloud_run_service" "default" {
@@ -1308,6 +1311,7 @@ resource "google_cloud_run_service" "default" {
13081311
}
13091312

13101313
func TestAccCloudRunService_csiVolume(t *testing.T) {
1314+
acctest.SkipIfVcr(t)
13111315
t.Parallel()
13121316

13131317
project := envvar.GetTestProjectFromEnv()

google-beta/services/cloudrunv2/resource_cloud_run_v2_job_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ func testAccCloudRunV2Job_cloudrunv2JobWithDirectVPCAndNamedBinAuthPolicyUpdate(
311311
}
312312

313313
func TestAccCloudRunV2Job_cloudrunv2JobWithGcsUpdate(t *testing.T) {
314+
acctest.SkipIfVcr(t)
314315
t.Parallel()
315316

316317
jobName := fmt.Sprintf("tf-test-cloudrun-service%s", acctest.RandString(t, 10))
@@ -399,6 +400,7 @@ func testAccCloudRunV2Job_cloudrunv2JobWithGcsVolume(context map[string]interfac
399400
}
400401

401402
func TestAccCloudRunV2Job_cloudrunv2JobWithNfsUpdate(t *testing.T) {
403+
acctest.SkipIfVcr(t)
402404
t.Parallel()
403405

404406
jobName := fmt.Sprintf("tf-test-cloudrun-service%s", acctest.RandString(t, 10))

0 commit comments

Comments
 (0)