Skip to content

Commit 0b9b57a

Browse files
committed
Allow computed gateway IDs
1 parent bdf3d3f commit 0b9b57a

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Creates a site-to-site VPN connection intended to terminate to a FortiGate firew
6060
| <a name="input_tunnel2_psk"></a> [tunnel2\_psk](#input\_tunnel2\_psk) | Specify a Tunnel 2 PSK explicitly (optional) | `string` | `""` | no |
6161
| <a name="input_tunnel2_psk_version"></a> [tunnel2\_psk\_version](#input\_tunnel2\_psk\_version) | Version to use for PSK (increment to generate a new PSK) | `number` | `1` | no |
6262
| <a name="input_use_secrets_manager"></a> [use\_secrets\_manager](#input\_use\_secrets\_manager) | Use Secrets Manager to store/manage PSKs | `bool` | `true` | no |
63+
| <a name="input_use_tgw"></a> [use\_tgw](#input\_use\_tgw) | Set to true if attaching the VPN to a Transit Gateway | `bool` | `false` | no |
6364
| <a name="input_vgw_id"></a> [vgw\_id](#input\_vgw\_id) | Virtual Private Gateway to attach VPN to (required if `transit_gateway_id` not set) | `string` | `null` | no |
6465
| <a name="input_wan_interface"></a> [wan\_interface](#input\_wan\_interface) | WAN interface to use in fortigate config template | `string` | `"wan1"` | no |
6566

main.tf

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
data "aws_vpn_gateway" "this" {
2-
count = var.vgw_id == null ? 0 : 1
2+
count = var.use_tgw ? 0 : 1
33
id = var.vgw_id
44
}
55

66
data "aws_ec2_transit_gateway" "this" {
7-
count = var.transit_gateway_id == null ? 0 : 1
7+
count = var.use_tgw ? 1 : 0
88
id = var.transit_gateway_id
99
}
1010

@@ -40,8 +40,11 @@ locals {
4040
"Name" = "${var.account_name}<=>${var.customer_name}"
4141
}
4242
)
43+
44+
tgw_id = var.use_tgw ? var.transit_gateway_id : null
4345
tunnel1_psk = var.use_secrets_manager ? module.psk1.secret : var.tunnel1_psk
4446
tunnel2_psk = var.use_secrets_manager ? module.psk2.secret : var.tunnel2_psk
47+
vgw_id = var.use_tgw ? null : var.vgw_id
4548

4649
# compute aws bgp asn
4750
amazon_bgp_asn = try(data.aws_ec2_transit_gateway.this[0].amazon_side_asn, data.aws_vpn_gateway.this[0].amazon_side_asn)
@@ -57,13 +60,13 @@ resource "aws_customer_gateway" "this" {
5760
resource "aws_vpn_connection" "this" {
5861
customer_gateway_id = aws_customer_gateway.this.id
5962
tags = local.tags_with_name
60-
transit_gateway_id = var.transit_gateway_id
63+
transit_gateway_id = local.tgw_id
6164
tunnel1_inside_cidr = var.tunnel1_inside_cidr
6265
tunnel1_preshared_key = local.tunnel1_psk
6366
tunnel2_inside_cidr = var.tunnel2_inside_cidr
6467
tunnel2_preshared_key = local.tunnel2_psk
6568
type = aws_customer_gateway.this.type
66-
vpn_gateway_id = var.vgw_id
69+
vpn_gateway_id = local.vgw_id
6770
}
6871

6972
resource "local_file" "this" {

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,9 @@ variable "wan_interface" {
9595
description = "WAN interface to use in fortigate config template"
9696
type = string
9797
}
98+
99+
variable "use_tgw" {
100+
default = false
101+
description = "Set to true if attaching the VPN to a Transit Gateway"
102+
type = bool
103+
}

0 commit comments

Comments
 (0)