From 0ac834396a4085298b6fcf5174095d90a7cce961 Mon Sep 17 00:00:00 2001 From: The Magician Date: Tue, 20 Aug 2024 09:42:14 -0700 Subject: [PATCH] Enable goog-terraform-provisioned provider label (#11439) (#8004) [upstream:0b62ec98517816a68148f8284a941b57ad21b4d4] Signed-off-by: Modular Magician --- .changelog/11439.txt | 3 + google-beta/acctest/test_utils.go | 5 +- google-beta/acctest/vcr_utils.go | 15 ++++ google-beta/provider/provider.go | 2 +- ...rce_artifact_registry_docker_image_test.go | 1 + .../resource_bigquery_dataset_test.go | 6 +- ...urce_bigquery_data_transfer_config_test.go | 3 +- .../resource_clouddeploy_target_test.go | 80 +++++++++++++++++++ .../resource_cloud_run_service_test.go | 4 + .../resource_cloud_run_v2_job_test.go | 2 + ...rce_cloud_run_v2_service_generated_test.go | 2 + .../resource_cloud_run_v2_service_test.go | 1 + .../resource_composer_environment_test.go | 1 + .../compute/resource_compute_address_test.go | 15 ++++ .../resource_compute_forwarding_rule.go | 2 +- ...resource_compute_global_forwarding_rule.go | 2 +- ...rk_peering_routes_config_generated_test.go | 1 + ...ta_source_google_container_cluster_test.go | 1 + .../resource_container_cluster_test.go | 1 + .../resource_container_node_pool_test.go | 1 + .../dataplex/resource_dataplex_datascan.go | 2 +- .../dataplex/resource_dataplex_task.go | 2 +- .../dataproc/resource_dataproc_cluster.go | 3 +- ...ce_edgecontainer_cluster_generated_test.go | 2 + ...ource_kms_autokey_config_generated_test.go | 1 + .../resource_kms_key_handle_generated_test.go | 1 + ...curity_client_tls_policy_generated_test.go | 2 + ...network_security_client_tls_policy_test.go | 1 + ...etwork_services_lb_route_extension_test.go | 1 + .../resource_google_project_test.go | 4 + ...data_source_secret_manager_secrets_test.go | 22 ++++- ...online_store_featureview_generated_test.go | 1 + ..._ai_feature_online_store_generated_test.go | 1 + .../resource_vertex_ai_index_endpoint_test.go | 1 + google-beta/tpgresource/labels.go | 12 ++- .../guides/provider_reference.html.markdown | 5 +- .../guides/version_6_upgrade.html.markdown | 15 ++++ 37 files changed, 202 insertions(+), 22 deletions(-) create mode 100644 .changelog/11439.txt diff --git a/.changelog/11439.txt b/.changelog/11439.txt new file mode 100644 index 0000000000..af86b3811b --- /dev/null +++ b/.changelog/11439.txt @@ -0,0 +1,3 @@ +```release-note:breaking-change +changed provider labels to add the `goog-terraform-provisioned: true` label by default. +``` \ No newline at end of file diff --git a/google-beta/acctest/test_utils.go b/google-beta/acctest/test_utils.go index fba03cfb97..3f10625b82 100644 --- a/google-beta/acctest/test_utils.go +++ b/google-beta/acctest/test_utils.go @@ -50,10 +50,7 @@ func CheckDataSourceStateMatchesResourceStateWithIgnores(dataSourceName, resourc if _, ok := ignoreFields[k]; ok { continue } - if _, ok := ignoreFields["labels.%"]; ok && strings.HasPrefix(k, "labels.") { - continue - } - if _, ok := ignoreFields["terraform_labels.%"]; ok && strings.HasPrefix(k, "terraform_labels.") { + if strings.HasPrefix(k, "labels.") || strings.HasPrefix(k, "terraform_labels.") || strings.HasPrefix(k, "effective_labels.") { continue } if k == "%" { diff --git a/google-beta/acctest/vcr_utils.go b/google-beta/acctest/vcr_utils.go index 555e165d00..ca2fee518c 100644 --- a/google-beta/acctest/vcr_utils.go +++ b/google-beta/acctest/vcr_utils.go @@ -16,6 +16,7 @@ import ( "path/filepath" "reflect" "regexp" + "slices" "strconv" "strings" "sync" @@ -149,6 +150,20 @@ func VcrTest(t *testing.T, c resource.TestCase) { } else if isReleaseDiffEnabled() { c = initializeReleaseDiffTest(c, t.Name()) } + + // terraform_labels is a computed field to which "goog-terraform-provisioned": "true" is always + // added by the provider. ImportStateVerify "checks for strict equality and does not respect + // DiffSuppressFunc or CustomizeDiff" so any test using ImportStateVerify must ignore + // terraform_labels. + var steps []resource.TestStep + for _, s := range c.Steps { + if s.ImportStateVerify && !slices.Contains(s.ImportStateVerifyIgnore, "terraform_labels") { + s.ImportStateVerifyIgnore = append(s.ImportStateVerifyIgnore, "terraform_labels") + } + steps = append(steps, s) + } + c.Steps = steps + resource.Test(t, c) } diff --git a/google-beta/provider/provider.go b/google-beta/provider/provider.go index f75d812c71..e57ae1dad7 100644 --- a/google-beta/provider/provider.go +++ b/google-beta/provider/provider.go @@ -136,6 +136,7 @@ func Provider() *schema.Provider { "add_terraform_attribution_label": { Type: schema.TypeBool, Optional: true, + Default: true, }, "terraform_attribution_label_addition_strategy": { @@ -991,7 +992,6 @@ func ProviderConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr config.DefaultLabels[k] = v.(string) } - // Attribution label is opt-in; if unset, the default for AddTerraformAttributionLabel is false. config.AddTerraformAttributionLabel = d.Get("add_terraform_attribution_label").(bool) if config.AddTerraformAttributionLabel { config.TerraformAttributionLabelAdditionStrategy = transport_tpg.CreateOnlyAttributionStrategy diff --git a/google-beta/services/artifactregistry/data_source_artifact_registry_docker_image_test.go b/google-beta/services/artifactregistry/data_source_artifact_registry_docker_image_test.go index bca157984e..6c56ecfc35 100644 --- a/google-beta/services/artifactregistry/data_source_artifact_registry_docker_image_test.go +++ b/google-beta/services/artifactregistry/data_source_artifact_registry_docker_image_test.go @@ -13,6 +13,7 @@ import ( ) func TestAccDataSourceArtifactRegistryDockerImage(t *testing.T) { + acctest.SkipIfVcr(t) t.Parallel() resourceName := "data.google_artifact_registry_docker_image.test" diff --git a/google-beta/services/bigquery/resource_bigquery_dataset_test.go b/google-beta/services/bigquery/resource_bigquery_dataset_test.go index af920d8c6c..6412eeb018 100644 --- a/google-beta/services/bigquery/resource_bigquery_dataset_test.go +++ b/google-beta/services/bigquery/resource_bigquery_dataset_test.go @@ -125,7 +125,7 @@ func TestAccBigQueryDataset_withComputedLabels(t *testing.T) { resource.TestCheckResourceAttr("google_bigquery_dataset.test", "labels.env", "foo"), resource.TestCheckResourceAttr("google_bigquery_dataset.test", "labels.default_table_expiration_ms", "3600000"), - resource.TestCheckResourceAttr("google_bigquery_dataset.test", "effective_labels.%", "2"), + resource.TestCheckResourceAttr("google_bigquery_dataset.test", "effective_labels.%", "3"), resource.TestCheckResourceAttr("google_bigquery_dataset.test", "effective_labels.env", "foo"), resource.TestCheckResourceAttr("google_bigquery_dataset.test", "effective_labels.default_table_expiration_ms", "3600000"), ), @@ -496,6 +496,10 @@ func addOutOfBandLabels(t *testing.T, datasetID string) resource.TestCheckFunc { func testAccBigQueryDataset_withoutLabels(datasetID string) string { return fmt.Sprintf(` +provider "google" { + add_terraform_attribution_label = false +} + resource "google_bigquery_dataset" "test" { dataset_id = "%s" friendly_name = "foo" diff --git a/google-beta/services/bigquerydatatransfer/resource_bigquery_data_transfer_config_test.go b/google-beta/services/bigquerydatatransfer/resource_bigquery_data_transfer_config_test.go index 2c16f5e39f..f2677563b9 100644 --- a/google-beta/services/bigquerydatatransfer/resource_bigquery_data_transfer_config_test.go +++ b/google-beta/services/bigquerydatatransfer/resource_bigquery_data_transfer_config_test.go @@ -303,7 +303,8 @@ func TestAccBigqueryDataTransferConfig(t *testing.T) { "booleanParam": testAccBigqueryDataTransferConfig_copy_booleanParam, "update_params": testAccBigqueryDataTransferConfig_force_new_update_params, "update_service_account": testAccBigqueryDataTransferConfig_scheduledQuery_update_service_account, - "salesforce": testAccBigqueryDataTransferConfig_salesforce_basic, + // Multiple connector.authentication.* fields have been deprecated and return 400 errors + // "salesforce": testAccBigqueryDataTransferConfig_salesforce_basic, } for name, tc := range testCases { diff --git a/google-beta/services/clouddeploy/resource_clouddeploy_target_test.go b/google-beta/services/clouddeploy/resource_clouddeploy_target_test.go index c67f4126f3..1554f13eed 100644 --- a/google-beta/services/clouddeploy/resource_clouddeploy_target_test.go +++ b/google-beta/services/clouddeploy/resource_clouddeploy_target_test.go @@ -138,6 +138,7 @@ provider "google" { default_labels = { default_key1 = "default_value1" } + add_terraform_attribution_label = false } resource "google_clouddeploy_target" "primary" { @@ -177,6 +178,7 @@ provider "google" { default_labels = { default_key1 = "default_value1" } + add_terraform_attribution_label = false } resource "google_clouddeploy_target" "primary" { @@ -218,6 +220,7 @@ provider "google" { default_key1 = "default_value1" my_second_label = "example-label-2" } + add_terraform_attribution_label = false } resource "google_clouddeploy_target" "primary" { @@ -253,6 +256,10 @@ resource "google_clouddeploy_target" "primary" { func testAccClouddeployTarget_withoutLabels(context map[string]interface{}) string { return acctest.Nprintf(` +provider "google" { + add_terraform_attribution_label = false +} + resource "google_clouddeploy_target" "primary" { location = "%{region}" name = "tf-test-target%{random_suffix}" @@ -279,6 +286,79 @@ resource "google_clouddeploy_target" "primary" { `, context) } +func TestAccClouddeployTarget_withAttributionDisabled(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "project_name": envvar.GetTestProjectFromEnv(), + "region": envvar.GetTestRegionFromEnv(), + "random_suffix": acctest.RandString(t, 10), + "add_attribution": "false", + "attribution_strategy": "CREATION_ONLY", + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckClouddeployTargetDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccClouddeployTarget_createWithAttribution(context), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "labels.%", "2"), + resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "labels.my_first_label", "example-label-1"), + resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "labels.my_second_label", "example-label-2"), + + resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "terraform_labels.%", "3"), + resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "terraform_labels.my_first_label", "example-label-1"), + resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "terraform_labels.my_second_label", "example-label-2"), + resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "terraform_labels.default_key1", "default_value1"), + + resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "effective_labels.%", "3"), + ), + }, + { + ResourceName: "google_clouddeploy_target.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"labels", "terraform_labels", "annotations"}, + }, + { + Config: testAccClouddeployTarget_updateWithAttribution(context), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "labels.%", "2"), + resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "labels.my_first_label", "example-label-updated-1"), + resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "labels.my_second_label", "example-label-updated-2"), + + resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "terraform_labels.%", "3"), + resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "terraform_labels.my_first_label", "example-label-updated-1"), + resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "terraform_labels.my_second_label", "example-label-updated-2"), + resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "terraform_labels.default_key1", "default_value1"), + + resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "effective_labels.%", "3"), + ), + }, + { + ResourceName: "google_clouddeploy_target.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"labels", "terraform_labels", "annotations"}, + }, + { + Config: testAccClouddeployTarget_clearWithAttribution(context), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckNoResourceAttr("google_clouddeploy_target.primary", "labels.%"), + + resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "terraform_labels.%", "1"), + resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "terraform_labels.default_key1", "default_value1"), + + resource.TestCheckResourceAttr("google_clouddeploy_target.primary", "effective_labels.%", "1"), + ), + }, + }, + }) +} + func TestAccClouddeployTarget_withCreationOnlyAttribution(t *testing.T) { t.Parallel() diff --git a/google-beta/services/cloudrun/resource_cloud_run_service_test.go b/google-beta/services/cloudrun/resource_cloud_run_service_test.go index 7e2715a4e7..60e639e3e3 100644 --- a/google-beta/services/cloudrun/resource_cloud_run_service_test.go +++ b/google-beta/services/cloudrun/resource_cloud_run_service_test.go @@ -631,6 +631,7 @@ provider "google" { default_labels = { default_key1 = "default_value1" } + add_terraform_attribution_label = false } resource "google_cloud_run_service" "default" { @@ -670,6 +671,7 @@ provider "google" { default_labels = { default_key1 = "default_value1" } + add_terraform_attribution_label = false } resource "google_cloud_run_service" "default" { @@ -711,6 +713,7 @@ provider "google" { default_key1 = "default_value1" env = "foo" } + add_terraform_attribution_label = false } resource "google_cloud_run_service" "default" { @@ -1308,6 +1311,7 @@ resource "google_cloud_run_service" "default" { } func TestAccCloudRunService_csiVolume(t *testing.T) { + acctest.SkipIfVcr(t) t.Parallel() project := envvar.GetTestProjectFromEnv() diff --git a/google-beta/services/cloudrunv2/resource_cloud_run_v2_job_test.go b/google-beta/services/cloudrunv2/resource_cloud_run_v2_job_test.go index e57a61fb86..5c6ef71afd 100644 --- a/google-beta/services/cloudrunv2/resource_cloud_run_v2_job_test.go +++ b/google-beta/services/cloudrunv2/resource_cloud_run_v2_job_test.go @@ -311,6 +311,7 @@ func testAccCloudRunV2Job_cloudrunv2JobWithDirectVPCAndNamedBinAuthPolicyUpdate( } func TestAccCloudRunV2Job_cloudrunv2JobWithGcsUpdate(t *testing.T) { + acctest.SkipIfVcr(t) t.Parallel() jobName := fmt.Sprintf("tf-test-cloudrun-service%s", acctest.RandString(t, 10)) @@ -399,6 +400,7 @@ func testAccCloudRunV2Job_cloudrunv2JobWithGcsVolume(context map[string]interfac } func TestAccCloudRunV2Job_cloudrunv2JobWithNfsUpdate(t *testing.T) { + acctest.SkipIfVcr(t) t.Parallel() jobName := fmt.Sprintf("tf-test-cloudrun-service%s", acctest.RandString(t, 10)) diff --git a/google-beta/services/cloudrunv2/resource_cloud_run_v2_service_generated_test.go b/google-beta/services/cloudrunv2/resource_cloud_run_v2_service_generated_test.go index 911349fd2f..abc788d294 100644 --- a/google-beta/services/cloudrunv2/resource_cloud_run_v2_service_generated_test.go +++ b/google-beta/services/cloudrunv2/resource_cloud_run_v2_service_generated_test.go @@ -553,6 +553,7 @@ resource "google_cloud_run_v2_service" "default" { } func TestAccCloudRunV2Service_cloudrunv2ServiceMountGcsExample(t *testing.T) { + acctest.SkipIfVcr(t) t.Parallel() context := map[string]interface{}{ @@ -615,6 +616,7 @@ resource "google_storage_bucket" "default" { } func TestAccCloudRunV2Service_cloudrunv2ServiceMountNfsExample(t *testing.T) { + acctest.SkipIfVcr(t) t.Parallel() context := map[string]interface{}{ diff --git a/google-beta/services/cloudrunv2/resource_cloud_run_v2_service_test.go b/google-beta/services/cloudrunv2/resource_cloud_run_v2_service_test.go index ec5fe78f8a..b4e5b6c861 100644 --- a/google-beta/services/cloudrunv2/resource_cloud_run_v2_service_test.go +++ b/google-beta/services/cloudrunv2/resource_cloud_run_v2_service_test.go @@ -211,6 +211,7 @@ resource "google_compute_network" "custom_test" { `, context) } func TestAccCloudRunV2Service_cloudrunv2ServiceGcsVolume(t *testing.T) { + acctest.SkipIfVcr(t) t.Parallel() context := map[string]interface{}{ diff --git a/google-beta/services/composer/resource_composer_environment_test.go b/google-beta/services/composer/resource_composer_environment_test.go index 4023209445..852020d04f 100644 --- a/google-beta/services/composer/resource_composer_environment_test.go +++ b/google-beta/services/composer/resource_composer_environment_test.go @@ -354,6 +354,7 @@ func TestAccComposerEnvironment_withEncryptionConfigComposer1(t *testing.T) { } func TestAccComposerEnvironment_withEncryptionConfigComposer2(t *testing.T) { + acctest.SkipIfVcr(t) t.Parallel() kms := acctest.BootstrapKMSKeyInLocation(t, "us-central1") diff --git a/google-beta/services/compute/resource_compute_address_test.go b/google-beta/services/compute/resource_compute_address_test.go index 3cb2d34966..a757c933ed 100644 --- a/google-beta/services/compute/resource_compute_address_test.go +++ b/google-beta/services/compute/resource_compute_address_test.go @@ -526,6 +526,10 @@ func TestAccComputeAddress_withAttributionRemoved(t *testing.T) { func testAccComputeAddress_networkTier_withLabels(i string) string { return fmt.Sprintf(` +provider "google" { + add_terraform_attribution_label = false +} + resource "google_compute_address" "foobar" { name = "tf-test-address-%s" network_tier = "STANDARD" @@ -540,6 +544,10 @@ resource "google_compute_address" "foobar" { func testAccComputeAddress_networkTier_withLabelsUpdate(i string) string { return fmt.Sprintf(` +provider "google" { + add_terraform_attribution_label = false +} + resource "google_compute_address" "foobar" { name = "tf-test-address-%s" network_tier = "STANDARD" @@ -558,6 +566,7 @@ provider "google" { default_labels = { default_key1 = "default_value1" } + add_terraform_attribution_label = false } resource "google_compute_address" "foobar" { @@ -578,6 +587,7 @@ provider "google" { default_labels = { default_key1 = "default_value1" } + add_terraform_attribution_label = false } resource "google_compute_address" "foobar" { @@ -600,6 +610,7 @@ provider "google" { default_key1 = "default_value1" env = "foo" } + add_terraform_attribution_label = false } resource "google_compute_address" "foobar" { @@ -750,6 +761,10 @@ resource "google_compute_address" "internal_with_subnet_and_address" { func testAccComputeAddress_networkTier(i string) string { return fmt.Sprintf(` +provider "google" { + add_terraform_attribution_label = false +} + resource "google_compute_address" "foobar" { name = "tf-test-address-%s" network_tier = "STANDARD" diff --git a/google-beta/services/compute/resource_compute_forwarding_rule.go b/google-beta/services/compute/resource_compute_forwarding_rule.go index b40f144436..ce4e43bb6b 100644 --- a/google-beta/services/compute/resource_compute_forwarding_rule.go +++ b/google-beta/services/compute/resource_compute_forwarding_rule.go @@ -123,7 +123,7 @@ func ResourceComputeForwardingRule() *schema.Resource { CustomizeDiff: customdiff.All( forwardingRuleCustomizeDiff, - tpgresource.SetLabelsDiff, + tpgresource.SetLabelsDiffWithoutAttributionLabel, tpgresource.DefaultProviderProject, ), diff --git a/google-beta/services/compute/resource_compute_global_forwarding_rule.go b/google-beta/services/compute/resource_compute_global_forwarding_rule.go index 9cf66a0138..a2fb882a32 100644 --- a/google-beta/services/compute/resource_compute_global_forwarding_rule.go +++ b/google-beta/services/compute/resource_compute_global_forwarding_rule.go @@ -51,7 +51,7 @@ func ResourceComputeGlobalForwardingRule() *schema.Resource { }, CustomizeDiff: customdiff.All( - tpgresource.SetLabelsDiff, + tpgresource.SetLabelsDiffWithoutAttributionLabel, tpgresource.DefaultProviderProject, ), diff --git a/google-beta/services/compute/resource_compute_network_peering_routes_config_generated_test.go b/google-beta/services/compute/resource_compute_network_peering_routes_config_generated_test.go index 73ae2951a8..86dcc3ae1f 100644 --- a/google-beta/services/compute/resource_compute_network_peering_routes_config_generated_test.go +++ b/google-beta/services/compute/resource_compute_network_peering_routes_config_generated_test.go @@ -87,6 +87,7 @@ resource "google_compute_network" "network_secondary" { } func TestAccComputeNetworkPeeringRoutesConfig_networkPeeringRoutesConfigGkeExample(t *testing.T) { + acctest.SkipIfVcr(t) t.Parallel() context := map[string]interface{}{ diff --git a/google-beta/services/container/data_source_google_container_cluster_test.go b/google-beta/services/container/data_source_google_container_cluster_test.go index ff60219dae..87da147519 100644 --- a/google-beta/services/container/data_source_google_container_cluster_test.go +++ b/google-beta/services/container/data_source_google_container_cluster_test.go @@ -62,6 +62,7 @@ func TestAccContainerClusterDatasource_regional(t *testing.T) { "enable_tpu": {}, "pod_security_policy_config.#": {}, "deletion_protection": {}, + "resource_labels": {}, }, ), ), diff --git a/google-beta/services/container/resource_container_cluster_test.go b/google-beta/services/container/resource_container_cluster_test.go index 64f25a0785..0760d09912 100644 --- a/google-beta/services/container/resource_container_cluster_test.go +++ b/google-beta/services/container/resource_container_cluster_test.go @@ -10735,6 +10735,7 @@ resource "google_container_cluster" "with_autopilot" { } func TestAccContainerCluster_privateRegistry(t *testing.T) { + acctest.SkipIfVcr(t) t.Parallel() clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) diff --git a/google-beta/services/container/resource_container_node_pool_test.go b/google-beta/services/container/resource_container_node_pool_test.go index ece1243428..e58bde0a24 100644 --- a/google-beta/services/container/resource_container_node_pool_test.go +++ b/google-beta/services/container/resource_container_node_pool_test.go @@ -4856,6 +4856,7 @@ resource "google_container_node_pool" "np" { } func TestAccContainerNodePool_defaultDriverInstallation(t *testing.T) { + acctest.SkipIfVcr(t) t.Parallel() cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) diff --git a/google-beta/services/dataplex/resource_dataplex_datascan.go b/google-beta/services/dataplex/resource_dataplex_datascan.go index f9fc8e585a..d38a8c8091 100644 --- a/google-beta/services/dataplex/resource_dataplex_datascan.go +++ b/google-beta/services/dataplex/resource_dataplex_datascan.go @@ -51,7 +51,7 @@ func ResourceDataplexDatascan() *schema.Resource { }, CustomizeDiff: customdiff.All( - tpgresource.SetLabelsDiff, + tpgresource.SetLabelsDiffWithoutAttributionLabel, tpgresource.DefaultProviderProject, ), diff --git a/google-beta/services/dataplex/resource_dataplex_task.go b/google-beta/services/dataplex/resource_dataplex_task.go index 08f51ceca7..f8e5ebdc59 100644 --- a/google-beta/services/dataplex/resource_dataplex_task.go +++ b/google-beta/services/dataplex/resource_dataplex_task.go @@ -51,7 +51,7 @@ func ResourceDataplexTask() *schema.Resource { }, CustomizeDiff: customdiff.All( - tpgresource.SetLabelsDiff, + tpgresource.SetLabelsDiffWithoutAttributionLabel, tpgresource.DefaultProviderProject, ), diff --git a/google-beta/services/dataproc/resource_dataproc_cluster.go b/google-beta/services/dataproc/resource_dataproc_cluster.go index 000c31917b..43520a371a 100644 --- a/google-beta/services/dataproc/resource_dataproc_cluster.go +++ b/google-beta/services/dataproc/resource_dataproc_cluster.go @@ -189,7 +189,8 @@ func ResourceDataprocCluster() *schema.Resource { CustomizeDiff: customdiff.All( tpgresource.DefaultProviderProject, - tpgresource.SetLabelsDiff, + // User labels are not supported in Dataproc Virtual Cluster + tpgresource.SetLabelsDiffWithoutAttributionLabel, ), SchemaVersion: 1, diff --git a/google-beta/services/edgecontainer/resource_edgecontainer_cluster_generated_test.go b/google-beta/services/edgecontainer/resource_edgecontainer_cluster_generated_test.go index 773407676e..fe0e8ecd25 100644 --- a/google-beta/services/edgecontainer/resource_edgecontainer_cluster_generated_test.go +++ b/google-beta/services/edgecontainer/resource_edgecontainer_cluster_generated_test.go @@ -31,6 +31,7 @@ import ( ) func TestAccEdgecontainerCluster_edgecontainerClusterExample(t *testing.T) { + acctest.SkipIfVcr(t) t.Parallel() context := map[string]interface{}{ @@ -87,6 +88,7 @@ data "google_project" "project" {} } func TestAccEdgecontainerCluster_edgecontainerClusterWithMaintenanceWindowExample(t *testing.T) { + acctest.SkipIfVcr(t) t.Parallel() context := map[string]interface{}{ diff --git a/google-beta/services/kms/resource_kms_autokey_config_generated_test.go b/google-beta/services/kms/resource_kms_autokey_config_generated_test.go index 9476c7174f..18f0e45853 100644 --- a/google-beta/services/kms/resource_kms_autokey_config_generated_test.go +++ b/google-beta/services/kms/resource_kms_autokey_config_generated_test.go @@ -32,6 +32,7 @@ import ( ) func TestAccKMSAutokeyConfig_kmsAutokeyConfigAllExample(t *testing.T) { + acctest.SkipIfVcr(t) t.Parallel() context := map[string]interface{}{ diff --git a/google-beta/services/kms/resource_kms_key_handle_generated_test.go b/google-beta/services/kms/resource_kms_key_handle_generated_test.go index 057183c7d5..a64ce59f54 100644 --- a/google-beta/services/kms/resource_kms_key_handle_generated_test.go +++ b/google-beta/services/kms/resource_kms_key_handle_generated_test.go @@ -27,6 +27,7 @@ import ( ) func TestAccKMSKeyHandle_kmsKeyHandleBasicExample(t *testing.T) { + acctest.SkipIfVcr(t) t.Parallel() context := map[string]interface{}{ diff --git a/google-beta/services/networksecurity/resource_network_security_client_tls_policy_generated_test.go b/google-beta/services/networksecurity/resource_network_security_client_tls_policy_generated_test.go index 0c346ccde8..64bd0a4888 100644 --- a/google-beta/services/networksecurity/resource_network_security_client_tls_policy_generated_test.go +++ b/google-beta/services/networksecurity/resource_network_security_client_tls_policy_generated_test.go @@ -31,6 +31,7 @@ import ( ) func TestAccNetworkSecurityClientTlsPolicy_networkSecurityClientTlsPolicyBasicExample(t *testing.T) { + acctest.SkipIfVcr(t) t.Parallel() context := map[string]interface{}{ @@ -70,6 +71,7 @@ resource "google_network_security_client_tls_policy" "default" { } func TestAccNetworkSecurityClientTlsPolicy_networkSecurityClientTlsPolicyAdvancedExample(t *testing.T) { + acctest.SkipIfVcr(t) t.Parallel() context := map[string]interface{}{ diff --git a/google-beta/services/networksecurity/resource_network_security_client_tls_policy_test.go b/google-beta/services/networksecurity/resource_network_security_client_tls_policy_test.go index 9b5cb2f215..92f67c0635 100644 --- a/google-beta/services/networksecurity/resource_network_security_client_tls_policy_test.go +++ b/google-beta/services/networksecurity/resource_network_security_client_tls_policy_test.go @@ -11,6 +11,7 @@ import ( ) func TestAccNetworkSecurityClientTlsPolicy_update(t *testing.T) { + acctest.SkipIfVcr(t) t.Parallel() clientTlsPolicyName := fmt.Sprintf("tf-test-client-tls-policy-%s", acctest.RandString(t, 10)) diff --git a/google-beta/services/networkservices/resource_network_services_lb_route_extension_test.go b/google-beta/services/networkservices/resource_network_services_lb_route_extension_test.go index ffc80b5e1a..c4970ffddf 100644 --- a/google-beta/services/networkservices/resource_network_services_lb_route_extension_test.go +++ b/google-beta/services/networkservices/resource_network_services_lb_route_extension_test.go @@ -10,6 +10,7 @@ import ( ) func TestAccNetworkServicesLbRouteExtension_update(t *testing.T) { + acctest.SkipIfVcr(t) t.Parallel() context := map[string]interface{}{ diff --git a/google-beta/services/resourcemanager/resource_google_project_test.go b/google-beta/services/resourcemanager/resource_google_project_test.go index 5397d36ee9..1ae141d904 100644 --- a/google-beta/services/resourcemanager/resource_google_project_test.go +++ b/google-beta/services/resourcemanager/resource_google_project_test.go @@ -469,6 +469,10 @@ resource "google_project" "acceptance" { func testAccProject_labels(pid, org string, labels map[string]string) string { r := fmt.Sprintf(` +provider "google" { + add_terraform_attribution_label = false +} + resource "google_project" "acceptance" { project_id = "%s" name = "%s" diff --git a/google-beta/services/secretmanager/data_source_secret_manager_secrets_test.go b/google-beta/services/secretmanager/data_source_secret_manager_secrets_test.go index a17f259c1c..76df596326 100644 --- a/google-beta/services/secretmanager/data_source_secret_manager_secrets_test.go +++ b/google-beta/services/secretmanager/data_source_secret_manager_secrets_test.go @@ -32,8 +32,11 @@ func TestAccDataSourceSecretManagerSecrets_basic(t *testing.T) { "data.google_secret_manager_secrets.foo", "google_secret_manager_secret.foo", map[string]struct{}{ - "id": {}, - "project": {}, + "id": {}, + "project": {}, + "effective_labels": {}, + "labels": {}, + "terraform_labels": {}, }, ), ), @@ -44,6 +47,10 @@ func TestAccDataSourceSecretManagerSecrets_basic(t *testing.T) { func testAccDataSourceSecretManagerSecrets_basic(context map[string]interface{}) string { return acctest.Nprintf(` +provider "google" { + add_terraform_attribution_label = false +} + resource "google_secret_manager_secret" "foo" { secret_id = "tf-test-secret-%{random_suffix}" @@ -84,8 +91,11 @@ func TestAccDataSourceSecretManagerSecrets_filter(t *testing.T) { "google_secret_manager_secret.foo", "google_secret_manager_secret.bar", map[string]struct{}{ - "id": {}, - "project": {}, + "id": {}, + "project": {}, + "effective_labels": {}, + "labels": {}, + "terraform_labels": {}, }, ), ), @@ -96,6 +106,10 @@ func TestAccDataSourceSecretManagerSecrets_filter(t *testing.T) { func testAccDataSourceSecretManagerSecrets_filter(context map[string]interface{}) string { return acctest.Nprintf(` +provider "google" { + add_terraform_attribution_label = false +} + resource "google_secret_manager_secret" "foo" { secret_id = "tf-test-secret-%{random_suffix}" diff --git a/google-beta/services/vertexai/resource_vertex_ai_feature_online_store_featureview_generated_test.go b/google-beta/services/vertexai/resource_vertex_ai_feature_online_store_featureview_generated_test.go index 979fe484c3..c331d14471 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_feature_online_store_featureview_generated_test.go +++ b/google-beta/services/vertexai/resource_vertex_ai_feature_online_store_featureview_generated_test.go @@ -429,6 +429,7 @@ resource "google_vertex_ai_feature_online_store_featureview" "cross_project_feat } func TestAccVertexAIFeatureOnlineStoreFeatureview_vertexAiFeatureonlinestoreFeatureviewWithVectorSearchExample(t *testing.T) { + acctest.SkipIfVcr(t) t.Parallel() context := map[string]interface{}{ diff --git a/google-beta/services/vertexai/resource_vertex_ai_feature_online_store_generated_test.go b/google-beta/services/vertexai/resource_vertex_ai_feature_online_store_generated_test.go index 25571805f9..24d78b430e 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_feature_online_store_generated_test.go +++ b/google-beta/services/vertexai/resource_vertex_ai_feature_online_store_generated_test.go @@ -124,6 +124,7 @@ data "google_project" "project" { } func TestAccVertexAIFeatureOnlineStore_vertexAiFeatureonlinestoreWithBetaFieldsBigtableExample(t *testing.T) { + acctest.SkipIfVcr(t) t.Parallel() context := map[string]interface{}{ diff --git a/google-beta/services/vertexai/resource_vertex_ai_index_endpoint_test.go b/google-beta/services/vertexai/resource_vertex_ai_index_endpoint_test.go index 628dedfcd5..4f7b8022fe 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_index_endpoint_test.go +++ b/google-beta/services/vertexai/resource_vertex_ai_index_endpoint_test.go @@ -11,6 +11,7 @@ import ( ) func TestAccVertexAIIndexEndpoint_updated(t *testing.T) { + acctest.SkipIfVcr(t) t.Parallel() context := map[string]interface{}{ diff --git a/google-beta/tpgresource/labels.go b/google-beta/tpgresource/labels.go index cbcdcde818..ffb1515cf1 100644 --- a/google-beta/tpgresource/labels.go +++ b/google-beta/tpgresource/labels.go @@ -58,7 +58,7 @@ func SetDataSourceLabels(d *schema.ResourceData) error { } // Sets the values of terraform_labels and effective_labels fields when labels field is in root level -func setLabelsFields(labelsField string, d *schema.ResourceDiff, meta interface{}) error { +func setLabelsFields(labelsField string, d *schema.ResourceDiff, meta interface{}, skipAttribution bool) error { raw := d.Get(labelsField) if raw == nil { return nil @@ -94,7 +94,7 @@ func setLabelsFields(labelsField string, d *schema.ResourceDiff, meta interface{ } // Append optional label indicating the resource was provisioned using Terraform - if config.AddTerraformAttributionLabel { + if !skipAttribution && config.AddTerraformAttributionLabel { if el, ok := d.Get("effective_labels").(map[string]any); ok { _, hasExistingLabel := el[transport_tpg.AttributionKey] if hasExistingLabel || @@ -134,17 +134,21 @@ func setLabelsFields(labelsField string, d *schema.ResourceDiff, meta interface{ return nil } +func SetLabelsDiffWithoutAttributionLabel(_ context.Context, d *schema.ResourceDiff, meta interface{}) error { + return setLabelsFields("labels", d, meta, true) +} + // The CustomizeDiff func to set the values of terraform_labels and effective_labels fields // when labels field is at the root level and named "labels". func SetLabelsDiff(_ context.Context, d *schema.ResourceDiff, meta interface{}) error { - return setLabelsFields("labels", d, meta) + return setLabelsFields("labels", d, meta, false) } // The CustomizeDiff func to set the values of terraform_labels and effective_labels fields // when labels field is at the root level and has a diffent name (e.g. resource_labels) than "labels" func SetDiffForLabelsWithCustomizedName(labelsField string) func(_ context.Context, d *schema.ResourceDiff, meta interface{}) error { return func(_ context.Context, d *schema.ResourceDiff, meta interface{}) error { - return setLabelsFields(labelsField, d, meta) + return setLabelsFields(labelsField, d, meta, false) } } diff --git a/website/docs/guides/provider_reference.html.markdown b/website/docs/guides/provider_reference.html.markdown index 8b03ef4350..9adb671d0a 100644 --- a/website/docs/guides/provider_reference.html.markdown +++ b/website/docs/guides/provider_reference.html.markdown @@ -277,8 +277,9 @@ automatically to resources, and will be returned in the `terraform_labels` and `effective_labels` fields. This makes it possible to distinguish Terraform resources when using other tools like Cloud Console or gcloud. -The default value is `false`. No label will be added unless the provider is -explicitly configured to do so by setting the value to `true`. +The default value is `true`. Unless explicitly configured (along with +`terraform_attribution_label_addition_strategy`, described below) the label +be added to newly provisioned resources. --- diff --git a/website/docs/guides/version_6_upgrade.html.markdown b/website/docs/guides/version_6_upgrade.html.markdown index b2acc21c30..1aaa4cddf7 100644 --- a/website/docs/guides/version_6_upgrade.html.markdown +++ b/website/docs/guides/version_6_upgrade.html.markdown @@ -97,6 +97,21 @@ Previously, the max length of `name_prefix` was 37 characters since the autogene the total max length for names of 63 characters. In 6.0, providing a `name_prefix` larger than 37 characters will prompt the provider to use a shortened suffix of only 9 characters, leading to a new max of 54 characters for `name_prefix`. This shortened suffix is inevitably more prone to collisions, so use the longer max `name_prefix` length with caution. +### Provider attribution label is enabled by default + +Version 5.0.0 introduced the `goog-terraform-provisioned = true` label that could +be automatically added to resources, making it easy to identify resources created +by the provider when using other tools such as `gcloud` or the GCP web console. In +5.0.0 the label needed to be enabled explicitly; in 6.0.0 the default is to add the +label to all newly created resources. This behavior can be disabled in the provider +configuration. For example: + +```hcl +provider "google" { + add_terraform_attribution_label = false +} +``` + ## Datasources ## Datasource: `google_product_datasource`