diff --git a/modules/vpc-peering-accepter/README.md b/modules/vpc-peering-accepter/README.md index b7b0e42..1c4091f 100644 --- a/modules/vpc-peering-accepter/README.md +++ b/modules/vpc-peering-accepter/README.md @@ -31,6 +31,8 @@ This module creates following resources. |------|------| | [aws_vpc_peering_connection_accepter.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_peering_connection_accepter) | resource | | [aws_vpc_peering_connection_options.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_peering_connection_options) | resource | +| [aws_caller_identity.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source | +| [aws_region.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source | | [aws_vpc_peering_connection.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc_peering_connection) | data source | ## Inputs @@ -38,7 +40,7 @@ This module creates following resources. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | [name](#input\_name) | (Required) Desired name for the VPC Peering resources. | `string` | n/a | yes | -| [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.
(Optional) `id` - The VPC Peering Connection ID to manage.
account. |
object({
id = optional(string)
})
| n/a | yes | +| [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.
(Optional) `id` - The VPC Peering Connection ID to manage.
(Optional) `requester_vpc` - The information of the requester VPC. `requester_vpc` as defined below.
(Optional) `id` - The ID of the requester VPC.
(Optional) `region` - The region of the VPC with which you are creating the VPC Peering Connection.
(Optional) `account` - The AWS account ID of the owner of the peer VPC.
(Optional) `accepter_vpc` - The information of the accepter VPC. `accepter_vpc` as defined below.
(Optional) `id` - The ID of the accepter VPC.
account. |
object({
id = optional(string)
requester_vpc = optional(object({
id = optional(string)
region = optional(string)
account = optional(string)

ipv4_cidr = optional(string)
}), {})
accepter_vpc = optional(object({
id = optional(string)

ipv4_cidr = optional(string)
}), {})
})
| n/a | yes | | [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 | | [module\_tags\_enabled](#input\_module\_tags\_enabled) | (Optional) Whether to create AWS Resource Tags for the module informations. | `bool` | `true` | no | | [resource\_group\_description](#input\_resource\_group\_description) | (Optional) The description of Resource Group. | `string` | `"Managed by Terraform."` | no | diff --git a/modules/vpc-peering-accepter/main.tf b/modules/vpc-peering-accepter/main.tf index 2e0d79b..448cfc2 100644 --- a/modules/vpc-peering-accepter/main.tf +++ b/modules/vpc-peering-accepter/main.tf @@ -14,6 +14,23 @@ locals { } : {} } +data "aws_caller_identity" "this" {} +data "aws_region" "this" {} + +data "aws_vpc_peering_connection" "this" { + id = var.peering_connection.id + + vpc_id = var.peering_connection.requester_vpc.id + region = var.peering_connection.requester_vpc.region + owner_id = var.peering_connection.requester_vpc.account + cidr_block = var.peering_connection.requester_vpc.ipv4_cidr + + peer_vpc_id = var.peering_connection.accepter_vpc.id + peer_region = data.aws_region.this.name + peer_owner_id = data.aws_caller_identity.this.account_id + peer_cidr_block = var.peering_connection.accepter_vpc.ipv4_cidr +} + locals { requester_vpc = { account = data.aws_vpc_peering_connection.this.owner_id @@ -62,7 +79,3 @@ resource "aws_vpc_peering_connection_options" "this" { allow_remote_vpc_dns_resolution = var.allow_remote_vpc_dns_resolution } } - -data "aws_vpc_peering_connection" "this" { - id = var.peering_connection.id -} diff --git a/modules/vpc-peering-accepter/variables.tf b/modules/vpc-peering-accepter/variables.tf index 6469932..9e9089f 100644 --- a/modules/vpc-peering-accepter/variables.tf +++ b/modules/vpc-peering-accepter/variables.tf @@ -2,10 +2,28 @@ variable "peering_connection" { description = <