Skip to content

Commit e6c742a

Browse files
Add default_from_apis: true to service.spec.template.metadata.labels in cloudrun resource (#8435) (#5953)
Signed-off-by: Modular Magician <[email protected]>
1 parent d2c4280 commit e6c742a

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

.changelog/8435.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
cloudrun: fixed the bug where default system labels set in `service.spec.template.metadata.labels` were treated as a diff.
3+
```

google-beta/services/cloudrun/resource_cloud_run_service.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,27 @@ func cloudrunLabelDiffSuppress(k, old, new string, d *schema.ResourceData) bool
100100
return false
101101
}
102102

103+
var cloudRunGoogleProvidedTemplateLabels = []string{
104+
"run.googleapis.com/startupProbeType",
105+
}
106+
107+
func cloudrunTemplateLabelDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
108+
// Suppress diffs for the labels provided by Google
109+
for _, label := range cloudRunGoogleProvidedTemplateLabels {
110+
if strings.Contains(k, label) && new == "" {
111+
return true
112+
}
113+
}
114+
115+
// Let diff be determined by labels (above)
116+
if strings.Contains(k, "labels.%") {
117+
return true
118+
}
119+
120+
// For other keys, don't suppress diff.
121+
return false
122+
}
123+
103124
func ResourceCloudRunService() *schema.Resource {
104125
return &schema.Resource{
105126
Create: resourceCloudRunServiceCreate,
@@ -817,8 +838,10 @@ keys to configure features on a Revision template:
817838
Elem: &schema.Schema{Type: schema.TypeString},
818839
},
819840
"labels": {
820-
Type: schema.TypeMap,
821-
Optional: true,
841+
Type: schema.TypeMap,
842+
Computed: true,
843+
Optional: true,
844+
DiffSuppressFunc: cloudrunTemplateLabelDiffSuppress,
822845
Description: `Map of string keys and values that can be used to organize and categorize
823846
(scope and select) objects.`,
824847
Elem: &schema.Schema{Type: schema.TypeString},

0 commit comments

Comments
 (0)