Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Use 'TypeFloat' (golang float64) instead of 'TypeString' for …
Browse files Browse the repository at this point in the history
…Amazon side ASN."

This reverts commit 1c7e0aa0c977e9b7edb2b348fd356b590e1d976c.
Kit Ewbank authored and radeksimko committed Feb 8, 2018
1 parent 94a33dd commit 6842933
Showing 6 changed files with 33 additions and 21 deletions.
6 changes: 3 additions & 3 deletions aws/data_source_aws_vpn_gateway.go
Original file line number Diff line number Diff line change
@@ -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 {
2 changes: 1 addition & 1 deletion aws/data_source_aws_vpn_gateway_test.go
Original file line number Diff line number Diff line change
@@ -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"),
),
},
},
11 changes: 8 additions & 3 deletions aws/resource_aws_vpn_gateway.go
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion aws/resource_aws_vpn_gateway_test.go
Original file line number Diff line number Diff line change
@@ -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"),
),
},
},
9 changes: 7 additions & 2 deletions aws/validators.go
Original file line number Diff line number Diff line change
@@ -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))
24 changes: 13 additions & 11 deletions aws/validators_test.go
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 6842933

Please sign in to comment.