Skip to content

Commit

Permalink
Merge pull request #6253 from ewbankkit/issue-6242
Browse files Browse the repository at this point in the history
r/aws_dx_gateway: Use a single Amazon-side ASN validator
  • Loading branch information
bflad authored Oct 30, 2018
2 parents a8674b4 + 41c5c4b commit 3e0a371
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 62 deletions.
2 changes: 1 addition & 1 deletion aws/resource_aws_dx_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func resourceAwsDxGateway() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateDxGatewayAmazonSideAsn,
ValidateFunc: validateAmazonSideAsn,
},
},

Expand Down
2 changes: 1 addition & 1 deletion aws/resource_aws_vpn_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func resourceAwsVpnGateway() *schema.Resource {
Optional: true,
ForceNew: true,
Computed: true,
ValidateFunc: validateVpnGatewayAmazonSideAsn,
ValidateFunc: validateAmazonSideAsn,
},

"vpc_id": {
Expand Down
18 changes: 1 addition & 17 deletions aws/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -1793,7 +1793,7 @@ func validateDynamoDbStreamSpec(d *schema.ResourceDiff) error {
return nil
}

func validateVpnGatewayAmazonSideAsn(v interface{}, k string) (ws []string, errors []error) {
func validateAmazonSideAsn(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)

// http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateVpnGateway.html
Expand All @@ -1814,22 +1814,6 @@ func validateVpnGatewayAmazonSideAsn(v interface{}, k string) (ws []string, erro
return
}

func validateDxGatewayAmazonSideAsn(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)

// https://docs.aws.amazon.com/directconnect/latest/APIReference/API_CreateDirectConnectGateway.html
asn, err := strconv.ParseInt(value, 10, 64)
if err != nil {
errors = append(errors, fmt.Errorf("%q (%q) must be a 64-bit integer", k, v))
return
}

if (asn < 64512) || (asn > 65534 && asn < 4200000000) || (asn > 4294967294) {
errors = append(errors, fmt.Errorf("%q (%q) must be in the range 64512 to 65534 or 4200000000 to 4294967294", k, v))
}
return
}

func validateIotThingTypeName(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if !regexp.MustCompile(`[a-zA-Z0-9:_-]+`).MatchString(value) {
Expand Down
46 changes: 3 additions & 43 deletions aws/validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2693,7 +2693,7 @@ func TestValidateCognitoUserPoolId(t *testing.T) {
}
}

func TestValidateVpnGatewayAmazonSideAsn(t *testing.T) {
func TestValidateAmazonSideAsn(t *testing.T) {
validAsns := []string{
"7224",
"9059",
Expand All @@ -2709,7 +2709,7 @@ func TestValidateVpnGatewayAmazonSideAsn(t *testing.T) {
"4294967294",
}
for _, v := range validAsns {
_, errors := validateVpnGatewayAmazonSideAsn(v, "amazon_side_asn")
_, errors := validateAmazonSideAsn(v, "amazon_side_asn")
if len(errors) != 0 {
t.Fatalf("%q should be a valid ASN: %q", v, errors)
}
Expand All @@ -2730,47 +2730,7 @@ func TestValidateVpnGatewayAmazonSideAsn(t *testing.T) {
"9999999999",
}
for _, v := range invalidAsns {
_, errors := validateVpnGatewayAmazonSideAsn(v, "amazon_side_asn")
if len(errors) == 0 {
t.Fatalf("%q should be an invalid ASN", v)
}
}
}

func TestValidateDxGatewayAmazonSideAsn(t *testing.T) {
validAsns := []string{
"64512",
"64513",
"65533",
"65534",
"4200000000",
"4200000001",
"4294967293",
"4294967294",
}
for _, v := range validAsns {
_, errors := validateDxGatewayAmazonSideAsn(v, "amazon_side_asn")
if len(errors) != 0 {
t.Fatalf("%q should be a valid ASN: %q", v, errors)
}
}

invalidAsns := []string{
"1",
"ABCDEFG",
"",
"7224",
"9059",
"10124",
"17493",
"64511",
"65535",
"4199999999",
"4294967295",
"9999999999",
}
for _, v := range invalidAsns {
_, errors := validateDxGatewayAmazonSideAsn(v, "amazon_side_asn")
_, errors := validateAmazonSideAsn(v, "amazon_side_asn")
if len(errors) == 0 {
t.Fatalf("%q should be an invalid ASN", v)
}
Expand Down

0 comments on commit 3e0a371

Please sign in to comment.