Skip to content

Commit

Permalink
resource/aws_vpc: Add support for classiclink_dns_support (#1079)
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
stack72 authored Jul 7, 2017
1 parent 48eb1c7 commit 063939e
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
58 changes: 57 additions & 1 deletion aws/resource_aws_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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,
Expand All @@ -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)

Expand Down
26 changes: 26 additions & 0 deletions aws/resource_aws_vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
`
2 changes: 2 additions & 0 deletions website/docs/r/vpc.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down

0 comments on commit 063939e

Please sign in to comment.