Skip to content

Commit

Permalink
Add default_from_apis: true to `service.spec.template.metadata.labe…
Browse files Browse the repository at this point in the history
…ls` in `cloudrun` resource (#8435) (#15302)

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jul 26, 2023
1 parent 3961580 commit 990b634
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/8435.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
cloudrun: fixed the bug where default system labels set in `service.spec.template.metadata.labels` were treated as a diff.
```
27 changes: 25 additions & 2 deletions google/services/cloudrun/resource_cloud_run_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,27 @@ func cloudrunLabelDiffSuppress(k, old, new string, d *schema.ResourceData) bool
return false
}

var cloudRunGoogleProvidedTemplateLabels = []string{
"run.googleapis.com/startupProbeType",
}

func cloudrunTemplateLabelDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
// Suppress diffs for the labels provided by Google
for _, label := range cloudRunGoogleProvidedTemplateLabels {
if strings.Contains(k, label) && 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 @@ -797,8 +818,10 @@ keys to configure features on a Revision template:
Elem: &schema.Schema{Type: schema.TypeString},
},
"labels": {
Type: schema.TypeMap,
Optional: true,
Type: schema.TypeMap,
Computed: true,
Optional: true,
DiffSuppressFunc: cloudrunTemplateLabelDiffSuppress,
Description: `Map of string keys and values that can be used to organize and categorize
(scope and select) objects.`,
Elem: &schema.Schema{Type: schema.TypeString},
Expand Down

0 comments on commit 990b634

Please sign in to comment.