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`.