Skip to content

Commit 7e089cf

Browse files
committed
Support more filter options in vpc-peering-accepter
1 parent 9beaaf7 commit 7e089cf

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

modules/vpc-peering-accepter/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ This module creates following resources.
3131
|------|------|
3232
| [aws_vpc_peering_connection_accepter.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_peering_connection_accepter) | resource |
3333
| [aws_vpc_peering_connection_options.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_peering_connection_options) | resource |
34+
| [aws_caller_identity.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
35+
| [aws_region.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
3436
| [aws_vpc_peering_connection.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc_peering_connection) | data source |
3537

3638
## Inputs
3739

3840
| Name | Description | Type | Default | Required |
3941
|------|-------------|------|---------|:--------:|
4042
| <a name="input_name"></a> [name](#input\_name) | (Required) Desired name for the VPC Peering resources. | `string` | n/a | yes |
41-
| <a name="input_peering_connection"></a> [peering\_connection](#input\_peering\_connection) | (Required) The information of the VPC Peering Connection to accept. The given filters must match exactly one VPC peering connection. `peering_connection` as defined below.<br> (Optional) `id` - The VPC Peering Connection ID to manage.<br> account. | <pre>object({<br> id = optional(string)<br> })</pre> | n/a | yes |
43+
| <a name="input_peering_connection"></a> [peering\_connection](#input\_peering\_connection) | (Required) The information of the VPC Peering Connection to accept. The given filters must match exactly one VPC peering connection. `peering_connection` as defined below.<br> (Optional) `id` - The VPC Peering Connection ID to manage.<br> (Optional) `requester_vpc` - The information of the requester VPC. `requester_vpc` as defined below.<br> (Optional) `id` - The ID of the requester VPC.<br> (Optional) `region` - The region of the VPC with which you are creating the VPC Peering Connection.<br> (Optional) `account` - The AWS account ID of the owner of the peer VPC.<br> (Optional) `accepter_vpc` - The information of the accepter VPC. `accepter_vpc` as defined below.<br> (Optional) `id` - The ID of the accepter VPC.<br> account. | <pre>object({<br> id = optional(string)<br> requester_vpc = optional(object({<br> id = optional(string)<br> region = optional(string)<br> account = optional(string)<br><br> ipv4_cidr = optional(string)<br> }), {})<br> accepter_vpc = optional(object({<br> id = optional(string)<br><br> ipv4_cidr = optional(string)<br> }), {})<br> })</pre> | n/a | yes |
4244
| <a name="input_allow_remote_vpc_dns_resolution"></a> [allow\_remote\_vpc\_dns\_resolution](#input\_allow\_remote\_vpc\_dns\_resolution) | (Optional) Whether to allow a accepter VPC to resolve public DNS hostnames to private IP addresses when queried from instances in the requester VPC. Defaults to `false`. | `bool` | `false` | no |
4345
| <a name="input_module_tags_enabled"></a> [module\_tags\_enabled](#input\_module\_tags\_enabled) | (Optional) Whether to create AWS Resource Tags for the module informations. | `bool` | `true` | no |
4446
| <a name="input_resource_group_description"></a> [resource\_group\_description](#input\_resource\_group\_description) | (Optional) The description of Resource Group. | `string` | `"Managed by Terraform."` | no |

modules/vpc-peering-accepter/main.tf

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@ locals {
1414
} : {}
1515
}
1616

17+
data "aws_caller_identity" "this" {}
18+
data "aws_region" "this" {}
19+
20+
data "aws_vpc_peering_connection" "this" {
21+
id = var.peering_connection.id
22+
23+
vpc_id = var.peering_connection.requester_vpc.id
24+
region = var.peering_connection.requester_vpc.region
25+
owner_id = var.peering_connection.requester_vpc.account
26+
cidr_block = var.peering_connection.requester_vpc.ipv4_cidr
27+
28+
peer_vpc_id = var.peering_connection.accepter_vpc.id
29+
peer_region = data.aws_region.this.name
30+
peer_owner_id = data.aws_caller_identity.this.account_id
31+
peer_cidr_block = var.peering_connection.accepter_vpc.ipv4_cidr
32+
}
33+
1734
locals {
1835
requester_vpc = {
1936
account = data.aws_vpc_peering_connection.this.owner_id
@@ -62,7 +79,3 @@ resource "aws_vpc_peering_connection_options" "this" {
6279
allow_remote_vpc_dns_resolution = var.allow_remote_vpc_dns_resolution
6380
}
6481
}
65-
66-
data "aws_vpc_peering_connection" "this" {
67-
id = var.peering_connection.id
68-
}

modules/vpc-peering-accepter/variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,28 @@ variable "peering_connection" {
22
description = <<EOF
33
(Required) The information of the VPC Peering Connection to accept. The given filters must match exactly one VPC peering connection. `peering_connection` as defined below.
44
(Optional) `id` - The VPC Peering Connection ID to manage.
5+
(Optional) `requester_vpc` - The information of the requester VPC. `requester_vpc` as defined below.
6+
(Optional) `id` - The ID of the requester VPC.
7+
(Optional) `region` - The region of the VPC with which you are creating the VPC Peering Connection.
8+
(Optional) `account` - The AWS account ID of the owner of the peer VPC.
9+
(Optional) `accepter_vpc` - The information of the accepter VPC. `accepter_vpc` as defined below.
10+
(Optional) `id` - The ID of the accepter VPC.
511
account.
612
EOF
713
type = object({
814
id = optional(string)
15+
requester_vpc = optional(object({
16+
id = optional(string)
17+
region = optional(string)
18+
account = optional(string)
19+
20+
ipv4_cidr = optional(string)
21+
}), {})
22+
accepter_vpc = optional(object({
23+
id = optional(string)
24+
25+
ipv4_cidr = optional(string)
26+
}), {})
927
})
1028
nullable = false
1129
}

0 commit comments

Comments
 (0)