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

Added CIDR block set to datasource VPC peering #13420

Merged
Show file tree
Hide file tree
Changes from 3 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
46 changes: 46 additions & 0 deletions aws/data_source_aws_vpc_peering_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ func dataSourceAwsVpcPeeringConnection() *schema.Resource {
Optional: true,
Computed: true,
},
"cidr_block_set": {
Type: schema.TypeList,
Optional: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the attribute is not used for configuring the data source, Optional should be removed. 👍

Suggested change
Optional: true,

Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cidr_block": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"region": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -60,6 +73,19 @@ func dataSourceAwsVpcPeeringConnection() *schema.Resource {
Optional: true,
Computed: true,
},
"peer_cidr_block_set": {
Type: schema.TypeList,
Optional: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly:

Suggested change
Optional: true,

Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cidr_block": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"peer_region": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -138,10 +164,30 @@ func dataSourceAwsVpcPeeringConnectionRead(d *schema.ResourceData, meta interfac
d.Set("vpc_id", pcx.RequesterVpcInfo.VpcId)
d.Set("owner_id", pcx.RequesterVpcInfo.OwnerId)
d.Set("cidr_block", pcx.RequesterVpcInfo.CidrBlock)
cidrBlockSet := []interface{}{}
for _, associationSet := range pcx.RequesterVpcInfo.CidrBlockSet {
association := map[string]interface{}{
"cidr_block": aws.StringValue(associationSet.CidrBlock),
}
cidrBlockSet = append(cidrBlockSet, association)
}
if err := d.Set("cidr_block_set", cidrBlockSet); err != nil {
return fmt.Errorf("error setting cidr_block_set: %s", err)
}
d.Set("region", pcx.RequesterVpcInfo.Region)
d.Set("peer_vpc_id", pcx.AccepterVpcInfo.VpcId)
d.Set("peer_owner_id", pcx.AccepterVpcInfo.OwnerId)
d.Set("peer_cidr_block", pcx.AccepterVpcInfo.CidrBlock)
peerCidrBlockSet := []interface{}{}
for _, associationSet := range pcx.AccepterVpcInfo.CidrBlockSet {
association := map[string]interface{}{
"cidr_block": aws.StringValue(associationSet.CidrBlock),
}
peerCidrBlockSet = append(peerCidrBlockSet, association)
}
if err := d.Set("peer_cidr_block_set", peerCidrBlockSet); err != nil {
return fmt.Errorf("error setting peer_cidr_block_set: %s", err)
}
d.Set("peer_region", pcx.AccepterVpcInfo.Region)
if err := d.Set("tags", keyvaluetags.Ec2KeyValueTags(pcx.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
Expand Down
63 changes: 63 additions & 0 deletions aws/data_source_aws_vpc_peering_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ func TestAccDataSourceAwsVpcPeeringConnection_basic(t *testing.T) {
})
}

func TestAccDataSourceAwsVpcPeeringConnection_cidBlockSets(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Rename to TestAccDataSourceAwsVpcPeeringConnection_cidrBlockSets().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!
Renamed

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAwsVpcPeeringConnectionCidrBlockSetConfig,
Check: resource.ComposeTestCheckFunc(
testAccDataSourceAwsVpcPeeringConnectionCheck("data.aws_vpc_peering_connection.test_by_id"),
resource.TestCheckResourceAttrSet("data.aws_vpc_peering_connection.test_by_id", "cidr_block_set.0.cidr_block"),
resource.TestCheckResourceAttrSet("data.aws_vpc_peering_connection.test_by_id", "cidr_block_set.1.cidr_block"),
resource.TestCheckResourceAttrSet("data.aws_vpc_peering_connection.test_by_id", "peer_cidr_block_set.0.cidr_block"),
resource.TestCheckResourceAttrSet("data.aws_vpc_peering_connection.test_by_id", "peer_cidr_block_set.1.cidr_block"),
),
},
},
})
}

func testAccDataSourceAwsVpcPeeringConnectionCheck(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
Expand Down Expand Up @@ -134,3 +153,47 @@ data "aws_vpc_peering_connection" "test_by_owner_ids" {
depends_on = ["aws_vpc_peering_connection.test"]
}
`

const testAccDataSourceAwsVpcPeeringConnectionCidrBlockSetConfig = `
resource "aws_vpc" "foo" {
cidr_block = "10.4.0.0/16"

tags = {
Name = "terraform-testacc-vpc-peering-connection-data-source-foo-cidr-block-set"
}
}

resource "aws_vpc_ipv4_cidr_block_association" "foo_secondary_cidr" {
vpc_id = "${aws_vpc.foo.id}"
cidr_block = "10.5.0.0/16"
}

resource "aws_vpc" "bar" {
cidr_block = "10.6.0.0/16"

tags = {
Name = "terraform-testacc-vpc-peering-connection-data-source-bar-cidr-block-set"
}
}

resource "aws_vpc_ipv4_cidr_block_association" "bar_secondary_cidr" {
vpc_id = "${aws_vpc.bar.id}"
cidr_block = "10.7.0.0/16"
}

resource "aws_vpc_peering_connection" "test" {
vpc_id = "${aws_vpc.foo.id}"
peer_vpc_id = "${aws_vpc.bar.id}"
auto_accept = true

tags = {
Name = "terraform-testacc-vpc-peering-connection-data-source-foo-to-bar-cidr-block-set"
}

depends_on = ["aws_vpc_ipv4_cidr_block_association.foo_secondary_cidr", "aws_vpc_ipv4_cidr_block_association.bar_secondary_cidr"]
}

data "aws_vpc_peering_connection" "test_by_id" {
id = "${aws_vpc_peering_connection.test.id}"
}
`
12 changes: 10 additions & 2 deletions website/docs/d/vpc_peering_connection.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ The given filters must match exactly one VPC peering connection whose data will

* `owner_id` - (Optional) The AWS account ID of the owner of the requester VPC of the specific VPC Peering Connection to retrieve.

* `cidr_block` - (Optional) The CIDR block of the requester VPC of the specific VPC Peering Connection to retrieve.
* `cidr_block` - (Optional) The primary CIDR block of the requester VPC of the specific VPC Peering Connection to retrieve.

* `region` - (Optional) The region of the requester VPC of the specific VPC Peering Connection to retrieve.

* `peer_vpc_id` - (Optional) The ID of the accepter VPC of the specific VPC Peering Connection to retrieve.

* `peer_owner_id` - (Optional) The AWS account ID of the owner of the accepter VPC of the specific VPC Peering Connection to retrieve.

* `peer_cidr_block` - (Optional) The CIDR block of the accepter VPC of the specific VPC Peering Connection to retrieve.
* `peer_cidr_block` - (Optional) The primary CIDR block of the accepter VPC of the specific VPC Peering Connection to retrieve.

* `peer_region` - (Optional) The region of the accepter VPC of the specific VPC Peering Connection to retrieve.

Expand Down Expand Up @@ -82,6 +82,10 @@ All of the argument attributes except `filter` are also exported as result attri
* `requester` - A configuration block that describes [VPC Peering Connection]
(http://docs.aws.amazon.com/AmazonVPC/latest/PeeringGuide) options set for the requester VPC.

* `cidr_block_set` - (Optional) The list of all CIDR blocks of the requester VPC of the specific VPC Peering Connection to retrieve.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* `cidr_block_set` - (Optional) The list of all CIDR blocks of the requester VPC of the specific VPC Peering Connection to retrieve.
* `cidr_block_set` - List of all CIDR blocks of the requester VPC.


* `peer_cidr_block_set` - (Optional) The list of all CIDR blocks of the accepter VPC of the specific VPC Peering Connection to retrieve.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* `peer_cidr_block_set` - (Optional) The list of all CIDR blocks of the accepter VPC of the specific VPC Peering Connection to retrieve.
* `peer_cidr_block_set` - List of all CIDR blocks of the accepter VPC.


#### Accepter and Requester Attributes Reference

* `allow_remote_vpc_dns_resolution` - Indicates whether a local VPC can resolve public DNS hostnames to
Expand All @@ -92,3 +96,7 @@ with the peer VPC over the VPC peering connection.

* `allow_vpc_to_remote_classic_link` - Indicates whether a local VPC can communicate with a ClassicLink
connection in the peer VPC over the VPC peering connection.

#### CIDR block set Attributes Reference

* `cidr_block` - A CIDR block associated to the VPC of the specific VPC Peering Connection.