Skip to content

Commit

Permalink
Merge pull request #37815 from nikhil-goenka/f/aws_customer_gateway
Browse files Browse the repository at this point in the history
bgp_asn_extended
  • Loading branch information
johnsonaj authored Jun 6, 2024
2 parents e358873 + edfda88 commit efa6f2f
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .changelog/37815.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_customer_gateway: Add `bgp_asn_extended` argument
```

```release-note:enhancement
data-source/aws_customer_gateway: Add `bgp_asn_extended` argument
```
27 changes: 23 additions & 4 deletions internal/service/ec2/vpnsite_customer_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,18 @@ func resourceCustomerGateway() *schema.Resource {
Computed: true,
},
"bgp_asn": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: verify.Valid4ByteASN,
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: verify.Valid4ByteASN,
ConflictsWith: []string{"bgp_asn_extended"},
},
"bgp_asn_extended": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: verify.Valid4ByteASN,
ConflictsWith: []string{"bgp_asn"},
},
names.AttrCertificateARN: {
Type: schema.TypeString,
Expand Down Expand Up @@ -102,6 +110,16 @@ func resourceCustomerGatewayCreate(ctx context.Context, d *schema.ResourceData,
input.BgpAsn = aws.Int32(int32(v))
}

if v, ok := d.GetOk("bgp_asn_extended"); ok {
v, err := strconv.ParseInt(v.(string), 10, 64)

if err != nil {
return sdkdiag.AppendFromErr(diags, err)
}

input.BgpAsnExtended = aws.Int64(v)
}

if v, ok := d.GetOk(names.AttrCertificateARN); ok {
input.CertificateArn = aws.String(v.(string))
}
Expand Down Expand Up @@ -154,6 +172,7 @@ func resourceCustomerGatewayRead(ctx context.Context, d *schema.ResourceData, me
}.String()
d.Set(names.AttrARN, arn)
d.Set("bgp_asn", customerGateway.BgpAsn)
d.Set("bgp_asn_extended", customerGateway.BgpAsnExtended)
d.Set(names.AttrCertificateARN, customerGateway.CertificateArn)
d.Set(names.AttrDeviceName, customerGateway.DeviceName)
d.Set(names.AttrIPAddress, customerGateway.IpAddress)
Expand Down
15 changes: 15 additions & 0 deletions internal/service/ec2/vpnsite_customer_gateway_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ func dataSourceCustomerGateway() *schema.Resource {
Type: schema.TypeInt,
Computed: true,
},
"bgp_asn_extended": {
Type: schema.TypeInt,
Computed: true,
},
names.AttrCertificateARN: {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -108,6 +112,17 @@ func dataSourceCustomerGatewayRead(ctx context.Context, d *schema.ResourceData,
} else {
d.Set("bgp_asn", nil)
}
if v := aws.ToString(cgw.BgpAsnExtended); v != "" {
v, err := strconv.ParseInt(v, 0, 0)

if err != nil {
return sdkdiag.AppendFromErr(diags, err)
}

d.Set("bgp_asn_extended", v)
} else {
d.Set("bgp_asn_extended", nil)
}
d.Set(names.AttrCertificateARN, cgw.CertificateArn)
d.Set(names.AttrDeviceName, cgw.DeviceName)
d.Set(names.AttrIPAddress, cgw.IpAddress)
Expand Down
44 changes: 44 additions & 0 deletions internal/service/ec2/vpnsite_customer_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,40 @@ func TestAccSiteVPNCustomerGateway_basic(t *testing.T) {
})
}

func TestAccSiteVPNCustomerGateway_bgpASNExtended(t *testing.T) {
ctx := acctest.Context(t)
var gateway awstypes.CustomerGateway
rBgpAsnExtended := sdkacctest.RandIntRange(2147483648, 4294967295)
resourceName := "aws_customer_gateway.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckCustomerGatewayDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccSiteVPNCustomerGatewayConfig_bgpASNExtended(rBgpAsnExtended),
Check: resource.ComposeTestCheckFunc(
testAccCheckCustomerGatewayExists(ctx, resourceName, &gateway),
acctest.MatchResourceAttrRegionalARN(resourceName, names.AttrARN, "ec2", regexache.MustCompile(`customer-gateway/cgw-.+`)),
resource.TestCheckResourceAttr(resourceName, "bgp_asn_extended", strconv.Itoa(rBgpAsnExtended)),
resource.TestCheckResourceAttr(resourceName, names.AttrCertificateARN, ""),
resource.TestCheckResourceAttr(resourceName, names.AttrDeviceName, ""),
resource.TestCheckResourceAttr(resourceName, names.AttrIPAddress, "172.0.0.1"),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, acctest.Ct0),
resource.TestCheckResourceAttr(resourceName, names.AttrType, "ipsec.1"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccSiteVPNCustomerGateway_disappears(t *testing.T) {
ctx := acctest.Context(t)
var gateway awstypes.CustomerGateway
Expand Down Expand Up @@ -298,6 +332,16 @@ resource "aws_customer_gateway" "test" {
`, rBgpAsn)
}

func testAccSiteVPNCustomerGatewayConfig_bgpASNExtended(rBgpAsnExtended int) string {
return fmt.Sprintf(`
resource "aws_customer_gateway" "test" {
bgp_asn_extended = %[1]d
ip_address = "172.0.0.1"
type = "ipsec.1"
}
`, rBgpAsnExtended)
}

func testAccSiteVPNCustomerGatewayConfig_tags1(rBgpAsn int, tagKey1, tagValue1 string) string {
return fmt.Sprintf(`
resource "aws_customer_gateway" "test" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/customer_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ This data source exports the following attributes in addition to the arguments a

* `arn` - ARN of the customer gateway.
* `bgp_asn` - Gateway's Border Gateway Protocol (BGP) Autonomous System Number (ASN).
* `bgp_asn_extended` - Gateway's Border Gateway Protocol (BGP) Autonomous System Number (ASN).
* `certificate_arn` - ARN for the customer gateway certificate.
* `device_name` - Name for the customer gateway device.
* `ip_address` - IP address of the gateway's Internet-routable external interface.
Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/customer_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ resource "aws_customer_gateway" "main" {

This resource supports the following arguments:

* `bgp_asn` - (Required) The gateway's Border Gateway Protocol (BGP) Autonomous System Number (ASN).
* `bgp_asn` - (Optional, Forces new resource) The gateway's Border Gateway Protocol (BGP) Autonomous System Number (ASN). Valid values are from `1` to `2147483647`. Conflicts with `bgp_asn_extended`.
* `bgp_asn_extended` - (Optional, Forces new resource) The gateway's Border Gateway Protocol (BGP) Autonomous System Number (ASN). Valid values are from `2147483648` to `4294967295` Conflicts with `bgp_asn`.
* `certificate_arn` - (Optional) The Amazon Resource Name (ARN) for the customer gateway certificate.
* `device_name` - (Optional) A name for the customer gateway device.
* `ip_address` - (Optional) The IPv4 address for the customer gateway device's outside interface.
Expand Down

0 comments on commit efa6f2f

Please sign in to comment.