Skip to content

Commit 5bd21bd

Browse files
authored
Added Customer Gateway resource (#360)
1 parent bd51e9f commit 5bd21bd

File tree

8 files changed

+71
-2
lines changed

8 files changed

+71
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ Sometimes it is handy to have public access to Redshift clusters (for example if
256256
| create\_redshift\_subnet\_group | Controls if redshift subnet group should be created | bool | `"true"` | no |
257257
| create\_redshift\_subnet\_route\_table | Controls if separate route table for redshift should be created | bool | `"false"` | no |
258258
| create\_vpc | Controls if VPC should be created (it affects almost all resources) | bool | `"true"` | no |
259+
| customer\_gateway\_tags | Additional tags for the Customer Gateway | map(string) | `{}` | no |
260+
| customer\_gateways | Maps of Customer Gateway's attributes (BGP ASN and Gateway's Internet-routable external IP address) | map(map(any)) | `{}` | no |
259261
| database\_acl\_tags | Additional tags for the database subnets network ACL | map(string) | `{}` | no |
260262
| database\_dedicated\_network\_acl | Whether to use dedicated network ACL (not default) and custom rules for database subnets | bool | `"false"` | no |
261263
| database\_inbound\_acl\_rules | Database subnets inbound network ACL rules | list(map(string)) | `[ { "cidr_block": "0.0.0.0/0", "from_port": 0, "protocol": "-1", "rule_action": "allow", "rule_number": 100, "to_port": 0 } ]` | no |
@@ -506,6 +508,7 @@ Sometimes it is handy to have public access to Redshift clusters (for example if
506508
| Name | Description |
507509
|------|-------------|
508510
| azs | A list of availability zones specified as argument to this module |
511+
| cgw\_ids | List of IDs of Customer Gateway |
509512
| database\_network\_acl\_id | ID of the database network ACL |
510513
| database\_route\_table\_ids | List of IDs of database route tables |
511514
| database\_subnet\_arns | List of ARNs of database subnets |
@@ -564,6 +567,7 @@ Sometimes it is handy to have public access to Redshift clusters (for example if
564567
| redshift\_subnets | List of IDs of redshift subnets |
565568
| redshift\_subnets\_cidr\_blocks | List of cidr_blocks of redshift subnets |
566569
| redshift\_subnets\_ipv6\_cidr\_blocks | List of IPv6 cidr_blocks of redshift subnets in an IPv6 enabled VPC |
570+
| this\_customer\_gateway | Map of Customer Gateway attributes |
567571
| vgw\_id | The ID of the VPN Gateway |
568572
| vpc\_arn | The ARN of the VPC |
569573
| vpc\_cidr\_block | The CIDR block of the VPC |

examples/complete-vpc/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ Note that this example may create resources which can cost money (AWS Elastic IP
2121

2222
| Name | Description |
2323
|------|-------------|
24+
| cgw\_ids | List of IDs of Customer Gateway |
2425
| database\_subnets | List of IDs of database subnets |
2526
| elasticache\_subnets | List of IDs of elasticache subnets |
2627
| intra\_subnets | List of IDs of intra subnets |
2728
| nat\_public\_ips | List of public Elastic IPs created for AWS NAT Gateway |
2829
| private\_subnets | List of IDs of private subnets |
2930
| public\_subnets | List of IDs of public subnets |
3031
| redshift\_subnets | List of IDs of redshift subnets |
32+
| this\_customer\_gateway | Map of Customer Gateway attributes |
3133
| vpc\_endpoint\_ssm\_dns\_entry | The DNS entries for the VPC Endpoint for SSM. |
3234
| vpc\_endpoint\_ssm\_id | The ID of VPC endpoint for SSM |
3335
| vpc\_endpoint\_ssm\_network\_interface\_ids | One or more network interfaces for the VPC Endpoint for SSM. |

examples/complete-vpc/main.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ module "vpc" {
3333
enable_nat_gateway = true
3434
single_nat_gateway = true
3535

36+
customer_gateways = {
37+
IP1 = {
38+
bgp_asn = 65112
39+
ip_address = "1.2.3.4"
40+
},
41+
IP2 = {
42+
bgp_asn = 65112
43+
ip_address = "5.6.7.8"
44+
}
45+
}
46+
3647
enable_vpn_gateway = true
3748

3849
enable_dhcp_options = true

examples/complete-vpc/outputs.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ output "vpc_endpoint_ssm_dns_entry" {
5757
value = module.vpc.vpc_endpoint_ssm_dns_entry
5858
}
5959

60+
# Customer Gateway
61+
output "cgw_ids" {
62+
description = "List of IDs of Customer Gateway"
63+
value = module.vpc.cgw_ids
64+
}
65+
66+
output "this_customer_gateway" {
67+
description = "Map of Customer Gateway attributes"
68+
value = module.vpc.this_customer_gateway
69+
}
70+
6071
//
6172
//# VPC endpoints
6273
//output "vpc_endpoint_ec2_id" {

main.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,25 @@ resource "aws_route_table_association" "public" {
989989
route_table_id = aws_route_table.public[0].id
990990
}
991991

992+
####################
993+
# Customer Gateways
994+
####################
995+
resource "aws_customer_gateway" "this" {
996+
for_each = var.customer_gateways
997+
998+
bgp_asn = each.value["bgp_asn"]
999+
ip_address = each.value["ip_address"]
1000+
type = "ipsec.1"
1001+
1002+
tags = merge(
1003+
{
1004+
Name = format("%s-%s", var.name, each.key)
1005+
},
1006+
var.tags,
1007+
var.customer_gateway_tags,
1008+
)
1009+
}
1010+
9921011
##############
9931012
# VPN Gateway
9941013
##############

outputs.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,16 @@ output "egress_only_internet_gateway_id" {
263263
value = concat(aws_egress_only_internet_gateway.this.*.id, [""])[0]
264264
}
265265

266+
output "cgw_ids" {
267+
description = "List of IDs of Customer Gateway"
268+
value = [for k, v in aws_customer_gateway.this : v.id]
269+
}
270+
271+
output "this_customer_gateway" {
272+
description = "Map of Customer Gateway attributes"
273+
value = aws_customer_gateway.this
274+
}
275+
266276
output "vgw_id" {
267277
description = "The ID of the VPN Gateway"
268278
value = concat(

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,12 @@ variable "map_public_ip_on_launch" {
13051305
default = true
13061306
}
13071307

1308+
variable "customer_gateways" {
1309+
description = "Maps of Customer Gateway's attributes (BGP ASN and Gateway's Internet-routable external IP address)"
1310+
type = map(map(any))
1311+
default = {}
1312+
}
1313+
13081314
variable "enable_vpn_gateway" {
13091315
description = "Should be true if you want to create a new VPN Gateway resource and attach it to the VPC"
13101316
type = bool
@@ -1489,6 +1495,12 @@ variable "nat_eip_tags" {
14891495
default = {}
14901496
}
14911497

1498+
variable "customer_gateway_tags" {
1499+
description = "Additional tags for the Customer Gateway"
1500+
type = map(string)
1501+
default = {}
1502+
}
1503+
14921504
variable "vpn_gateway_tags" {
14931505
description = "Additional tags for the VPN gateway"
14941506
type = map(string)

vpc-endpoints.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ resource "aws_vpc_endpoint" "efs" {
971971
count = var.create_vpc && var.enable_efs_endpoint ? 1 : 0
972972

973973
vpc_id = local.vpc_id
974-
service_name = data.aws_vpc_endpoint_service.efs.service_name
974+
service_name = data.aws_vpc_endpoint_service.efs[0].service_name
975975
vpc_endpoint_type = "Interface"
976976

977977
security_group_ids = var.efs_endpoint_security_group_ids
@@ -994,7 +994,7 @@ resource "aws_vpc_endpoint" "cloud_directory" {
994994
count = var.create_vpc && var.enable_cloud_directory_endpoint ? 1 : 0
995995

996996
vpc_id = local.vpc_id
997-
service_name = data.aws_vpc_endpoint_service.cloud_directory.service_name
997+
service_name = data.aws_vpc_endpoint_service.cloud_directory[0].service_name
998998
vpc_endpoint_type = "Interface"
999999

10001000
security_group_ids = var.cloud_directory_endpoint_security_group_ids

0 commit comments

Comments
 (0)