Skip to content

Commit

Permalink
Merge pull request #13291 from megubyte/v001-check/r-organizations-ac…
Browse files Browse the repository at this point in the history
…count

r/organizations_account: tech debt: replace custom validation funcs
  • Loading branch information
anGie44 authored May 13, 2020
2 parents 101e583 + 1cb3110 commit 1fb5324
Showing 1 changed file with 8 additions and 35 deletions.
43 changes: 8 additions & 35 deletions aws/resource_aws_organizations_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ func resourceAwsOrganizationsAccount() *schema.Resource {
ValidateFunc: validation.StringLenBetween(1, 50),
},
"email": {
ForceNew: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validateAwsOrganizationsAccountEmail,
ForceNew: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.All(
validation.StringLenBetween(6, 64),
validation.StringMatch(regexp.MustCompile(`^[^\s@]+@[^\s@]+\.[^\s@]+$`), "must be a valid email address"),
),
},
"iam_user_access_to_billing": {
ForceNew: true,
Expand All @@ -69,7 +72,7 @@ func resourceAwsOrganizationsAccount() *schema.Resource {
ForceNew: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateAwsOrganizationsAccountRoleName,
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^[\w+=,.@-]{1,64}$`), "must consist of uppercase letters, lowercase letters, digits with no spaces, and any of the following characters"),
},
"tags": tagsSchema(),
},
Expand Down Expand Up @@ -301,36 +304,6 @@ func resourceAwsOrganizationsAccountStateRefreshFunc(conn *organizations.Organiz
}
}

func validateAwsOrganizationsAccountEmail(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if !regexp.MustCompile(`^[^\s@]+@[^\s@]+\.[^\s@]+$`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"%q must be a valid email address", value))
}

if len(value) < 6 {
errors = append(errors, fmt.Errorf(
"%q cannot be less than 6 characters", value))
}

if len(value) > 64 {
errors = append(errors, fmt.Errorf(
"%q cannot be greater than 64 characters", value))
}

return
}

func validateAwsOrganizationsAccountRoleName(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if !regexp.MustCompile(`^[\w+=,.@-]{1,64}$`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"%q must consist of uppercase letters, lowercase letters, digits with no spaces, and any of the following characters: =,.@-", value))
}

return
}

func resourceAwsOrganizationsAccountGetParentId(conn *organizations.Organizations, childId string) (string, error) {
input := &organizations.ListParentsInput{
ChildId: aws.String(childId),
Expand Down

0 comments on commit 1fb5324

Please sign in to comment.