Skip to content

Commit 92401df

Browse files
Cloud Run Diff Supression (#4186) (#2679)
Signed-off-by: Modular Magician <[email protected]>
1 parent 46005b5 commit 92401df

File tree

5 files changed

+38
-4
lines changed

5 files changed

+38
-4
lines changed

.changelog/4186.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
run: patched `google_cloud_run_service` to suppress Google generated annotations
3+
```

google-beta/resource_cloud_run_service.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"log"
2121
"reflect"
2222
"strconv"
23+
"strings"
2324
"time"
2425

2526
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -34,6 +35,23 @@ func revisionNameCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v i
3435
return nil
3536
}
3637

38+
const cloudRunGoogleProvidedAnnotation = "serving.knative.dev"
39+
40+
func cloudrunAnnotationDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
41+
// Suppress diffs for the annotations provided by Google
42+
if strings.Contains(k, cloudRunGoogleProvidedAnnotation) && new == "" {
43+
return true
44+
}
45+
46+
// Let diff be determined by annotations (above)
47+
if strings.Contains(k, "annotations.%") {
48+
return true
49+
}
50+
51+
// For other keys, don't suppress diff.
52+
return false
53+
}
54+
3755
func resourceCloudRunService() *schema.Resource {
3856
return &schema.Resource{
3957
Create: resourceCloudRunServiceCreate,
@@ -485,9 +503,10 @@ and annotations.`,
485503
Elem: &schema.Resource{
486504
Schema: map[string]*schema.Schema{
487505
"annotations": {
488-
Type: schema.TypeMap,
489-
Computed: true,
490-
Optional: true,
506+
Type: schema.TypeMap,
507+
Computed: true,
508+
Optional: true,
509+
DiffSuppressFunc: cloudrunAnnotationDiffSuppress,
491510
Description: `Annotations is a key value map stored with a resource that
492511
may be set by external tools to store and retrieve arbitrary metadata. More
493512
info: http://kubernetes.io/docs/user-guide/annotations`,

google-beta/resource_cloud_run_service_generated_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@ resource "google_cloud_run_service" "default" {
254254
}
255255
}
256256
257+
metadata {
258+
annotations = {
259+
generated-by = "magic-modules"
260+
}
261+
}
262+
257263
traffic {
258264
percent = 100
259265
latest_revision = true

website/docs/r/cloud_run_domain_mapping.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Resource to hold the state and status of a user's domain mapping.
2727

2828
To get more information about DomainMapping, see:
2929

30-
* [API documentation](https://cloud.google.com/run/docs/reference/rest/v1alpha1/projects.locations.domainmappings)
30+
* [API documentation](https://cloud.google.com/run/docs/reference/rest/v1/projects.locations.domainmappings)
3131
* How-to Guides
3232
* [Official Documentation](https://cloud.google.com/run/docs/mapping-custom-domains)
3333

website/docs/r/cloud_run_service.html.markdown

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ resource "google_cloud_run_service" "default" {
180180
}
181181
}
182182
183+
metadata {
184+
annotations = {
185+
generated-by = "magic-modules"
186+
}
187+
}
188+
183189
traffic {
184190
percent = 100
185191
latest_revision = true

0 commit comments

Comments
 (0)