Skip to content

Commit

Permalink
Add validation for start_time to resource_policy (#5366)
Browse files Browse the repository at this point in the history
* Use more markdown for Bug

* Consistently use sentences for each bullet

* Rewrite bug reproduction block

* Allow domain mapping to succeed if DNS is pending

Signed-off-by: Modular Magician <magic-modules@google.com>

* Updated google_folder.html (#4149)

* Updated google_folder.html

The page in the first example shows that you should use organization_id with value of 1234567. In the Import example, it's not clear whether organization_id is user, or folder_id is used. API call behind this import command is only accepting folder_id (can be checked when setting TF_LOG to trace and viewing the API call)

* Update website/docs/r/google_folder.html.markdown

Co-Authored-By: Dana Hoffman <danahoffman@google.com>

Co-authored-by: Dana Hoffman <danahoffman@google.com>

* add google_kms_secret_ciphertext resource, deprecate datasource (#5314)

Signed-off-by: Modular Magician <magic-modules@google.com>

Co-authored-by: Dana Hoffman <danahoffman@google.com>

* Allow add/removing Bigtable clusters (#5318)

Signed-off-by: Modular Magician <magic-modules@google.com>

Co-authored-by: Riley Karson <rileykarson@google.com>

* Add bootstrapped test networks for service networking tests (#5316)

Signed-off-by: Modular Magician <magic-modules@google.com>

Co-authored-by: emily <emilyye@google.com>

* Update CHANGELOG.md

* fix docs for google_bigquery_default_service_account (#5329)

Signed-off-by: Modular Magician <magic-modules@google.com>

Co-authored-by: Martin Nowak <code@dawg.eu>

* Nil return for absent Bigtable resources (#5331)

Signed-off-by: Modular Magician <magic-modules@google.com>

Co-authored-by: Brian Hildebrandt <brian3.14159@gmail.com>

* add lifecycle_config to dataproc_cluster.cluster_config

Signed-off-by: Modular Magician <magic-modules@google.com>

* Add warnings about custom role format for IAM bindings (#5335)

Signed-off-by: Modular Magician <magic-modules@google.com>

Co-authored-by: emily <emilyye@google.com>

* Add mutex to peering create (#5338)

Signed-off-by: Modular Magician <magic-modules@google.com>

Co-authored-by: emily <emilyye@google.com>

* Handle aggregatedList case for generated sweepers

Signed-off-by: Modular Magician <magic-modules@google.com>

* Add default_if_empty for quic_override (#5351)

Signed-off-by: Modular Magician <magic-modules@google.com>

Co-authored-by: Riley Karson <rileykarson@google.com>

* Batch errors now indicate how to disable batching

Signed-off-by: Modular Magician <magic-modules@google.com>

* Add default_if_empty to google_compute_router_nat defaults (#5353)

Signed-off-by: Modular Magician <magic-modules@google.com>

Co-authored-by: Riley Karson <rileykarson@google.com>

* Allow for retries of single requests in a batch on failure (#5355)

Signed-off-by: Modular Magician <magic-modules@google.com>

Co-authored-by: emily <emilyye@google.com>

* Avoid panic in usage_export_bucket

Signed-off-by: Modular Magician <magic-modules@google.com>

* Add validation for start_time to resource_policy

Signed-off-by: Modular Magician <magic-modules@google.com>

* Add validation for start_time to resource_policy (#2940)

Merged PR #2940.

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
Co-authored-by: Chris Stephens <chrisst@google.com>
Co-authored-by: Petar Marinkovic <13387474+marinkovicpetar@users.noreply.github.com>
Co-authored-by: Dana Hoffman <danahoffman@google.com>
Co-authored-by: megan07 <mbang@hashicorp.com>
Co-authored-by: Riley Karson <rileykarson@google.com>
Co-authored-by: emily <emilyye@google.com>
Co-authored-by: Paddy <paddy@hashicorp.com>
Co-authored-by: Martin Nowak <code@dawg.eu>
Co-authored-by: Brian Hildebrandt <brian3.14159@gmail.com>
Co-authored-by: Cameron Thornton <camthornton@google.com>
  • Loading branch information
12 people authored Jan 9, 2020
1 parent a5d66db commit abd6c7d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .changelog/2940.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
`compute`: Added validation for `compute_resource_policy` to no longer allow invalid `start_time` values that weren't hourly.
```
19 changes: 11 additions & 8 deletions google/resource_compute_resource_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ which cannot be a dash.`,
Description: `The number of days between snapshots.`,
},
"start_time": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateHourlyOnly,
Description: `This must be in UTC format that resolves to one of
00:00, 04:00, 08:00, 12:00, 16:00, or 20:00. For example,
both 13:00-5 and 08:00 are valid.`,
Expand All @@ -118,12 +119,14 @@ both 13:00-5 and 08:00 are valid.`,
Description: `The number of hours between snapshots.`,
},
"start_time": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateHourlyOnly,
Description: `Time within the window to start the operations.
It must be in format "HH:MM",
where HH : [00-23] and MM : [00-00] GMT.`,
It must be in an hourly format "HH:MM",
where HH : [00-23] and MM : [00] GMT.
eg: 21:00`,
},
},
},
Expand Down
20 changes: 20 additions & 0 deletions google/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,23 @@ func StringNotInSlice(invalid []string, ignoreCase bool) schema.SchemaValidateFu
return
}
}

// Ensure that hourly timestamp strings "HH:MM" have the minutes zeroed out for hourly only inputs
func validateHourlyOnly(val interface{}, key string) (warns []string, errs []error) {
v := val.(string)
parts := strings.Split(v, ":")
if len(parts) != 2 {
errs = append(errs, fmt.Errorf("%q must be in the format HH:00, got: %s", key, v))
return
}
if parts[1] != "00" {
errs = append(errs, fmt.Errorf("%q does not allow minutes, it must be in the format HH:00, got: %s", key, v))
}
i, err := strconv.Atoi(parts[0])
if err != nil {
errs = append(errs, fmt.Errorf("%q cannot be parsed, it must be in the format HH:00, got: %s", key, v))
} else if i < 0 || i > 23 {
errs = append(errs, fmt.Errorf("%q does not specify a valid hour, it must be in the format HH:00 where HH : [00-23], got: %s", key, v))
}
return
}
5 changes: 3 additions & 2 deletions website/docs/r/compute_resource_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ The `hourly_schedule` block supports:
* `start_time` -
(Required)
Time within the window to start the operations.
It must be in format "HH:MM",
where HH : [00-23] and MM : [00-00] GMT.
It must be in an hourly format "HH:MM",
where HH : [00-23] and MM : [00] GMT.
eg: 21:00

The `daily_schedule` block supports:

Expand Down

0 comments on commit abd6c7d

Please sign in to comment.