From 651d9428bde43441870fd18c90854f129bdb0a7a Mon Sep 17 00:00:00 2001 From: Cameron Thornton Date: Mon, 19 Aug 2024 12:20:09 -0500 Subject: [PATCH] add SetLabelsDiffWithoutAttributionLabel --- mmv1/api/resource.rb | 10 +++++++++- mmv1/products/compute/ForwardingRule.yaml | 2 ++ mmv1/products/compute/GlobalForwardingRule.yaml | 2 ++ mmv1/products/dataplex/Datascan.yaml | 2 ++ mmv1/products/dataplex/Task.yaml | 2 ++ .../services/dataproc/resource_dataproc_cluster.go | 3 ++- .../data_source_secret_manager_secrets_test.go | 14 ++++++++++---- mmv1/third_party/terraform/tpgresource/labels.go | 11 +++++++++++ 8 files changed, 40 insertions(+), 6 deletions(-) diff --git a/mmv1/api/resource.rb b/mmv1/api/resource.rb index 98d2b0fe775a..9cbc3215db20 100644 --- a/mmv1/api/resource.rb +++ b/mmv1/api/resource.rb @@ -250,6 +250,9 @@ module Properties # Add a deprecation message for a resource that's been deprecated in the API. attr_reader :deprecation_message + + # Do not apply the default attribution label + attr_reader :skip_attribution_label end include Properties @@ -342,6 +345,7 @@ def validate check :taint_resource_on_failed_create, type: :boolean, default: false check :skip_sweeper, type: :boolean, default: false check :deprecation_message, type: ::String + check :skip_attribution_label, type: :boolean, default: false validate_identity unless @identity.nil? end @@ -475,7 +479,11 @@ def add_labels_related_fields(props, parent) def add_labels_fields(props, parent, labels) @custom_diff ||= [] if parent.nil? || parent.flatten_object - @custom_diff.append('tpgresource.SetLabelsDiff') + if @skip_attribution_label + @custom_diff.append('tpgresource.SetLabelsDiffWithoutAttributionLabel') + else + @custom_diff.append('tpgresource.SetLabelsDiff') + end elsif parent.name == 'metadata' @custom_diff.append('tpgresource.SetMetadataLabelsDiff') end diff --git a/mmv1/products/compute/ForwardingRule.yaml b/mmv1/products/compute/ForwardingRule.yaml index c000581a39c4..3f3674ed87ca 100644 --- a/mmv1/products/compute/ForwardingRule.yaml +++ b/mmv1/products/compute/ForwardingRule.yaml @@ -17,6 +17,8 @@ kind: 'compute#forwardingRule' base_url: projects/{{project}}/regions/{{region}}/forwardingRules collection_url_key: 'items' has_self_link: true +# Has a separate endpoint for labels +skip_attribution_label: true description: | A ForwardingRule resource. A ForwardingRule resource specifies which pool of target virtual machines to forward a packet to if it matches the given diff --git a/mmv1/products/compute/GlobalForwardingRule.yaml b/mmv1/products/compute/GlobalForwardingRule.yaml index 439777281782..d39c85bf8da5 100644 --- a/mmv1/products/compute/GlobalForwardingRule.yaml +++ b/mmv1/products/compute/GlobalForwardingRule.yaml @@ -17,6 +17,8 @@ kind: 'compute#forwardingRule' base_url: projects/{{project}}/global/forwardingRules immutable: true has_self_link: true +# Has a separate endpoint for labels +skip_attribution_label: true legacy_long_form_project: true collection_url_key: 'items' description: | diff --git a/mmv1/products/dataplex/Datascan.yaml b/mmv1/products/dataplex/Datascan.yaml index c1c71bed0dc2..eb70d4b116e4 100644 --- a/mmv1/products/dataplex/Datascan.yaml +++ b/mmv1/products/dataplex/Datascan.yaml @@ -18,6 +18,8 @@ self_link: 'projects/{{project}}/locations/{{location}}/dataScans/{{data_scan_id create_url: 'projects/{{project}}/locations/{{location}}/dataScans?dataScanId={{data_scan_id}}' update_verb: :PATCH update_mask: true +# User-provided label cannot start with goog- +skip_attribution_label: true import_format: [ 'projects/{{project}}/locations/{{location}}/dataScans/{{data_scan_id}}', diff --git a/mmv1/products/dataplex/Task.yaml b/mmv1/products/dataplex/Task.yaml index 66ed12c16dbb..ecd20a1b7be5 100644 --- a/mmv1/products/dataplex/Task.yaml +++ b/mmv1/products/dataplex/Task.yaml @@ -19,6 +19,8 @@ update_url: 'projects/{{project}}/locations/{{location}}/lakes/{{lake}}/tasks/{{ delete_url: 'projects/{{project}}/locations/{{location}}/lakes/{{lake}}/tasks/{{task_id}}' update_verb: :PATCH update_mask: true +# User-provided label cannot start with goog- +skip_attribution_label: true description: | A Dataplex task represents the work that you want Dataplex to do on a schedule. It encapsulates code, parameters, and the schedule. async: !ruby/object:Api::OpAsync diff --git a/mmv1/third_party/terraform/services/dataproc/resource_dataproc_cluster.go b/mmv1/third_party/terraform/services/dataproc/resource_dataproc_cluster.go index 0abed2ab6332..8535f48d4833 100644 --- a/mmv1/third_party/terraform/services/dataproc/resource_dataproc_cluster.go +++ b/mmv1/third_party/terraform/services/dataproc/resource_dataproc_cluster.go @@ -187,7 +187,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/mmv1/third_party/terraform/services/secretmanager/data_source_secret_manager_secrets_test.go b/mmv1/third_party/terraform/services/secretmanager/data_source_secret_manager_secrets_test.go index 792e9bb41875..804c1539ad8c 100644 --- a/mmv1/third_party/terraform/services/secretmanager/data_source_secret_manager_secrets_test.go +++ b/mmv1/third_party/terraform/services/secretmanager/data_source_secret_manager_secrets_test.go @@ -30,8 +30,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": {}, }, ), ), @@ -82,8 +85,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": {}, }, ), ), diff --git a/mmv1/third_party/terraform/tpgresource/labels.go b/mmv1/third_party/terraform/tpgresource/labels.go index 147508993e81..b1e1f52d52bb 100644 --- a/mmv1/third_party/terraform/tpgresource/labels.go +++ b/mmv1/third_party/terraform/tpgresource/labels.go @@ -55,6 +55,17 @@ func SetDataSourceLabels(d *schema.ResourceData) error { return nil } +func SetLabelsDiffWithoutAttributionLabel(c context.Context, d *schema.ResourceDiff, meta interface{}) error { + config := meta.(*transport_tpg.Config) + previouslySetValue := config.AddTerraformAttributionLabel + config.AddTerraformAttributionLabel = false + + err := SetLabelsDiff(c, d, meta) + + config.AddTerraformAttributionLabel = previouslySetValue + return err +} + func SetLabelsDiff(_ context.Context, d *schema.ResourceDiff, meta interface{}) error { raw := d.Get("labels") if raw == nil {