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

resource/aws_vpc: Add support for classiclink_dns_support #1079

Merged
merged 1 commit into from
Jul 7, 2017
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
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
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we default this value to false? It looks like here in the error case the value will not get set at all (d.Set only called in the else clause here). I'm imagining a situation where a user has an account/region that doesn't support this, they try to enable it with true here, it fails, but we never set it ourselves to false and so they end up with true in the state file, which doesn't reflect reality. Is that possible or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This follows exactly the same pattern as enable_classiclink - that seems to work well so therefore, we don't set it to default - thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

} 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