diff --git a/builtin/providers/aws/data_source_aws_vpc.go b/builtin/providers/aws/data_source_aws_vpc.go index ffcad8cc6..6e09e971d 100644 --- a/builtin/providers/aws/data_source_aws_vpc.go +++ b/builtin/providers/aws/data_source_aws_vpc.go @@ -14,19 +14,19 @@ func dataSourceAwsVpc() *schema.Resource { Read: dataSourceAwsVpcRead, Schema: map[string]*schema.Schema{ - "cidr_block": &schema.Schema{ + "cidr_block": { Type: schema.TypeString, Optional: true, Computed: true, }, - "dhcp_options_id": &schema.Schema{ + "dhcp_options_id": { Type: schema.TypeString, Optional: true, Computed: true, }, - "default": &schema.Schema{ + "default": { Type: schema.TypeBool, Optional: true, Computed: true, @@ -34,18 +34,28 @@ func dataSourceAwsVpc() *schema.Resource { "filter": ec2CustomFiltersSchema(), - "id": &schema.Schema{ + "id": { Type: schema.TypeString, Optional: true, Computed: true, }, - "instance_tenancy": &schema.Schema{ + "instance_tenancy": { Type: schema.TypeString, Computed: true, }, - "state": &schema.Schema{ + "ipv6_cidr_block": { + Type: schema.TypeString, + Computed: true, + }, + + "ipv6_association_id": { + Type: schema.TypeString, + Computed: true, + }, + + "state": { Type: schema.TypeString, Optional: true, Computed: true, @@ -117,5 +127,10 @@ func dataSourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error { d.Set("state", vpc.State) d.Set("tags", tagsToMap(vpc.Tags)) + if vpc.Ipv6CidrBlockAssociationSet != nil { + d.Set("ipv6_association_id", vpc.Ipv6CidrBlockAssociationSet[0].AssociationId) + d.Set("ipv6_cidr_block", vpc.Ipv6CidrBlockAssociationSet[0].Ipv6CidrBlock) + } + return nil } diff --git a/builtin/providers/aws/data_source_aws_vpc_test.go b/builtin/providers/aws/data_source_aws_vpc_test.go index 9a1996742..dbc09fea1 100644 --- a/builtin/providers/aws/data_source_aws_vpc_test.go +++ b/builtin/providers/aws/data_source_aws_vpc_test.go @@ -13,7 +13,7 @@ func TestAccDataSourceAwsVpc_basic(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccDataSourceAwsVpcConfig, Check: resource.ComposeTestCheckFunc( testAccDataSourceAwsVpcCheck("data.aws_vpc.by_id"), @@ -26,6 +26,25 @@ func TestAccDataSourceAwsVpc_basic(t *testing.T) { }) } +func TestAccDataSourceAwsVpc_ipv6Associated(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAwsVpcConfigIpv6, + Check: resource.ComposeTestCheckFunc( + testAccDataSourceAwsVpcCheck("data.aws_vpc.by_id"), + resource.TestCheckResourceAttrSet( + "data.aws_vpc.by_id", "ipv6_association_id"), + resource.TestCheckResourceAttrSet( + "data.aws_vpc.by_id", "ipv6_cidr_block"), + ), + }, + }, + }) +} + func testAccDataSourceAwsVpcCheck(name string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] @@ -59,6 +78,25 @@ func testAccDataSourceAwsVpcCheck(name string) resource.TestCheckFunc { } } +const testAccDataSourceAwsVpcConfigIpv6 = ` +provider "aws" { + region = "us-west-2" +} + +resource "aws_vpc" "test" { + cidr_block = "172.16.0.0/16" + assign_generated_ipv6_cidr_block = true + + tags { + Name = "terraform-testacc-vpc-data-source" + } +} + +data "aws_vpc" "by_id" { + id = "${aws_vpc.test.id}" +} +` + const testAccDataSourceAwsVpcConfig = ` provider "aws" { region = "us-west-2" diff --git a/website/source/docs/providers/aws/d/vpc.html.markdown b/website/source/docs/providers/aws/d/vpc.html.markdown index 859c0f76f..e1c5f4f17 100644 --- a/website/source/docs/providers/aws/d/vpc.html.markdown +++ b/website/source/docs/providers/aws/d/vpc.html.markdown @@ -77,3 +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.