Skip to content

Commit 021c5d3

Browse files
updated submodule of vpc, added variable (#8)
* updated submodule of vpc, added variable and peering support
1 parent c0f4620 commit 021c5d3

File tree

7 files changed

+55
-39
lines changed

7 files changed

+55
-39
lines changed

examples/complete-vpc-with-vpn/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ No providers.
3232
| Name | Source | Version |
3333
|------|--------|---------|
3434
| <a name="module_key_pair_vpn"></a> [key\_pair\_vpn](#module\_key\_pair\_vpn) | squareops/keypair/aws | n/a |
35-
| <a name="module_vpc"></a> [vpc](#module\_vpc) | ../../ | n/a |
35+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | squareops/vpc/aws | n/a |
3636

3737
## Resources
3838

examples/vpc-with-peering/main.tf

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
locals {
2-
accepter_vpc_id = "vpc-034d30be2f4d1skaf"
3-
requester_vpc_id = "vpc-0fbdbf97efdf3skaf"
4-
accepter_vpc_region = "us-east-2"
5-
requester_vpc_region = "us-east-2"
2+
accepter_name = "tenent-peering"
3+
accepter_region = "us-east-2"
4+
accepter_vpc_id = "vpc-049f2peerb195d692"
5+
requester_name = "management-peering"
6+
requester_region = "us-east-2"
7+
requester_vpc_id = "vpc-0125epeere8cfb616"
8+
additional_tags = {
9+
Owner = "tenent"
10+
Tenancy = "dedicated"
11+
}
612
}
713

814
module "vpc_peering" {
915
source = "squareops/vpc/aws//modules/vpc_peering"
10-
name = "vpc-peer"
16+
accepter_name = local.accepter_name
1117
accepter_vpc_id = local.accepter_vpc_id
18+
accepter_vpc_region = local.accepter_region
19+
requester_name = local.requester_name
1220
requester_vpc_id = local.requester_vpc_id
13-
accepter_vpc_region = local.accepter_vpc_region
14-
requester_vpc_region = local.requester_vpc_region
15-
21+
requester_vpc_region = local.requester_region
1622
}

examples/vpc-with-peering/provider.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
provider "aws" {
2+
region = local.region
3+
default_tags {
4+
tags = local.additional_tags
5+
}
6+
}

modules/vpc_peering/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ No modules.
5656

5757
| Name | Description | Type | Default | Required |
5858
|------|-------------|------|---------|:--------:|
59-
| <a name="input_accepter_vpc_id"></a> [accepter\_vpc\_id](#input\_accepter\_vpc\_id) | The ID of Acceptor VPC | `string` | `""` | no |
60-
| <a name="input_accepter_vpc_region"></a> [accepter\_vpc\_region](#input\_accepter\_vpc\_region) | The region of Acceptor VPC | `string` | `""` | no |
61-
| <a name="input_create"></a> [create](#input\_create) | Set it to true to create VPC peering | `bool` | `true` | no |
62-
| <a name="input_name"></a> [name](#input\_name) | Name for the VPC peering | `string` | `""` | no |
63-
| <a name="input_requester_vpc_id"></a> [requester\_vpc\_id](#input\_requester\_vpc\_id) | The ID of Requester VPC | `string` | `""` | no |
64-
| <a name="input_requester_vpc_region"></a> [requester\_vpc\_region](#input\_requester\_vpc\_region) | The region Requester VPC | `string` | `""` | no |
59+
| <a name="input_accepter_name"></a> [accepter\_name](#input\_accepter\_name) | Assign a meaningful name or label to the VPC Accepter. This aids in distinguishing the Accepter VPC within the VPC peering connection. | `string` | `""` | no |
60+
| <a name="input_accepter_vpc_id"></a> [accepter\_vpc\_id](#input\_accepter\_vpc\_id) | Specify the unique identifier of the VPC that will act as the Acceptor in the VPC peering connection. | `string` | `""` | no |
61+
| <a name="input_accepter_vpc_region"></a> [accepter\_vpc\_region](#input\_accepter\_vpc\_region) | Provide the AWS region where the Acceptor VPC is located. This helps in identifying the correct region for establishing the VPC peering connection. | `string` | `""` | no |
62+
| <a name="input_peering_enabled"></a> [peering\_enabled](#input\_peering\_enabled) | Set this variable to true if you want to create the VPC peering connection. Set it to false if you want to skip the creation process. | `bool` | `true` | no |
63+
| <a name="input_requester_name"></a> [requester\_name](#input\_requester\_name) | Provide a descriptive name or label for the VPC Requester. This helps identify and differentiate the Requester VPC in the peering connection. | `string` | `""` | no |
64+
| <a name="input_requester_vpc_id"></a> [requester\_vpc\_id](#input\_requester\_vpc\_id) | Specify the unique identifier of the VPC that will act as the Reqester in the VPC peering connection. | `string` | `""` | no |
65+
| <a name="input_requester_vpc_region"></a> [requester\_vpc\_region](#input\_requester\_vpc\_region) | Specify the AWS region where the Requester VPC resides. It ensures the correct region is used for setting up the VPC peering. | `string` | `""` | no |
6566

6667
## Outputs
6768

modules/vpc_peering/main.tf

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,30 @@ data "aws_route_tables" "requester" {
3434
}
3535

3636
resource "aws_vpc_peering_connection" "this" {
37-
count = var.create ? 1 : 0
37+
count = var.peering_enabled ? 1 : 0
3838
vpc_id = var.requester_vpc_id
3939
peer_vpc_id = var.accepter_vpc_id
4040
peer_region = var.accepter_vpc_region
4141
auto_accept = false
4242
provider = aws.peer
4343
tags = {
44-
Name = var.name
45-
Side = "Requester"
44+
Name = format("%s-%s-%s", var.requester_name, "to", var.accepter_name)
4645
}
4746
}
4847

4948
resource "aws_vpc_peering_connection_accepter" "this" {
50-
count = var.create ? 1 : 0
49+
count = var.peering_enabled ? 1 : 0
5150
depends_on = [aws_vpc_peering_connection.this]
5251
provider = aws.accepter
5352
vpc_peering_connection_id = aws_vpc_peering_connection.this[0].id
5453
auto_accept = true
5554
tags = {
56-
Name = var.name
57-
Side = "Accepter"
55+
Name = format("%s-%s-%s", var.requester_name, "to", var.accepter_name)
5856
}
5957
}
6058

6159
resource "aws_vpc_peering_connection_options" "this" {
62-
count = var.create ? 1 : 0
60+
count = var.peering_enabled ? 1 : 0
6361
depends_on = [aws_vpc_peering_connection_accepter.this]
6462
vpc_peering_connection_id = aws_vpc_peering_connection.this[0].id
6563
accepter {
@@ -72,17 +70,17 @@ resource "aws_vpc_peering_connection_options" "this" {
7270
#### route tables ####
7371

7472
resource "aws_route" "requester" {
75-
count = var.create ? length(local.requester_route_tables_ids) : 0
73+
count = var.peering_enabled ? length(local.requester_route_tables_ids) : 0
7674
route_table_id = local.requester_route_tables_ids[count.index]
7775
destination_cidr_block = data.aws_vpc.accepter.cidr_block
78-
vpc_peering_connection_id = var.create ? aws_vpc_peering_connection.this[0].id : null
76+
vpc_peering_connection_id = var.peering_enabled ? aws_vpc_peering_connection.this[0].id : null
7977
provider = aws.peer
8078
}
8179

8280
resource "aws_route" "accepter" {
83-
count = var.create ? length(local.accepter_route_tables_ids) : 0
81+
count = var.peering_enabled ? length(local.accepter_route_tables_ids) : 0
8482
route_table_id = local.accepter_route_tables_ids[count.index]
8583
destination_cidr_block = data.aws_vpc.requester.cidr_block
86-
vpc_peering_connection_id = var.create ? aws_vpc_peering_connection.this[0].id : null
84+
vpc_peering_connection_id = var.peering_enabled ? aws_vpc_peering_connection.this[0].id : null
8785
provider = aws.accepter
8886
}

modules/vpc_peering/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
output "vpc_peering_connection_id" {
22
description = "Peering connection ID"
3-
value = var.create ? aws_vpc_peering_connection.this[0].id : null
3+
value = var.peering_enabled ? aws_vpc_peering_connection.this[0].id : null
44
}
55

66
output "vpc_peering_accept_status" {
77
description = "Status for the connection"
8-
value = var.create ? aws_vpc_peering_connection_accepter.this[0].accept_status : null
8+
value = var.peering_enabled ? aws_vpc_peering_connection_accepter.this[0].accept_status : null
99
}

modules/vpc_peering/variables.tf

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,41 @@
11
variable "accepter_vpc_id" {
22
type = string
3-
description = "The ID of Acceptor VPC"
3+
description = "Specify the unique identifier of the VPC that will act as the Acceptor in the VPC peering connection."
44
default = ""
55
}
66

77
variable "accepter_vpc_region" {
88
type = string
9-
description = "The region of Acceptor VPC"
9+
description = "Provide the AWS region where the Acceptor VPC is located. This helps in identifying the correct region for establishing the VPC peering connection."
1010
default = ""
1111
}
1212

1313
variable "requester_vpc_id" {
1414
type = string
15-
description = "The ID of Requester VPC"
15+
description = "Specify the unique identifier of the VPC that will act as the Reqester in the VPC peering connection."
1616
default = ""
1717
}
1818

1919
variable "requester_vpc_region" {
2020
type = string
21-
description = "The region Requester VPC"
21+
description = "Specify the AWS region where the Requester VPC resides. It ensures the correct region is used for setting up the VPC peering."
2222
default = ""
2323
}
2424

25-
26-
variable "create" {
27-
description = "Set it to true to create VPC peering"
28-
type = bool
29-
default = true
25+
variable "requester_name" {
26+
type = string
27+
description = "Provide a descriptive name or label for the VPC Requester. This helps identify and differentiate the Requester VPC in the peering connection."
28+
default = ""
3029
}
3130

32-
variable "name" {
33-
description = "Name for the VPC peering"
31+
variable "accepter_name" {
3432
type = string
33+
description = "Assign a meaningful name or label to the VPC Accepter. This aids in distinguishing the Accepter VPC within the VPC peering connection."
3534
default = ""
3635
}
36+
37+
variable "peering_enabled" {
38+
type = bool
39+
description = "Set this variable to true if you want to create the VPC peering connection. Set it to false if you want to skip the creation process."
40+
default = true
41+
}

0 commit comments

Comments
 (0)