-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validation to google_project_iam_custom_role.id (#662)
Signed-off-by: Modular Magician <[email protected]>
- Loading branch information
1 parent
cd4d651
commit e261332
Showing
3 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,9 @@ const ( | |
// Format of default Compute service accounts created by Google | ||
// ${PROJECT_ID}[email protected] where PROJECT_ID is an int64 (max 20 digits) | ||
ComputeServiceAccountNameRegex = "[0-9]{1,20}[email protected]" | ||
|
||
// https://cloud.google.com/iam/docs/understanding-custom-roles#naming_the_role | ||
IAMCustomRoleIDRegex = "^[a-zA-Z0-9_\\.\\-]{1,30}$" | ||
) | ||
|
||
var ( | ||
|
@@ -155,6 +158,15 @@ func validateCloudIoTID(v interface{}, k string) (warnings []string, errors []er | |
return | ||
} | ||
|
||
func validateIAMCustomRoleID(v interface{}, k string) (warnings []string, errors []error) { | ||
value := v.(string) | ||
if !regexp.MustCompile(IAMCustomRoleIDRegex).MatchString(value) { | ||
errors = append(errors, fmt.Errorf( | ||
"%q (%q) doesn't match regexp %q", k, value, IAMCustomRoleIDRegex)) | ||
} | ||
return | ||
} | ||
|
||
func orEmpty(f schema.SchemaValidateFunc) schema.SchemaValidateFunc { | ||
return func(i interface{}, k string) ([]string, []error) { | ||
v, ok := i.(string) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters