diff --git a/mmv1/products/tags/TagKey.yaml b/mmv1/products/tags/TagKey.yaml index ff5f57139453..a40e746f9130 100644 --- a/mmv1/products/tags/TagKey.yaml +++ b/mmv1/products/tags/TagKey.yaml @@ -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' @@ -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 = "/"`. immutable: true - ignore_read: true + diff_suppress_func: 'TagKeyPurposeDataDiffSuppress' - name: 'allowedValuesRegex' type: String description: | diff --git a/mmv1/templates/terraform/constants/tags.go.tmpl b/mmv1/templates/terraform/constants/tags.go.tmpl new file mode 100644 index 000000000000..9f9595fcb59f --- /dev/null +++ b/mmv1/templates/terraform/constants/tags.go.tmpl @@ -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 { + // 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 +}