Skip to content
Open
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: 2 additions & 1 deletion mmv1/products/tags/TagKey.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ iam_policy:
parent_resource_attribute: 'tag_key'
iam_conditions_request_type: 'REQUEST_BODY'
custom_code:
constants: 'templates/terraform/constants/tags.go.tmpl'
exclude_tgc: true
examples:
- name: 'tag_key_basic'
Expand Down Expand Up @@ -125,7 +126,7 @@ properties:

Purpose data corresponds to the policy system that the tag is intended for. For example, the GCE_FIREWALL purpose expects data in the following format: `network = "<project-name>/<vpc-name>"`.
immutable: true
ignore_read: true
diff_suppress_func: 'TagKeyPurposeDataDiffSuppress'
- name: 'allowedValuesRegex'
type: String
description: |
Expand Down
13 changes: 13 additions & 0 deletions mmv1/templates/terraform/constants/tags.go.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// TagKeyPurposeDataDiffSuppress suppresses diffs for purpose_data when the API
// returns normalized values. For example, the API may resolve "auto" to an
// actual organization number. Since purpose_data is immutable, if the old value
// (from state) exists and is non-empty, we suppress the diff to avoid
// unnecessary replacements after import.
func TagKeyPurposeDataDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm understanding correctly, wouldn't this also prevent someone from changing purpose_data in their config (and getting a plan to replace the tag key)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes that would be the case. Do you have any recommendations on how to get around the issue?
hashicorp/terraform-provider-google#20073

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roaks3 for more context, we are trying to import these secure tag keys. However, since purpose_data is not imported by provider, terraform is forcing replacements of the tag keys which we do not want as they are in use

// If the old value exists and the field is set in state, suppress the diff
// since the API normalizes values (e.g., "auto" -> actual org number)
if old != "" && new != "" {
return true
}
return false
}
Loading