Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloud Run Diff Supression #2679

Merged
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: 3 additions & 0 deletions .changelog/4186.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
run: patched `google_cloud_run_service` to suppress Google generated annotations
```
25 changes: 22 additions & 3 deletions google-beta/resource_cloud_run_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"log"
"reflect"
"strconv"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand All @@ -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,
Expand Down Expand Up @@ -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`,
Expand Down
6 changes: 6 additions & 0 deletions google-beta/resource_cloud_run_service_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ resource "google_cloud_run_service" "default" {
}
}

metadata {
annotations = {
generated-by = "magic-modules"
}
}

traffic {
percent = 100
latest_revision = true
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/cloud_run_domain_mapping.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions website/docs/r/cloud_run_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ resource "google_cloud_run_service" "default" {
}
}

metadata {
annotations = {
generated-by = "magic-modules"
}
}

traffic {
percent = 100
latest_revision = true
Expand Down