Skip to content

Commit d5fcdfa

Browse files
Allow sending start_time with default values. (#14779) (#23993)
[upstream:5297b9425edca63d1fec7c229ba207916f674549] Signed-off-by: Modular Magician <[email protected]>
1 parent 2c1a9d7 commit d5fcdfa

File tree

5 files changed

+83
-94
lines changed

5 files changed

+83
-94
lines changed

.changelog/14779.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 `start_time` with default values in `weekly_windows` in `google_clouddeploy_deploy_policy` resource. `start_time 00:00` means the policy will start at midnight.
3+
```

google/services/clouddeploy/resource_clouddeploy_deploy_policy.go

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,25 @@ func ResourceClouddeployDeployPolicy() *schema.Resource {
7474
"rules": {
7575
Type: schema.TypeList,
7676
Required: true,
77-
Description: `Required. Rules to apply. At least one rule must be present.`,
77+
Description: `Rules to apply. At least one rule must be present.`,
7878
Elem: &schema.Resource{
7979
Schema: map[string]*schema.Schema{
8080
"rollout_restriction": {
8181
Type: schema.TypeList,
8282
Optional: true,
83-
Description: `Optional. Rollout restrictions.`,
83+
Description: `Rollout restrictions.`,
8484
MaxItems: 1,
8585
Elem: &schema.Resource{
8686
Schema: map[string]*schema.Schema{
8787
"id": {
8888
Type: schema.TypeString,
8989
Required: true,
90-
Description: `Required. ID of the rule. This id must be unique in the 'DeployPolicy' resource to which this rule belongs. The format is 'a-z{0,62}'.`,
90+
Description: `ID of the rule. This id must be unique in the 'DeployPolicy' resource to which this rule belongs. The format is 'a-z{0,62}'.`,
9191
},
9292
"actions": {
9393
Type: schema.TypeList,
9494
Optional: true,
95-
Description: `Optional. Rollout actions to be restricted as part of the policy. If left empty, all actions will be restricted. Possible values: ["ADVANCE", "APPROVE", "CANCEL", "CREATE", "IGNORE_JOB", "RETRY_JOB", "ROLLBACK", "TERMINATE_JOBRUN"]`,
95+
Description: `Rollout actions to be restricted as part of the policy. If left empty, all actions will be restricted. Possible values: ["ADVANCE", "APPROVE", "CANCEL", "CREATE", "IGNORE_JOB", "RETRY_JOB", "ROLLBACK", "TERMINATE_JOBRUN"]`,
9696
Elem: &schema.Schema{
9797
Type: schema.TypeString,
9898
ValidateFunc: verify.ValidateEnum([]string{"ADVANCE", "APPROVE", "CANCEL", "CREATE", "IGNORE_JOB", "RETRY_JOB", "ROLLBACK", "TERMINATE_JOBRUN"}),
@@ -101,7 +101,7 @@ func ResourceClouddeployDeployPolicy() *schema.Resource {
101101
"invokers": {
102102
Type: schema.TypeList,
103103
Optional: true,
104-
Description: `Optional. What invoked the action. If left empty, all invoker types will be restricted. Possible values: ["USER", "DEPLOY_AUTOMATION"]`,
104+
Description: `What invoked the action. If left empty, all invoker types will be restricted. Possible values: ["USER", "DEPLOY_AUTOMATION"]`,
105105
Elem: &schema.Schema{
106106
Type: schema.TypeString,
107107
ValidateFunc: verify.ValidateEnum([]string{"USER", "DEPLOY_AUTOMATION"}),
@@ -110,25 +110,25 @@ func ResourceClouddeployDeployPolicy() *schema.Resource {
110110
"time_windows": {
111111
Type: schema.TypeList,
112112
Optional: true,
113-
Description: `Required. Time window within which actions are restricted.`,
113+
Description: `Time window within which actions are restricted.`,
114114
MaxItems: 1,
115115
Elem: &schema.Resource{
116116
Schema: map[string]*schema.Schema{
117117
"time_zone": {
118118
Type: schema.TypeString,
119119
Required: true,
120-
Description: `Required. The time zone in IANA format IANA Time Zone Database (e.g. America/New_York).`,
120+
Description: `The time zone in IANA format IANA Time Zone Database (e.g. America/New_York).`,
121121
},
122122
"one_time_windows": {
123123
Type: schema.TypeList,
124124
Optional: true,
125-
Description: `Optional. One-time windows within which actions are restricted.`,
125+
Description: `One-time windows within which actions are restricted.`,
126126
Elem: &schema.Resource{
127127
Schema: map[string]*schema.Schema{
128128
"end_date": {
129129
Type: schema.TypeList,
130130
Required: true,
131-
Description: `Required. End date.`,
131+
Description: `End date.`,
132132
MaxItems: 1,
133133
Elem: &schema.Resource{
134134
Schema: map[string]*schema.Schema{
@@ -153,7 +153,7 @@ func ResourceClouddeployDeployPolicy() *schema.Resource {
153153
"end_time": {
154154
Type: schema.TypeList,
155155
Required: true,
156-
Description: `Required. End time (exclusive). You may use 24:00 for the end of the day.`,
156+
Description: `End time (exclusive). You may use 24:00 for the end of the day.`,
157157
MaxItems: 1,
158158
Elem: &schema.Resource{
159159
Schema: map[string]*schema.Schema{
@@ -183,7 +183,7 @@ func ResourceClouddeployDeployPolicy() *schema.Resource {
183183
"start_date": {
184184
Type: schema.TypeList,
185185
Required: true,
186-
Description: `Required. Start date.`,
186+
Description: `Start date.`,
187187
MaxItems: 1,
188188
Elem: &schema.Resource{
189189
Schema: map[string]*schema.Schema{
@@ -208,7 +208,7 @@ func ResourceClouddeployDeployPolicy() *schema.Resource {
208208
"start_time": {
209209
Type: schema.TypeList,
210210
Required: true,
211-
Description: `Required. Start time (inclusive). Use 00:00 for the beginning of the day.`,
211+
Description: `Start time (inclusive). Use 00:00 for the beginning of the day.`,
212212
MaxItems: 1,
213213
Elem: &schema.Resource{
214214
Schema: map[string]*schema.Schema{
@@ -241,13 +241,13 @@ func ResourceClouddeployDeployPolicy() *schema.Resource {
241241
"weekly_windows": {
242242
Type: schema.TypeList,
243243
Optional: true,
244-
Description: `Optional. Recurring weekly windows within which actions are restricted.`,
244+
Description: `Recurring weekly windows within which actions are restricted.`,
245245
Elem: &schema.Resource{
246246
Schema: map[string]*schema.Schema{
247247
"days_of_week": {
248248
Type: schema.TypeList,
249249
Optional: true,
250-
Description: `Optional. Days of week. If left empty, all days of the week will be included. Possible values: ["MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"]`,
250+
Description: `Days of week. If left empty, all days of the week will be included. Possible values: ["MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"]`,
251251
Elem: &schema.Schema{
252252
Type: schema.TypeString,
253253
ValidateFunc: verify.ValidateEnum([]string{"MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"}),
@@ -256,7 +256,7 @@ func ResourceClouddeployDeployPolicy() *schema.Resource {
256256
"end_time": {
257257
Type: schema.TypeList,
258258
Optional: true,
259-
Description: `Optional. End time (exclusive). Use 24:00 to indicate midnight. If you specify endTime you must also specify startTime. If left empty, this will block for the entire day for the days specified in daysOfWeek.`,
259+
Description: `End time (exclusive). Use 24:00 to indicate midnight. If you specify endTime you must also specify startTime. If left empty, this will block for the entire day for the days specified in daysOfWeek.`,
260260
MaxItems: 1,
261261
Elem: &schema.Resource{
262262
Schema: map[string]*schema.Schema{
@@ -286,7 +286,7 @@ func ResourceClouddeployDeployPolicy() *schema.Resource {
286286
"start_time": {
287287
Type: schema.TypeList,
288288
Optional: true,
289-
Description: `Optional. Start time (inclusive). Use 00:00 for the beginning of the day. If you specify startTime you must also specify endTime. If left empty, this will block for the entire day for the days specified in daysOfWeek.`,
289+
Description: `Start time (inclusive). Use 00:00 for the beginning of the day. If you specify startTime you must also specify endTime. If left empty, this will block for the entire day for the days specified in daysOfWeek.`,
290290
MaxItems: 1,
291291
Elem: &schema.Resource{
292292
Schema: map[string]*schema.Schema{
@@ -328,7 +328,7 @@ func ResourceClouddeployDeployPolicy() *schema.Resource {
328328
"selectors": {
329329
Type: schema.TypeList,
330330
Required: true,
331-
Description: `Required. Selected resources to which the policy will be applied. At least one selector is required. If one selector matches the resource the policy applies. For example, if there are two selectors and the action being attempted matches one of them, the policy will apply to that action.`,
331+
Description: `Selected resources to which the policy will be applied. At least one selector is required. If one selector matches the resource the policy applies. For example, if there are two selectors and the action being attempted matches one of them, the policy will apply to that action.`,
332332
Elem: &schema.Resource{
333333
Schema: map[string]*schema.Schema{
334334
"delivery_pipeline": {
@@ -341,7 +341,7 @@ func ResourceClouddeployDeployPolicy() *schema.Resource {
341341
"id": {
342342
Type: schema.TypeString,
343343
Optional: true,
344-
Description: `Optional. ID of the DeliveryPipeline. The value of this field could be one of the following:
344+
Description: `ID of the DeliveryPipeline. The value of this field could be one of the following:
345345
- The last segment of a pipeline name
346346
- "*", all delivery pipelines in a location`,
347347
},
@@ -383,7 +383,7 @@ func ResourceClouddeployDeployPolicy() *schema.Resource {
383383
"annotations": {
384384
Type: schema.TypeMap,
385385
Optional: true,
386-
Description: `Optional. User annotations. These attributes can only be set and used by the user, and not by Cloud Deploy. Annotations must meet the following constraints: * Annotations are key/value pairs. * Valid annotation keys have two segments: an optional prefix and name, separated by a slash ('/'). * The name segment is required and must be 63 characters or less, beginning and ending with an alphanumeric character ('[a-z0-9A-Z]') with dashes ('-'), underscores ('_'), dots ('.'), and alphanumerics between. * The prefix is optional. If specified, the prefix must be a DNS subdomain: a series of DNS labels separated by dots('.'), not longer than 253 characters in total, followed by a slash ('/'). See https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/#syntax-and-character-set for more details.
386+
Description: `User annotations. These attributes can only be set and used by the user, and not by Cloud Deploy. Annotations must meet the following constraints: * Annotations are key/value pairs. * Valid annotation keys have two segments: an optional prefix and name, separated by a slash ('/'). * The name segment is required and must be 63 characters or less, beginning and ending with an alphanumeric character ('[a-z0-9A-Z]') with dashes ('-'), underscores ('_'), dots ('.'), and alphanumerics between. * The prefix is optional. If specified, the prefix must be a DNS subdomain: a series of DNS labels separated by dots('.'), not longer than 253 characters in total, followed by a slash ('/'). See https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/#syntax-and-character-set for more details.
387387
388388
**Note**: This field is non-authoritative, and will only manage the annotations present in your configuration.
389389
Please refer to the field 'effective_annotations' for all of the annotations present on the resource.`,
@@ -392,12 +392,12 @@ Please refer to the field 'effective_annotations' for all of the annotations pre
392392
"description": {
393393
Type: schema.TypeString,
394394
Optional: true,
395-
Description: `Optional. Description of the 'DeployPolicy'. Max length is 255 characters.`,
395+
Description: `Description of the 'DeployPolicy'. Max length is 255 characters.`,
396396
},
397397
"labels": {
398398
Type: schema.TypeMap,
399399
Optional: true,
400-
Description: `Optional. Labels are attributes that can be set and used by both the user and by Cloud Deploy. Labels must meet the following constraints: * Keys and values can contain only lowercase letters, numeric characters, underscores, and dashes. * All characters must use UTF-8 encoding, and international characters are allowed. * Keys must start with a lowercase letter or international character. * Each resource is limited to a maximum of 64 labels. Both keys and values are additionally constrained to be <= 63 characters.
400+
Description: `Labels are attributes that can be set and used by both the user and by Cloud Deploy. Labels must meet the following constraints: * Keys and values can contain only lowercase letters, numeric characters, underscores, and dashes. * All characters must use UTF-8 encoding, and international characters are allowed. * Keys must start with a lowercase letter or international character. * Each resource is limited to a maximum of 64 labels. Both keys and values are additionally constrained to be <= 63 characters.
401401
402402
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
403403
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
@@ -406,7 +406,7 @@ Please refer to the field 'effective_labels' for all of the labels present on th
406406
"suspended": {
407407
Type: schema.TypeBool,
408408
Optional: true,
409-
Description: `Optional. When suspended, the policy will not prevent actions from occurring, even if the action violates the policy.`,
409+
Description: `When suspended, the policy will not prevent actions from occurring, even if the action violates the policy.`,
410410
},
411411
"create_time": {
412412
Type: schema.TypeString,
@@ -428,7 +428,7 @@ Please refer to the field 'effective_labels' for all of the labels present on th
428428
"etag": {
429429
Type: schema.TypeString,
430430
Computed: true,
431-
Description: `Optional. The weak etag of the 'DeployPolicy' resource. This checksum is computed by the server based on the value of other fields, and may be sent on update and delete requests to ensure the client has an up-to-date value before proceeding.`,
431+
Description: `The weak etag of the 'DeployPolicy' resource. This checksum is computed by the server based on the value of other fields, and may be sent on update and delete requests to ensure the client has an up-to-date value before proceeding.`,
432432
},
433433
"terraform_labels": {
434434
Type: schema.TypeMap,
@@ -1199,9 +1199,6 @@ func flattenClouddeployDeployPolicyRulesRolloutRestrictionTimeWindowsOneTimeWind
11991199
return nil
12001200
}
12011201
original := v.(map[string]interface{})
1202-
if len(original) == 0 {
1203-
return nil
1204-
}
12051202
transformed := make(map[string]interface{})
12061203
transformed["hours"] =
12071204
flattenClouddeployDeployPolicyRulesRolloutRestrictionTimeWindowsOneTimeWindowsStartTimeHours(original["hours"], d, config)
@@ -1397,9 +1394,6 @@ func flattenClouddeployDeployPolicyRulesRolloutRestrictionTimeWindowsWeeklyWindo
13971394
return nil
13981395
}
13991396
original := v.(map[string]interface{})
1400-
if len(original) == 0 {
1401-
return nil
1402-
}
14031397
transformed := make(map[string]interface{})
14041398
transformed["hours"] =
14051399
flattenClouddeployDeployPolicyRulesRolloutRestrictionTimeWindowsWeeklyWindowsStartTimeHours(original["hours"], d, config)
@@ -1846,7 +1840,7 @@ func expandClouddeployDeployPolicyRulesRolloutRestrictionTimeWindowsOneTimeWindo
18461840
transformedStartTime, err := expandClouddeployDeployPolicyRulesRolloutRestrictionTimeWindowsOneTimeWindowsStartTime(original["start_time"], d, config)
18471841
if err != nil {
18481842
return nil, err
1849-
} else if val := reflect.ValueOf(transformedStartTime); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1843+
} else {
18501844
transformed["startTime"] = transformedStartTime
18511845
}
18521846

@@ -1954,9 +1948,14 @@ func expandClouddeployDeployPolicyRulesRolloutRestrictionTimeWindowsOneTimeWindo
19541948

19551949
func expandClouddeployDeployPolicyRulesRolloutRestrictionTimeWindowsOneTimeWindowsStartTime(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
19561950
l := v.([]interface{})
1957-
if len(l) == 0 || l[0] == nil {
1951+
if len(l) == 0 {
19581952
return nil, nil
19591953
}
1954+
1955+
if l[0] == nil {
1956+
transformed := make(map[string]interface{})
1957+
return transformed, nil
1958+
}
19601959
raw := l[0]
19611960
original := raw.(map[string]interface{})
19621961
transformed := make(map[string]interface{})
@@ -2084,7 +2083,7 @@ func expandClouddeployDeployPolicyRulesRolloutRestrictionTimeWindowsWeeklyWindow
20842083
transformedStartTime, err := expandClouddeployDeployPolicyRulesRolloutRestrictionTimeWindowsWeeklyWindowsStartTime(original["start_time"], d, config)
20852084
if err != nil {
20862085
return nil, err
2087-
} else if val := reflect.ValueOf(transformedStartTime); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2086+
} else {
20882087
transformed["startTime"] = transformedStartTime
20892088
}
20902089

@@ -2106,9 +2105,14 @@ func expandClouddeployDeployPolicyRulesRolloutRestrictionTimeWindowsWeeklyWindow
21062105

21072106
func expandClouddeployDeployPolicyRulesRolloutRestrictionTimeWindowsWeeklyWindowsStartTime(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
21082107
l := v.([]interface{})
2109-
if len(l) == 0 || l[0] == nil {
2108+
if len(l) == 0 {
21102109
return nil, nil
21112110
}
2111+
2112+
if l[0] == nil {
2113+
transformed := make(map[string]interface{})
2114+
return transformed, nil
2115+
}
21122116
raw := l[0]
21132117
original := raw.(map[string]interface{})
21142118
transformed := make(map[string]interface{})

google/services/clouddeploy/resource_clouddeploy_deploy_policy_generated_test.go

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ resource "google_clouddeploy_deploy_policy" "b-deploy-policy" {
7272
time_zone = "America/Los_Angeles"
7373
weekly_windows {
7474
start_time {
75-
hours = "12"
76-
minutes = "00"
75+
hours = 0
76+
minutes = 0
7777
}
7878
end_time {
79-
hours = "13"
79+
hours = "24"
8080
minutes = "00"
8181
}
8282
}
@@ -150,16 +150,12 @@ resource "google_clouddeploy_deploy_policy" "f-deploy-policy" {
150150
time_zone = "America/Los_Angeles"
151151
weekly_windows {
152152
start_time {
153-
hours = "12"
154-
minutes = "00"
155-
seconds = "00"
156-
nanos = "00"
153+
hours = 0
154+
minutes = 0
157155
}
158156
end_time {
159157
hours = "13"
160158
minutes = "00"
161-
seconds = "00"
162-
nanos = "00"
163159
}
164160
}
165161
}
@@ -176,8 +172,6 @@ resource "google_clouddeploy_deploy_policy" "f-deploy-policy" {
176172
start_time {
177173
hours = "13"
178174
minutes = "00"
179-
seconds = "00"
180-
nanos = "00"
181175
}
182176
end_time {
183177
hours = "14"
@@ -190,16 +184,12 @@ resource "google_clouddeploy_deploy_policy" "f-deploy-policy" {
190184
191185
one_time_windows {
192186
start_time {
193-
hours = "15"
187+
hours = "00"
194188
minutes = "00"
195-
seconds = "00"
196-
nanos = "00"
197189
}
198190
end_time {
199191
hours = "16"
200192
minutes = "00"
201-
seconds = "00"
202-
nanos = "00"
203193
}
204194
start_date {
205195
year = "2019"

0 commit comments

Comments
 (0)