diff --git a/aws/data_source_aws_vpn_gateway.go b/aws/data_source_aws_vpn_gateway.go index bffbe01305b..2d0fa3277ac 100644 --- a/aws/data_source_aws_vpn_gateway.go +++ b/aws/data_source_aws_vpn_gateway.go @@ -36,7 +36,7 @@ func dataSourceAwsVpnGateway() *schema.Resource { Computed: true, }, "amazon_side_asn": { - Type: schema.TypeFloat, + Type: schema.TypeString, Optional: true, Computed: true, }, @@ -64,7 +64,7 @@ func dataSourceAwsVpnGatewayRead(d *schema.ResourceData, meta interface{}) error if asn, ok := d.GetOk("amazon_side_asn"); ok { req.Filters = append(req.Filters, buildEC2AttributeFilterList( map[string]string{ - "amazon-side-asn": strconv.FormatInt(int64(asn.(float64)), 10), + "amazon-side-asn": asn.(string), }, )...) } @@ -104,7 +104,7 @@ func dataSourceAwsVpnGatewayRead(d *schema.ResourceData, meta interface{}) error d.SetId(aws.StringValue(vgw.VpnGatewayId)) d.Set("state", vgw.State) d.Set("availability_zone", vgw.AvailabilityZone) - d.Set("amazon_side_asn", float64(aws.Int64Value(vgw.AmazonSideAsn))) + d.Set("amazon_side_asn", strconv.FormatInt(aws.Int64Value(vgw.AmazonSideAsn), 10)) d.Set("tags", tagsToMap(vgw.Tags)) for _, attachment := range vgw.VpcAttachments { diff --git a/aws/data_source_aws_vpn_gateway_test.go b/aws/data_source_aws_vpn_gateway_test.go index 6c8e0b672cf..084060675e4 100644 --- a/aws/data_source_aws_vpn_gateway_test.go +++ b/aws/data_source_aws_vpn_gateway_test.go @@ -31,7 +31,7 @@ func TestAccDataSourceAwsVpnGateway_unattached(t *testing.T) { resource.TestCheckResourceAttrSet("data.aws_vpn_gateway.test_by_id", "state"), resource.TestCheckResourceAttr("data.aws_vpn_gateway.test_by_tags", "tags.%", "3"), resource.TestCheckNoResourceAttr("data.aws_vpn_gateway.test_by_id", "attached_vpc_id"), - resource.TestCheckResourceAttr("data.aws_vpn_gateway.test_by_amazon_side_asn", "amazon_side_asn", "4.294967293E+09"), + resource.TestCheckResourceAttr("data.aws_vpn_gateway.test_by_amazon_side_asn", "amazon_side_asn", "4294967293"), ), }, }, diff --git a/aws/resource_aws_vpn_gateway.go b/aws/resource_aws_vpn_gateway.go index 2e95b5a17a7..57ed8a58605 100644 --- a/aws/resource_aws_vpn_gateway.go +++ b/aws/resource_aws_vpn_gateway.go @@ -3,6 +3,7 @@ package aws import ( "fmt" "log" + "strconv" "time" "github.com/aws/aws-sdk-go/aws" @@ -30,7 +31,7 @@ func resourceAwsVpnGateway() *schema.Resource { }, "amazon_side_asn": { - Type: schema.TypeFloat, + Type: schema.TypeString, Optional: true, ForceNew: true, Computed: true, @@ -56,7 +57,11 @@ func resourceAwsVpnGatewayCreate(d *schema.ResourceData, meta interface{}) error Type: aws.String("ipsec.1"), } if asn, ok := d.GetOk("amazon_side_asn"); ok { - createOpts.AmazonSideAsn = aws.Int64(int64(asn.(float64))) + i, err := strconv.ParseInt(asn.(string), 10, 64) + if err != nil { + return err + } + createOpts.AmazonSideAsn = aws.Int64(i) } // Create the VPN gateway @@ -109,7 +114,7 @@ func resourceAwsVpnGatewayRead(d *schema.ResourceData, meta interface{}) error { if vpnGateway.AvailabilityZone != nil && *vpnGateway.AvailabilityZone != "" { d.Set("availability_zone", vpnGateway.AvailabilityZone) } - d.Set("amazon_side_asn", float64(aws.Int64Value(vpnGateway.AmazonSideAsn))) + d.Set("amazon_side_asn", strconv.FormatInt(aws.Int64Value(vpnGateway.AmazonSideAsn), 10)) d.Set("tags", tagsToMap(vpnGateway.Tags)) return nil diff --git a/aws/resource_aws_vpn_gateway_test.go b/aws/resource_aws_vpn_gateway_test.go index 66e09d86aa9..481f76966be 100644 --- a/aws/resource_aws_vpn_gateway_test.go +++ b/aws/resource_aws_vpn_gateway_test.go @@ -140,7 +140,7 @@ func TestAccAWSVpnGateway_withAmazonSideAsnSetToState(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckVpnGatewayExists("aws_vpn_gateway.foo", &v), resource.TestCheckResourceAttr( - "aws_vpn_gateway.foo", "amazon_side_asn", "4.294967294E+09"), + "aws_vpn_gateway.foo", "amazon_side_asn", "4294967294"), ), }, }, diff --git a/aws/validators.go b/aws/validators.go index d4d4d685df8..990f90b36a8 100644 --- a/aws/validators.go +++ b/aws/validators.go @@ -6,6 +6,7 @@ import ( "net" "net/url" "regexp" + "strconv" "strings" "time" @@ -2256,10 +2257,14 @@ func validateStringIn(validValues ...string) schema.SchemaValidateFunc { } func validateAmazonSideAsn(v interface{}, k string) (ws []string, errors []error) { - value := v.(float64) + value := v.(string) // http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateVpnGateway.html - asn := int64(value) + 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)) diff --git a/aws/validators_test.go b/aws/validators_test.go index 05b8fffcf80..80e76312a61 100644 --- a/aws/validators_test.go +++ b/aws/validators_test.go @@ -3070,15 +3070,15 @@ func TestValidateGuardDutyThreatIntelSetFormat(t *testing.T) { } func TestValidateAmazonSideAsn(t *testing.T) { - validAsns := []float64{ - 64512, - 64513, - 65533, - 65534, - 4200000000, - 4200000001, - 4294967293, - 4294967294, + validAsns := []string{ + "64512", + "64513", + "65533", + "65534", + "4200000000", + "4200000001", + "4294967293", + "4294967294", } for _, v := range validAsns { _, errors := validateAmazonSideAsn(v, "amazon_side_asn") @@ -3087,8 +3087,10 @@ func TestValidateAmazonSideAsn(t *testing.T) { } } - invalidAsns := []float64{ - 1, + invalidAsns := []string{ + "1", + "ABCDEFG", + "", } for _, v := range invalidAsns { _, errors := validateAmazonSideAsn(v, "amazon_side_asn")