Skip to content

Commit

Permalink
Suppress Google labels from Cloud Run Service (#4528) (#3005)
Browse files Browse the repository at this point in the history
Co-authored-by: upodroid <[email protected]>
Co-authored-by: Cameron Thornton <[email protected]>
Signed-off-by: Modular Magician <[email protected]>

Co-authored-by: upodroid <[email protected]>
Co-authored-by: Cameron Thornton <[email protected]>
  • Loading branch information
3 people authored Feb 26, 2021
1 parent cc65fd0 commit 6f790e0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/4528.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
cloudrun: suppressed metadata.labels["cloud.googleapis.com/location"] value in `google_cloud_run_service`
```
26 changes: 22 additions & 4 deletions google-beta/resource_cloud_run_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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
Expand All @@ -53,6 +53,23 @@ func cloudrunAnnotationDiffSuppress(k, old, new string, d *schema.ResourceData)
return false
}

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
}

func resourceCloudRunService() *schema.Resource {
return &schema.Resource{
Create: resourceCloudRunServiceCreate,
Expand Down Expand Up @@ -522,9 +539,10 @@ or apply the lifecycle.ignore_changes rule to the metadata.0.annotations field.`
Elem: &schema.Schema{Type: schema.TypeString},
},
"labels": {
Type: schema.TypeMap,
Computed: true,
Optional: true,
Type: schema.TypeMap,
Computed: true,
Optional: true,
DiffSuppressFunc: cloudrunLabelDiffSuppress,
Description: `Map of string keys and values that can be used to organize and categorize
(scope and select) objects. May match selectors of replication controllers
and routes.
Expand Down
2 changes: 1 addition & 1 deletion google-beta/resource_dataflow_flex_template_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
compute "google.golang.org/api/compute/v1"
"google.golang.org/api/compute/v1"
)

func TestAccDataflowFlexTemplateJob_basic(t *testing.T) {
Expand Down

0 comments on commit 6f790e0

Please sign in to comment.