Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/aws_dx_gateway: Use a single Amazon-side ASN validator #6253

Merged
merged 1 commit into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1743,7 +1743,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 @@ -1764,22 +1764,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 @@ -2544,7 +2544,7 @@ func TestValidateCognitoUserPoolId(t *testing.T) {
}
}

func TestValidateVpnGatewayAmazonSideAsn(t *testing.T) {
func TestValidateAmazonSideAsn(t *testing.T) {
validAsns := []string{
"7224",
"9059",
Expand All @@ -2560,7 +2560,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 @@ -2581,47 +2581,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