diff --git a/mmv1/products/cloudrun/terraform.yaml b/mmv1/products/cloudrun/terraform.yaml index c08369684ca1..e6869c43e052 100644 --- a/mmv1/products/cloudrun/terraform.yaml +++ b/mmv1/products/cloudrun/terraform.yaml @@ -189,6 +189,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides custom_expand: "templates/terraform/custom_expand/default_to_project.go.erb" metadata.labels: !ruby/object:Overrides::Terraform::PropertyOverride default_from_api: true + diff_suppress_func: 'cloudrunLabelDiffSuppress' metadata.annotations: !ruby/object:Overrides::Terraform::PropertyOverride default_from_api: true diff_suppress_func: 'cloudrunAnnotationDiffSuppress' diff --git a/mmv1/templates/terraform/constants/cloud_run_service.go.erb b/mmv1/templates/terraform/constants/cloud_run_service.go.erb index ea49598be993..918394918ec2 100644 --- a/mmv1/templates/terraform/constants/cloud_run_service.go.erb +++ b/mmv1/templates/terraform/constants/cloud_run_service.go.erb @@ -6,7 +6,7 @@ func revisionNameCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v i return nil } -var cloudRunGoogleProvidedAnnotations = regexp.MustCompile(`serving\\.knative\\.dev/(?:(?:creator)|(?:lastModifier))$|run\\.googleapis\\.com/(?:(?:ingress-status))$`) +var cloudRunGoogleProvidedAnnotations = regexp.MustCompile(`serving\.knative\.dev/(?:(?:creator)|(?:lastModifier))$|run\.googleapis\.com/(?:(?:ingress-status))$|cloud\.googleapis\.com/(?:(?:location))`) func cloudrunAnnotationDiffSuppress(k, old, new string, d *schema.ResourceData) bool { // Suppress diffs for the annotations provided by Google @@ -21,4 +21,21 @@ func cloudrunAnnotationDiffSuppress(k, old, new string, d *schema.ResourceData) // For other keys, don't suppress diff. return false -} \ No newline at end of file +} + +var cloudRunGoogleProvidedLabels = regexp.MustCompile(`cloud\.googleapis\.com/(?:(?:location))`) + +func cloudrunLabelDiffSuppress(k, old, new string, d *schema.ResourceData) bool { + // Suppress diffs for the labels provided by Google + if cloudRunGoogleProvidedLabels.MatchString(k) && new == "" { + return true + } + + // Let diff be determined by labels (above) + if strings.Contains(k, "labels.%") { + return true + } + + // For other keys, don't suppress diff. + return false +}