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

data/aws_vpc: Expose enable_dns_* in aws_vpc data_source #1373

Merged
merged 1 commit into from
Aug 9, 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
22 changes: 22 additions & 0 deletions aws/data_source_aws_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ func dataSourceAwsVpc() *schema.Resource {
Computed: true,
},

"enable_dns_hostnames": {
Type: schema.TypeBool,
Computed: true,
},

"enable_dns_support": {
Type: schema.TypeBool,
Computed: true,
},

"tags": tagsSchemaComputed(),
},
}
Expand Down Expand Up @@ -132,5 +142,17 @@ func dataSourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error {
d.Set("ipv6_cidr_block", vpc.Ipv6CidrBlockAssociationSet[0].Ipv6CidrBlock)
}

attResp, err := awsVpcDescribeVpcAttribute("enableDnsSupport", *vpc.VpcId, conn)
if err != nil {
return err
}
d.Set("enable_dns_support", attResp.EnableDnsSupport.Value)

attResp, err = awsVpcDescribeVpcAttribute("enableDnsHostnames", *vpc.VpcId, conn)
if err != nil {
return err
}
d.Set("enable_dns_hostnames", attResp.EnableDnsHostnames.Value)

return nil
}
4 changes: 4 additions & 0 deletions aws/data_source_aws_vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func TestAccDataSourceAwsVpc_basic(t *testing.T) {
testAccDataSourceAwsVpcCheck("data.aws_vpc.by_cidr", cidr, tag),
testAccDataSourceAwsVpcCheck("data.aws_vpc.by_tag", cidr, tag),
testAccDataSourceAwsVpcCheck("data.aws_vpc.by_filter", cidr, tag),
resource.TestCheckResourceAttr(
"data.aws_vpc.by_id", "enable_dns_support", "true"),
resource.TestCheckResourceAttr(
"data.aws_vpc.by_id", "enable_dns_hostnames", "false"),
),
},
},
Expand Down
33 changes: 18 additions & 15 deletions aws/resource_aws_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,27 +194,17 @@ func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error {
}
}

// Attributes
attribute := "enableDnsSupport"
describeAttrOpts := &ec2.DescribeVpcAttributeInput{
Attribute: aws.String(attribute),
VpcId: aws.String(vpcid),
}
resp, err := conn.DescribeVpcAttribute(describeAttrOpts)
resp, err := awsVpcDescribeVpcAttribute("enableDnsSupport", vpcid, conn)
if err != nil {
return err
}
d.Set("enable_dns_support", *resp.EnableDnsSupport.Value)
attribute = "enableDnsHostnames"
describeAttrOpts = &ec2.DescribeVpcAttributeInput{
Attribute: &attribute,
VpcId: &vpcid,
}
resp, err = conn.DescribeVpcAttribute(describeAttrOpts)
d.Set("enable_dns_support", resp.EnableDnsSupport.Value)

resp, err = awsVpcDescribeVpcAttribute("enableDnsHostnames", vpcid, conn)
if err != nil {
return err
}
d.Set("enable_dns_hostnames", *resp.EnableDnsHostnames.Value)
d.Set("enable_dns_hostnames", resp.EnableDnsHostnames.Value)

describeClassiclinkOpts := &ec2.DescribeVpcClassicLinkInput{
VpcIds: []*string{&vpcid},
Expand Down Expand Up @@ -647,3 +637,16 @@ func resourceAwsVpcInstanceImport(
d.Set("assign_generated_ipv6_cidr_block", false)
return []*schema.ResourceData{d}, nil
}

func awsVpcDescribeVpcAttribute(attribute string, vpcId string, conn *ec2.EC2) (*ec2.DescribeVpcAttributeOutput, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

describeAttrOpts := &ec2.DescribeVpcAttributeInput{
Attribute: aws.String(attribute),
VpcId: aws.String(vpcId),
}
resp, err := conn.DescribeVpcAttribute(describeAttrOpts)
if err != nil {
return nil, err
}

return resp, nil
}
4 changes: 2 additions & 2 deletions website/docs/d/vpc.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ The following attribute is additionally exported:

* `instance_tenancy` - The allowed tenancy of instances launched into the
selected VPC. May be any of `"default"`, `"dedicated"`, or `"host"`.

* `ipv6_association_id` - The association ID for the IPv6 CIDR block.

* `ipv6_cidr_block` - The IPv6 CIDR block.
* `enable_dns_support` - Whether or not the VPC has DNS support
* `enable_dns_hostnames` - Whether or not the VPC has DNS hostname support