Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable goog-terraform-provisioned provider label #8004

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/11439.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:breaking-change
changed provider labels to add the `goog-terraform-provisioned: true` label by default.
```
5 changes: 1 addition & 4 deletions google-beta/acctest/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "%" {
Expand Down
15 changes: 15 additions & 0 deletions google-beta/acctest/vcr_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"path/filepath"
"reflect"
"regexp"
"slices"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion google-beta/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func Provider() *schema.Provider {
"add_terraform_attribution_label": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},

"terraform_attribution_label_addition_strategy": {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
)

func TestAccDataSourceArtifactRegistryDockerImage(t *testing.T) {
acctest.SkipIfVcr(t)
t.Parallel()

resourceName := "data.google_artifact_registry_docker_image.test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ provider "google" {
default_labels = {
default_key1 = "default_value1"
}
add_terraform_attribution_label = false
}

resource "google_clouddeploy_target" "primary" {
Expand Down Expand Up @@ -177,6 +178,7 @@ provider "google" {
default_labels = {
default_key1 = "default_value1"
}
add_terraform_attribution_label = false
}

resource "google_clouddeploy_target" "primary" {
Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -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}"
Expand All @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ provider "google" {
default_labels = {
default_key1 = "default_value1"
}
add_terraform_attribution_label = false
}

resource "google_cloud_run_service" "default" {
Expand Down Expand Up @@ -670,6 +671,7 @@ provider "google" {
default_labels = {
default_key1 = "default_value1"
}
add_terraform_attribution_label = false
}

resource "google_cloud_run_service" "default" {
Expand Down Expand Up @@ -711,6 +713,7 @@ provider "google" {
default_key1 = "default_value1"
env = "foo"
}
add_terraform_attribution_label = false
}

resource "google_cloud_run_service" "default" {
Expand Down Expand Up @@ -1308,6 +1311,7 @@ resource "google_cloud_run_service" "default" {
}

func TestAccCloudRunService_csiVolume(t *testing.T) {
acctest.SkipIfVcr(t)
t.Parallel()

project := envvar.GetTestProjectFromEnv()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{
Expand Down Expand Up @@ -615,6 +616,7 @@ resource "google_storage_bucket" "default" {
}

func TestAccCloudRunV2Service_cloudrunv2ServiceMountNfsExample(t *testing.T) {
acctest.SkipIfVcr(t)
t.Parallel()

context := map[string]interface{}{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
15 changes: 15 additions & 0 deletions google-beta/services/compute/resource_compute_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -558,6 +566,7 @@ provider "google" {
default_labels = {
default_key1 = "default_value1"
}
add_terraform_attribution_label = false
}

resource "google_compute_address" "foobar" {
Expand All @@ -578,6 +587,7 @@ provider "google" {
default_labels = {
default_key1 = "default_value1"
}
add_terraform_attribution_label = false
}

resource "google_compute_address" "foobar" {
Expand All @@ -600,6 +610,7 @@ provider "google" {
default_key1 = "default_value1"
env = "foo"
}
add_terraform_attribution_label = false
}

resource "google_compute_address" "foobar" {
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func ResourceComputeForwardingRule() *schema.Resource {

CustomizeDiff: customdiff.All(
forwardingRuleCustomizeDiff,
tpgresource.SetLabelsDiff,
tpgresource.SetLabelsDiffWithoutAttributionLabel,
tpgresource.DefaultProviderProject,
),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func ResourceComputeGlobalForwardingRule() *schema.Resource {
},

CustomizeDiff: customdiff.All(
tpgresource.SetLabelsDiff,
tpgresource.SetLabelsDiffWithoutAttributionLabel,
tpgresource.DefaultProviderProject,
),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func TestAccContainerClusterDatasource_regional(t *testing.T) {
"enable_tpu": {},
"pod_security_policy_config.#": {},
"deletion_protection": {},
"resource_labels": {},
},
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Loading