From 47bccaa3259c71769fbd5fba32cfaa9dc5ef96c6 Mon Sep 17 00:00:00 2001 From: stack72 Date: Fri, 7 Jul 2017 14:31:03 +0300 Subject: [PATCH] resource/aws_vpc: Add support for classiclink_dns_support Fixes: #1076 ``` % make testacc TEST=./aws TESTARGS='-run=TestAccAWSVpc' ==> Checking that code complies with gofmt requirements... TF_ACC=1 go test ./aws -v -run=TestAccAWSVpc -timeout 120m === RUN TestAccAWSVpcEndpoint_importBasic --- PASS: TestAccAWSVpcEndpoint_importBasic (68.54s) === RUN TestAccAWSVpc_importBasic --- PASS: TestAccAWSVpc_importBasic (53.29s) === RUN TestAccAWSVpcEndpointRouteTableAssociation_basic --- PASS: TestAccAWSVpcEndpointRouteTableAssociation_basic (59.57s) === RUN TestAccAWSVpcEndpoint_basic --- PASS: TestAccAWSVpcEndpoint_basic (58.48s) === RUN TestAccAWSVpcEndpoint_withRouteTableAndPolicy --- PASS: TestAccAWSVpcEndpoint_withRouteTableAndPolicy (117.51s) === RUN TestAccAWSVpcEndpoint_WithoutRouteTableOrPolicyConfig --- PASS: TestAccAWSVpcEndpoint_WithoutRouteTableOrPolicyConfig (53.33s) === RUN TestAccAWSVpcEndpoint_removed --- PASS: TestAccAWSVpcEndpoint_removed (49.14s) === RUN TestAccAWSVpc_basic --- PASS: TestAccAWSVpc_basic (45.19s) === RUN TestAccAWSVpc_enableIpv6 --- PASS: TestAccAWSVpc_enableIpv6 (132.93s) === RUN TestAccAWSVpc_dedicatedTenancy --- PASS: TestAccAWSVpc_dedicatedTenancy (46.52s) === RUN TestAccAWSVpc_tags --- PASS: TestAccAWSVpc_tags (87.11s) === RUN TestAccAWSVpc_update --- PASS: TestAccAWSVpc_update (85.61s) === RUN TestAccAWSVpc_DisabledDnsSupport --- PASS: TestAccAWSVpc_DisabledDnsSupport (43.34s) === RUN TestAccAWSVpc_classiclinkOptionSet --- PASS: TestAccAWSVpc_classiclinkOptionSet (45.99s) === RUN TestAccAWSVpc_classiclinkDnsSupportOptionSet --- PASS: TestAccAWSVpc_classiclinkDnsSupportOptionSet (52.46s) PASS ok github.com/terraform-providers/terraform-provider-aws/aws 1009.082s ``` --- aws/resource_aws_vpc.go | 58 +++++++++++++++++++++++++++++++- aws/resource_aws_vpc_test.go | 26 ++++++++++++++ website/docs/r/vpc.html.markdown | 2 ++ 3 files changed, 85 insertions(+), 1 deletion(-) diff --git a/aws/resource_aws_vpc.go b/aws/resource_aws_vpc.go index 6a8edca4b8fe..876a8ca83dc5 100644 --- a/aws/resource_aws_vpc.go +++ b/aws/resource_aws_vpc.go @@ -58,6 +58,12 @@ func resourceAwsVpc() *schema.Resource { Computed: true, }, + "enable_classiclink_dns_support": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + "assign_generated_ipv6_cidr_block": { Type: schema.TypeBool, Optional: true, @@ -235,6 +241,30 @@ func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error { d.Set("enable_classiclink", classiclink_enabled) } + DescribeClassiclinkDnsOpts := &ec2.DescribeVpcClassicLinkDnsSupportInput{ + VpcIds: []*string{&vpcid}, + } + + respClassiclinkDnsSupport, err := conn.DescribeVpcClassicLinkDnsSupport(DescribeClassiclinkDnsOpts) + if err != nil { + if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "UnsupportedOperation" { + log.Printf("[WARN] VPC Classic Link DNS Support is not supported in this region") + } else { + return err + } + } else { + classiclinkdns_enabled := false + for _, v := range respClassiclinkDnsSupport.Vpcs { + if *v.VpcId == vpcid { + if v.ClassicLinkDnsSupported != nil { + classiclinkdns_enabled = *v.ClassicLinkDnsSupported + } + break + } + } + d.Set("enable_classiclink_dns_support", classiclinkdns_enabled) + } + // Get the main routing table for this VPC // Really Ugly need to make this better - rmenn filter1 := &ec2.Filter{ @@ -317,7 +347,6 @@ func resourceAwsVpcUpdate(d *schema.ResourceData, meta interface{}) error { if d.HasChange("enable_classiclink") { val := d.Get("enable_classiclink").(bool) - if val { modifyOpts := &ec2.EnableVpcClassicLinkInput{ VpcId: &vpcid, @@ -343,6 +372,33 @@ func resourceAwsVpcUpdate(d *schema.ResourceData, meta interface{}) error { d.SetPartial("enable_classiclink") } + if d.HasChange("enable_classiclink_dns_support") { + val := d.Get("enable_classiclink_dns_support").(bool) + if val { + modifyOpts := &ec2.EnableVpcClassicLinkDnsSupportInput{ + VpcId: &vpcid, + } + log.Printf( + "[INFO] Modifying enable_classiclink_dns_support vpc attribute for %s: %#v", + d.Id(), modifyOpts) + if _, err := conn.EnableVpcClassicLinkDnsSupport(modifyOpts); err != nil { + return err + } + } else { + modifyOpts := &ec2.DisableVpcClassicLinkDnsSupportInput{ + VpcId: &vpcid, + } + log.Printf( + "[INFO] Modifying enable_classiclink_dns_support vpc attribute for %s: %#v", + d.Id(), modifyOpts) + if _, err := conn.DisableVpcClassicLinkDnsSupport(modifyOpts); err != nil { + return err + } + } + + d.SetPartial("enable_classiclink_dns_support") + } + if d.HasChange("assign_generated_ipv6_cidr_block") && !d.IsNewResource() { toAssign := d.Get("assign_generated_ipv6_cidr_block").(bool) diff --git a/aws/resource_aws_vpc_test.go b/aws/resource_aws_vpc_test.go index ca68bdfe8c18..2aeafe512c4f 100644 --- a/aws/resource_aws_vpc_test.go +++ b/aws/resource_aws_vpc_test.go @@ -298,6 +298,23 @@ func TestAccAWSVpc_classiclinkOptionSet(t *testing.T) { }) } +func TestAccAWSVpc_classiclinkDnsSupportOptionSet(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckVpcDestroy, + Steps: []resource.TestStep{ + { + Config: testAccVpcConfig_ClassiclinkDnsSupportOption, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "aws_vpc.bar", "enable_classiclink_dns_support", "true"), + ), + }, + }, + }) +} + const testAccVpcConfig = ` resource "aws_vpc" "foo" { cidr_block = "10.1.0.0/16" @@ -383,3 +400,12 @@ resource "aws_vpc" "bar" { enable_classiclink = true } ` + +const testAccVpcConfig_ClassiclinkDnsSupportOption = ` +resource "aws_vpc" "bar" { + cidr_block = "172.2.0.0/16" + + enable_classiclink = true + enable_classiclink_dns_support = true +} +` diff --git a/website/docs/r/vpc.html.markdown b/website/docs/r/vpc.html.markdown index 115da9d2399c..7423a584f056 100644 --- a/website/docs/r/vpc.html.markdown +++ b/website/docs/r/vpc.html.markdown @@ -44,6 +44,8 @@ The following arguments are supported: * `enable_classiclink` - (Optional) A boolean flag to enable/disable ClassicLink for the VPC. Only valid in regions and accounts that support EC2 Classic. See the [ClassicLink documentation][1] for more information. Defaults false. +* `enable_classiclink_dns_support` - (Optional) A boolean flag to enable/disable ClassicLink DNS Support for the VPC. + Only valid in regions and accounts that support EC2 Classic. * `assign_generated_ipv6_cidr_block` - (Optional) Requests an Amazon-provided IPv6 CIDR block with a /56 prefix length for the VPC. You cannot specify the range of IP addresses, or the size of the CIDR block. Default is `false`.