Skip to content

Commit df2e463

Browse files
Allow empty rollback block. (#13758) (#22501)
[upstream:85c6a040b70cd04c7469028dc135c83276b443ea] Signed-off-by: Modular Magician <[email protected]>
1 parent b45ba67 commit df2e463

File tree

5 files changed

+94
-11
lines changed

5 files changed

+94
-11
lines changed

.changelog/13758.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
clouddeploy: allowed sending empty block for `rollback` field in `google_clouddeploy_automation` resource.
3+
```

google/services/clouddeploy/resource_clouddeploy_automation.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ func ResourceClouddeployAutomation() *schema.Resource {
110110
},
111111
},
112112
},
113+
ExactlyOneOf: []string{},
113114
},
114115
"promote_release_rule": {
115116
Type: schema.TypeList,
@@ -140,6 +141,7 @@ func ResourceClouddeployAutomation() *schema.Resource {
140141
},
141142
},
142143
},
144+
ExactlyOneOf: []string{},
143145
},
144146
"repair_rollout_rule": {
145147
Type: schema.TypeList,
@@ -200,6 +202,7 @@ func ResourceClouddeployAutomation() *schema.Resource {
200202
},
201203
},
202204
},
205+
ExactlyOneOf: []string{},
203206
},
204207
"rollback": {
205208
Type: schema.TypeList,
@@ -220,12 +223,14 @@ func ResourceClouddeployAutomation() *schema.Resource {
220223
},
221224
},
222225
},
226+
ExactlyOneOf: []string{},
223227
},
224228
},
225229
},
226230
},
227231
},
228232
},
233+
ExactlyOneOf: []string{},
229234
},
230235
"timed_promote_release_rule": {
231236
Type: schema.TypeList,
@@ -263,6 +268,7 @@ func ResourceClouddeployAutomation() *schema.Resource {
263268
},
264269
},
265270
},
271+
ExactlyOneOf: []string{},
266272
},
267273
},
268274
},
@@ -1057,9 +1063,6 @@ func flattenClouddeployAutomationRulesRepairRolloutRuleRepairPhasesRollback(v in
10571063
return nil
10581064
}
10591065
original := v.(map[string]interface{})
1060-
if len(original) == 0 {
1061-
return nil
1062-
}
10631066
transformed := make(map[string]interface{})
10641067
transformed["destination_phase"] =
10651068
flattenClouddeployAutomationRulesRepairRolloutRuleRepairPhasesRollbackDestinationPhase(original["destinationPhase"], d, config)
@@ -1430,7 +1433,7 @@ func expandClouddeployAutomationRulesRepairRolloutRuleRepairPhases(v interface{}
14301433
transformedRollback, err := expandClouddeployAutomationRulesRepairRolloutRuleRepairPhasesRollback(original["rollback"], d, config)
14311434
if err != nil {
14321435
return nil, err
1433-
} else if val := reflect.ValueOf(transformedRollback); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1436+
} else {
14341437
transformed["rollback"] = transformedRollback
14351438
}
14361439

@@ -1486,9 +1489,14 @@ func expandClouddeployAutomationRulesRepairRolloutRuleRepairPhasesRetryBackoffMo
14861489

14871490
func expandClouddeployAutomationRulesRepairRolloutRuleRepairPhasesRollback(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
14881491
l := v.([]interface{})
1489-
if len(l) == 0 || l[0] == nil {
1492+
if len(l) == 0 {
14901493
return nil, nil
14911494
}
1495+
1496+
if l[0] == nil {
1497+
transformed := make(map[string]interface{})
1498+
return transformed, nil
1499+
}
14921500
raw := l[0]
14931501
original := raw.(map[string]interface{})
14941502
transformed := make(map[string]interface{})

google/services/clouddeploy/resource_clouddeploy_automation_generated_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,36 @@ resource "google_clouddeploy_automation" "b-automation" {
7070
id = "*"
7171
}
7272
}
73-
suspended = false
7473
rules {
7574
promote_release_rule {
7675
id = "promote-release"
7776
}
7877
}
78+
rules {
79+
advance_rollout_rule {
80+
id = "advance-rollout"
81+
}
82+
}
83+
rules {
84+
repair_rollout_rule {
85+
id = "repair-rollout"
86+
repair_phases {
87+
retry {
88+
attempts = "1"
89+
}
90+
}
91+
repair_phases {
92+
rollback {}
93+
}
94+
}
95+
}
96+
rules {
97+
timed_promote_release_rule {
98+
id = "timed-promote-release"
99+
schedule = "0 9 * * 1"
100+
time_zone = "America/New_York"
101+
}
102+
}
79103
}
80104
81105
resource "google_clouddeploy_delivery_pipeline" "pipeline" {

google/services/clouddeploy/resource_clouddeploy_automation_test.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,36 @@ resource "google_clouddeploy_automation" "automation" {
5858
id = "*"
5959
labels = {}
6060
}
61+
}
62+
rules {
63+
promote_release_rule {
64+
id = "promote-release"
65+
}
6166
}
6267
rules {
63-
advance_rollout_rule {
64-
id = "advance-rollout"
65-
source_phases = ["deploy"]
66-
wait = "200s"
68+
advance_rollout_rule {
69+
id = "advance-rollout"
70+
}
6771
}
72+
rules {
73+
repair_rollout_rule {
74+
id = "repair-rollout"
75+
repair_phases {
76+
retry {
77+
attempts = "1"
78+
}
79+
}
80+
repair_phases {
81+
rollback {}
82+
}
83+
}
84+
}
85+
rules {
86+
timed_promote_release_rule {
87+
id = "timed-promote-release"
88+
schedule = "0 9 * * 1"
89+
time_zone = "America/New_York"
90+
}
6891
}
6992
}
7093
@@ -137,6 +160,7 @@ resource "google_clouddeploy_automation" "automation" {
137160
repair_phases {
138161
rollback {
139162
destination_phase = "stable"
163+
disable_rollback_if_rollout_pending = true
140164
}
141165
}
142166
}

website/docs/r/clouddeploy_automation.html.markdown

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,36 @@ resource "google_clouddeploy_automation" "b-automation" {
4545
id = "*"
4646
}
4747
}
48-
suspended = false
4948
rules {
5049
promote_release_rule {
5150
id = "promote-release"
5251
}
5352
}
53+
rules {
54+
advance_rollout_rule {
55+
id = "advance-rollout"
56+
}
57+
}
58+
rules {
59+
repair_rollout_rule {
60+
id = "repair-rollout"
61+
repair_phases {
62+
retry {
63+
attempts = "1"
64+
}
65+
}
66+
repair_phases {
67+
rollback {}
68+
}
69+
}
70+
}
71+
rules {
72+
timed_promote_release_rule {
73+
id = "timed-promote-release"
74+
schedule = "0 9 * * 1"
75+
time_zone = "America/New_York"
76+
}
77+
}
5478
}
5579
5680
resource "google_clouddeploy_delivery_pipeline" "pipeline" {

0 commit comments

Comments
 (0)