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

added appliance_mode_support argument/attribute #16159

Merged
merged 5 commits into from
Nov 12, 2020
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
5 changes: 5 additions & 0 deletions aws/data_source_aws_ec2_transit_gateway_vpc_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func dataSourceAwsEc2TransitGatewayVpcAttachment() *schema.Resource {
Read: dataSourceAwsEc2TransitGatewayVpcAttachmentRead,

Schema: map[string]*schema.Schema{
"appliance_mode_support": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs documentation in website/docs/d/ec2_transit_gateway_vpc_attachment.html.markdown 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot, completely forgot that! Have updated the doc

Type: schema.TypeString,
Computed: true,
},
"dns_support": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -90,6 +94,7 @@ func dataSourceAwsEc2TransitGatewayVpcAttachmentRead(d *schema.ResourceData, met
return fmt.Errorf("error reading EC2 Transit Gateway VPC Attachment (%s): missing options", d.Id())
}

d.Set("appliance_mode_support", transitGatewayVpcAttachment.Options.ApplianceModeSupport)
d.Set("dns_support", transitGatewayVpcAttachment.Options.DnsSupport)
d.Set("ipv6_support", transitGatewayVpcAttachment.Options.Ipv6Support)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestAccAWSEc2TransitGatewayVpcAttachmentDataSource_Filter(t *testing.T) {
{
Config: testAccAWSEc2TransitGatewayVpcAttachmentDataSourceConfigFilter(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(resourceName, "appliance_mode_support", dataSourceName, "appliance_mode_support"),
resource.TestCheckResourceAttrPair(resourceName, "dns_support", dataSourceName, "dns_support"),
resource.TestCheckResourceAttrPair(resourceName, "ipv6_support", dataSourceName, "ipv6_support"),
resource.TestCheckResourceAttrPair(resourceName, "subnet_ids.#", dataSourceName, "subnet_ids.#"),
Expand All @@ -43,6 +44,7 @@ func TestAccAWSEc2TransitGatewayVpcAttachmentDataSource_ID(t *testing.T) {
{
Config: testAccAWSEc2TransitGatewayVpcAttachmentDataSourceConfigID(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(resourceName, "appliance_mode_support", dataSourceName, "appliance_mode_support"),
resource.TestCheckResourceAttrPair(resourceName, "dns_support", dataSourceName, "dns_support"),
resource.TestCheckResourceAttrPair(resourceName, "ipv6_support", dataSourceName, "ipv6_support"),
resource.TestCheckResourceAttrPair(resourceName, "subnet_ids.#", dataSourceName, "subnet_ids.#"),
Expand Down
19 changes: 14 additions & 5 deletions aws/resource_aws_ec2_transit_gateway_vpc_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ func resourceAwsEc2TransitGatewayVpcAttachment() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"appliance_mode_support": {
Type: schema.TypeString,
Optional: true,
Default: ec2.ApplianceModeSupportValueDisable,
ValidateFunc: validation.StringInSlice(ec2.ApplianceModeSupportValue_Values(), false),
},
"dns_support": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -84,8 +90,9 @@ func resourceAwsEc2TransitGatewayVpcAttachmentCreate(d *schema.ResourceData, met

input := &ec2.CreateTransitGatewayVpcAttachmentInput{
Options: &ec2.CreateTransitGatewayVpcAttachmentRequestOptions{
DnsSupport: aws.String(d.Get("dns_support").(string)),
Ipv6Support: aws.String(d.Get("ipv6_support").(string)),
ApplianceModeSupport: aws.String(d.Get("appliance_mode_support").(string)),
DnsSupport: aws.String(d.Get("dns_support").(string)),
Ipv6Support: aws.String(d.Get("ipv6_support").(string)),
},
SubnetIds: expandStringSet(d.Get("subnet_ids").(*schema.Set)),
TransitGatewayId: aws.String(transitGatewayID),
Expand Down Expand Up @@ -188,6 +195,7 @@ func resourceAwsEc2TransitGatewayVpcAttachmentRead(d *schema.ResourceData, meta
return fmt.Errorf("error reading EC2 Transit Gateway VPC Attachment (%s): missing options", d.Id())
}

d.Set("appliance_mode_support", transitGatewayVpcAttachment.Options.ApplianceModeSupport)
d.Set("dns_support", transitGatewayVpcAttachment.Options.DnsSupport)
d.Set("ipv6_support", transitGatewayVpcAttachment.Options.Ipv6Support)

Expand All @@ -211,11 +219,12 @@ func resourceAwsEc2TransitGatewayVpcAttachmentRead(d *schema.ResourceData, meta
func resourceAwsEc2TransitGatewayVpcAttachmentUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn

if d.HasChanges("dns_support", "ipv6_support", "subnet_ids") {
if d.HasChanges("appliance_mode_support", "dns_support", "ipv6_support", "subnet_ids") {
input := &ec2.ModifyTransitGatewayVpcAttachmentInput{
Options: &ec2.ModifyTransitGatewayVpcAttachmentRequestOptions{
DnsSupport: aws.String(d.Get("dns_support").(string)),
Ipv6Support: aws.String(d.Get("ipv6_support").(string)),
ApplianceModeSupport: aws.String(d.Get("appliance_mode_support").(string)),
DnsSupport: aws.String(d.Get("dns_support").(string)),
Ipv6Support: aws.String(d.Get("ipv6_support").(string)),
},
TransitGatewayAttachmentId: aws.String(d.Id()),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ func resourceAwsEc2TransitGatewayVpcAttachmentAccepter() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"appliance_mode_support": {
Type: schema.TypeString,
Computed: true,
},
"dns_support": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -166,6 +170,7 @@ func resourceAwsEc2TransitGatewayVpcAttachmentAccepterRead(d *schema.ResourceDat
return fmt.Errorf("error reading EC2 Transit Gateway VPC Attachment (%s): missing options", d.Id())
}

d.Set("appliance_mode_support", transitGatewayVpcAttachment.Options.ApplianceModeSupport)
d.Set("dns_support", transitGatewayVpcAttachment.Options.DnsSupport)
d.Set("ipv6_support", transitGatewayVpcAttachment.Options.Ipv6Support)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func TestAccAWSEc2TransitGatewayVpcAttachmentAccepter_basic(t *testing.T) {
Config: testAccAWSEc2TransitGatewayVpcAttachmentAccepterConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEc2TransitGatewayVpcAttachmentExists(resourceName, &transitGatewayVpcAttachment),
resource.TestCheckResourceAttr(resourceName, "appliance_mode_support", ec2.ApplianceModeSupportValueDisable),
resource.TestCheckResourceAttr(resourceName, "dns_support", ec2.DnsSupportValueEnable),
resource.TestCheckResourceAttr(resourceName, "ipv6_support", ec2.Ipv6SupportValueDisable),
resource.TestCheckResourceAttr(resourceName, "subnet_ids.#", "1"),
Expand Down Expand Up @@ -78,6 +79,7 @@ func TestAccAWSEc2TransitGatewayVpcAttachmentAccepter_Tags(t *testing.T) {
Config: testAccAWSEc2TransitGatewayVpcAttachmentAccepterConfig_tags(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEc2TransitGatewayVpcAttachmentExists(resourceName, &transitGatewayVpcAttachment),
resource.TestCheckResourceAttr(resourceName, "appliance_mode_support", ec2.ApplianceModeSupportValueDisable),
resource.TestCheckResourceAttr(resourceName, "dns_support", ec2.DnsSupportValueEnable),
resource.TestCheckResourceAttr(resourceName, "ipv6_support", ec2.Ipv6SupportValueDisable),
resource.TestCheckResourceAttr(resourceName, "subnet_ids.#", "1"),
Expand All @@ -98,6 +100,7 @@ func TestAccAWSEc2TransitGatewayVpcAttachmentAccepter_Tags(t *testing.T) {
Config: testAccAWSEc2TransitGatewayVpcAttachmentAccepterConfig_tagsUpdated(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEc2TransitGatewayVpcAttachmentExists(resourceName, &transitGatewayVpcAttachment),
resource.TestCheckResourceAttr(resourceName, "appliance_mode_support", ec2.ApplianceModeSupportValueDisable),
resource.TestCheckResourceAttr(resourceName, "dns_support", ec2.DnsSupportValueEnable),
resource.TestCheckResourceAttr(resourceName, "ipv6_support", ec2.Ipv6SupportValueDisable),
resource.TestCheckResourceAttr(resourceName, "subnet_ids.#", "1"),
Expand Down
84 changes: 84 additions & 0 deletions aws/resource_aws_ec2_transit_gateway_vpc_attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,47 @@ func TestAccAWSEc2TransitGatewayVpcAttachment_disappears(t *testing.T) {
})
}

func TestAccAWSEc2TransitGatewayVpcAttachment_ApplianceModeSupport(t *testing.T) {
var transitGatewayVpcAttachment1, transitGatewayVpcAttachment2 ec2.TransitGatewayVpcAttachment
resourceName := "aws_ec2_transit_gateway_vpc_attachment.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSEc2TransitGateway(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEc2TransitGatewayVpcAttachmentDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSEc2TransitGatewayVpcAttachmentConfigApplianceModeSupport("false"),
ExpectError: regexp.MustCompile(`expected appliance_mode_support to be one of`),
},
{
Config: testAccAWSEc2TransitGatewayVpcAttachmentConfigApplianceModeSupport("true"),
ExpectError: regexp.MustCompile(`expected appliance_mode_support to be one of`),
},
{
Config: testAccAWSEc2TransitGatewayVpcAttachmentConfigApplianceModeSupport(ec2.ApplianceModeSupportValueDisable),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEc2TransitGatewayVpcAttachmentExists(resourceName, &transitGatewayVpcAttachment1),
resource.TestCheckResourceAttr(resourceName, "appliance_mode_support", ec2.ApplianceModeSupportValueDisable),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccAWSEc2TransitGatewayVpcAttachmentConfigApplianceModeSupport(ec2.ApplianceModeSupportValueEnable),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEc2TransitGatewayVpcAttachmentExists(resourceName, &transitGatewayVpcAttachment2),
testAccCheckAWSEc2TransitGatewayVpcAttachmentNotRecreated(&transitGatewayVpcAttachment1, &transitGatewayVpcAttachment2),
resource.TestCheckResourceAttr(resourceName, "appliance_mode_support", ec2.ApplianceModeSupportValueEnable),
),
},
},
})
}

func TestAccAWSEc2TransitGatewayVpcAttachment_DnsSupport(t *testing.T) {
var transitGatewayVpcAttachment1, transitGatewayVpcAttachment2 ec2.TransitGatewayVpcAttachment
resourceName := "aws_ec2_transit_gateway_vpc_attachment.test"
Expand Down Expand Up @@ -582,6 +623,49 @@ resource "aws_ec2_transit_gateway_vpc_attachment" "test" {
`
}

func testAccAWSEc2TransitGatewayVpcAttachmentConfigApplianceModeSupport(appModeSupport string) string {
return fmt.Sprintf(`
data "aws_availability_zones" "available" {
# IncorrectState: Transit Gateway is not available in availability zone us-west-2d
exclude_zone_ids = ["usw2-az4"]
state = "available"

filter {
name = "opt-in-status"
values = ["opt-in-not-required"]
}
}

resource "aws_vpc" "test" {
cidr_block = "10.0.0.0/16"

tags = {
Name = "tf-acc-test-ec2-transit-gateway-vpc-attachment"
}
}

resource "aws_subnet" "test" {
availability_zone = data.aws_availability_zones.available.names[0]
cidr_block = "10.0.0.0/24"
vpc_id = aws_vpc.test.id

tags = {
Name = "tf-acc-test-ec2-transit-gateway-vpc-attachment"
}
}

resource "aws_ec2_transit_gateway" "test" {
}

resource "aws_ec2_transit_gateway_vpc_attachment" "test" {
appliance_mode_support = %q
subnet_ids = [aws_subnet.test.id]
transit_gateway_id = aws_ec2_transit_gateway.test.id
vpc_id = aws_vpc.test.id
}
`, appModeSupport)
}

func testAccAWSEc2TransitGatewayVpcAttachmentConfigDnsSupport(dnsSupport string) string {
return fmt.Sprintf(`
data "aws_availability_zones" "available" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ The following arguments are supported:

In addition to all arguments above, the following attributes are exported:

* `appliance_mode_support` - Whether Appliance Mode support is enabled.
* `dns_support` - Whether DNS support is enabled.
* `id` - EC2 Transit Gateway VPC Attachment identifier
* `ipv6_support` - Whether IPv6 support is enabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ The following arguments are supported:
* `subnet_ids` - (Required) Identifiers of EC2 Subnets.
* `transit_gateway_id` - (Required) Identifier of EC2 Transit Gateway.
* `vpc_id` - (Required) Identifier of EC2 VPC.
* `appliance_mode_support` - (Optional) Whether Appliance Mode support is enabled. If enabled, a traffic flow between a source and destination uses the same Availability Zone for the VPC attachment for the lifetime of that flow. Valid values: `disable`, `enable`. Default value: `disable`.
* `dns_support` - (Optional) Whether DNS support is enabled. Valid values: `disable`, `enable`. Default value: `enable`.
* `ipv6_support` - (Optional) Whether IPv6 support is enabled. Valid values: `disable`, `enable`. Default value: `disable`.
* `tags` - (Optional) Key-value tags for the EC2 Transit Gateway VPC Attachment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ The following arguments are supported:
In addition to all arguments above, the following attributes are exported:

* `id` - EC2 Transit Gateway Attachment identifier
* `appliance_mode_support` - Whether Appliance Mode support is enabled. Valid values: `disable`, `enable`.
* `dns_support` - Whether DNS support is enabled. Valid values: `disable`, `enable`.
* `ipv6_support` - Whether IPv6 support is enabled. Valid values: `disable`, `enable`.
* `subnet_ids` - Identifiers of EC2 Subnets.
Expand Down