-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Changes from 3 commits
3da7baa
46c6b0e
9cdcec2
b6f983b
550b971
62b9b1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -40,6 +40,19 @@ func dataSourceAwsVpcPeeringConnection() *schema.Resource { | |||
Optional: true, | ||||
Computed: true, | ||||
}, | ||||
"cidr_block_set": { | ||||
Type: schema.TypeList, | ||||
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, | ||||
|
@@ -60,6 +73,19 @@ func dataSourceAwsVpcPeeringConnection() *schema.Resource { | |||
Optional: true, | ||||
Computed: true, | ||||
}, | ||||
"peer_cidr_block_set": { | ||||
Type: schema.TypeList, | ||||
Optional: true, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly:
Suggested change
|
||||
Computed: true, | ||||
Elem: &schema.Resource{ | ||||
Schema: map[string]*schema.Schema{ | ||||
"cidr_block": { | ||||
Type: schema.TypeString, | ||||
Computed: true, | ||||
}, | ||||
}, | ||||
}, | ||||
}, | ||||
"peer_region": { | ||||
Type: schema.TypeString, | ||||
Optional: true, | ||||
|
@@ -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) | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,25 @@ func TestAccDataSourceAwsVpcPeeringConnection_basic(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccDataSourceAwsVpcPeeringConnection_cidBlockSets(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Rename to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! |
||
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] | ||
|
@@ -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}" | ||
} | ||
` |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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. | ||||||
|
||||||
|
@@ -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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
#### Accepter and Requester Attributes Reference | ||||||
|
||||||
* `allow_remote_vpc_dns_resolution` - Indicates whether a local VPC can resolve public DNS hostnames to | ||||||
|
@@ -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. |
There was a problem hiding this comment.
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. 👍