Skip to content

Commit

Permalink
add SetLabelsDiffWithoutAttributionLabel
Browse files Browse the repository at this point in the history
  • Loading branch information
c2thorn committed Aug 19, 2024
1 parent f3d2e34 commit 7c2a112
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 6 deletions.
10 changes: 9 additions & 1 deletion mmv1/api/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions mmv1/products/compute/ForwardingRule.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions mmv1/products/compute/GlobalForwardingRule.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 2 additions & 0 deletions mmv1/products/dataplex/Datascan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}',
Expand Down
2 changes: 2 additions & 0 deletions mmv1/products/dataplex/Task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
},
),
),
Expand Down Expand Up @@ -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": {},
},
),
),
Expand Down
11 changes: 11 additions & 0 deletions mmv1/third_party/terraform/tpgresource/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ func setLabelsFields(labelsField string, d *schema.ResourceDiff, meta interface{
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
}

// 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 {
Expand Down

0 comments on commit 7c2a112

Please sign in to comment.