diff --git a/.changelog/4186.txt b/.changelog/4186.txt new file mode 100644 index 0000000000..711d083111 --- /dev/null +++ b/.changelog/4186.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +run: patched `google_cloud_run_service` to suppress Google generated annotations +``` diff --git a/google-beta/resource_cloud_run_service.go b/google-beta/resource_cloud_run_service.go index a92b290a02..b3ab732f60 100644 --- a/google-beta/resource_cloud_run_service.go +++ b/google-beta/resource_cloud_run_service.go @@ -20,6 +20,7 @@ import ( "log" "reflect" "strconv" + "strings" "time" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -34,6 +35,23 @@ func revisionNameCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v i return nil } +const cloudRunGoogleProvidedAnnotation = "serving.knative.dev" + +func cloudrunAnnotationDiffSuppress(k, old, new string, d *schema.ResourceData) bool { + // Suppress diffs for the annotations provided by Google + if strings.Contains(k, cloudRunGoogleProvidedAnnotation) && new == "" { + return true + } + + // Let diff be determined by annotations (above) + if strings.Contains(k, "annotations.%") { + return true + } + + // For other keys, don't suppress diff. + return false +} + func resourceCloudRunService() *schema.Resource { return &schema.Resource{ Create: resourceCloudRunServiceCreate, @@ -485,9 +503,10 @@ and annotations.`, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "annotations": { - Type: schema.TypeMap, - Computed: true, - Optional: true, + Type: schema.TypeMap, + Computed: true, + Optional: true, + DiffSuppressFunc: cloudrunAnnotationDiffSuppress, Description: `Annotations is a key value map stored with a resource that may be set by external tools to store and retrieve arbitrary metadata. More info: http://kubernetes.io/docs/user-guide/annotations`, diff --git a/google-beta/resource_cloud_run_service_generated_test.go b/google-beta/resource_cloud_run_service_generated_test.go index d1ec7957c8..c114590c47 100644 --- a/google-beta/resource_cloud_run_service_generated_test.go +++ b/google-beta/resource_cloud_run_service_generated_test.go @@ -254,6 +254,12 @@ resource "google_cloud_run_service" "default" { } } + metadata { + annotations = { + generated-by = "magic-modules" + } + } + traffic { percent = 100 latest_revision = true diff --git a/website/docs/r/cloud_run_domain_mapping.html.markdown b/website/docs/r/cloud_run_domain_mapping.html.markdown index f1e433cc18..80a7ec934b 100644 --- a/website/docs/r/cloud_run_domain_mapping.html.markdown +++ b/website/docs/r/cloud_run_domain_mapping.html.markdown @@ -27,7 +27,7 @@ Resource to hold the state and status of a user's domain mapping. To get more information about DomainMapping, see: -* [API documentation](https://cloud.google.com/run/docs/reference/rest/v1alpha1/projects.locations.domainmappings) +* [API documentation](https://cloud.google.com/run/docs/reference/rest/v1/projects.locations.domainmappings) * How-to Guides * [Official Documentation](https://cloud.google.com/run/docs/mapping-custom-domains) diff --git a/website/docs/r/cloud_run_service.html.markdown b/website/docs/r/cloud_run_service.html.markdown index 11c82e2df4..a4d6da8496 100644 --- a/website/docs/r/cloud_run_service.html.markdown +++ b/website/docs/r/cloud_run_service.html.markdown @@ -180,6 +180,12 @@ resource "google_cloud_run_service" "default" { } } + metadata { + annotations = { + generated-by = "magic-modules" + } + } + traffic { percent = 100 latest_revision = true