Skip to content

Commit d6bed57

Browse files
authored
bugfix when tgw is enabled (#51)
1 parent d4c4947 commit d6bed57

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

main.tf

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ locals {
55
transit_gateway_enabled = local.enabled && var.transit_gateway_enabled
66

77
transit_gateway_attachment_id = join("", aws_vpn_connection.default[*].transit_gateway_attachment_id)
8-
vpn_gateway_id = join("", aws_vpn_gateway.default[*].id)
8+
vpn_gateway_id = one(aws_vpn_gateway.default[*].id)
99
customer_gateway_id = join("", aws_customer_gateway.default[*].id)
1010
vpn_connection_id = join("", aws_vpn_connection.default[*].id)
1111
}
@@ -20,11 +20,12 @@ resource "aws_vpn_gateway" "default" {
2020

2121
# https://www.terraform.io/docs/providers/aws/r/customer_gateway.html
2222
resource "aws_customer_gateway" "default" {
23-
count = local.enabled && var.customer_gateway_ip_address != null ? 1 : 0
24-
bgp_asn = var.customer_gateway_bgp_asn
25-
ip_address = var.customer_gateway_ip_address
26-
type = "ipsec.1"
27-
tags = module.this.tags
23+
count = local.enabled && var.customer_gateway_ip_address != null ? 1 : 0
24+
device_name = module.this.id
25+
bgp_asn = var.customer_gateway_bgp_asn
26+
ip_address = var.customer_gateway_ip_address
27+
type = "ipsec.1"
28+
tags = module.this.tags
2829
}
2930

3031
module "logs" {
@@ -96,7 +97,7 @@ resource "aws_vpn_connection" "default" {
9697

9798
# https://www.terraform.io/docs/providers/aws/r/vpn_gateway_route_propagation.html
9899
resource "aws_vpn_gateway_route_propagation" "default" {
99-
count = local.enabled ? length(var.route_table_ids) : 0
100+
count = local.enabled && !var.transit_gateway_enabled ? length(var.route_table_ids) : 0
100101
vpn_gateway_id = local.vpn_gateway_id
101102
route_table_id = element(var.route_table_ids, count.index)
102103
}

test/src/examples_complete_test.go

+19-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package test
22

33
import (
44
"os"
5+
"os/exec"
56
"strings"
67
"testing"
78

@@ -20,11 +21,26 @@ func cleanup(t *testing.T, terraformOptions *terraform.Options, tempTestFolder s
2021
os.RemoveAll(tempTestFolder)
2122
}
2223

24+
func detectPlatform() string {
25+
cmd := exec.Command("terraform", "--version")
26+
out, _ := cmd.CombinedOutput()
27+
platform := ""
28+
if strings.Contains(string(out), "Terraform") {
29+
platform = "tf"
30+
} else if strings.Contains(string(out), "OpenTofu") {
31+
platform = "tofu"
32+
} else {
33+
platform = "unknown"
34+
}
35+
return platform
36+
}
37+
2338
// Test the Terraform module in examples/complete using Terratest.
2439
func TestExamplesComplete(t *testing.T) {
2540
t.Parallel()
2641
randID := strings.ToLower(random.UniqueId())
27-
attributes := []string{randID}
42+
platform := detectPlatform()
43+
attributes := []string{randID, platform}
2844

2945
rootFolder := "../../"
3046
terraformFolderRelativeToRoot := "examples/complete"
@@ -61,7 +77,8 @@ func TestExamplesComplete(t *testing.T) {
6177
func TestExamplesCompleteDisabled(t *testing.T) {
6278
t.Parallel()
6379
randID := strings.ToLower(random.UniqueId())
64-
attributes := []string{randID}
80+
platform := detectPlatform()
81+
attributes := []string{randID, platform}
6582

6683
rootFolder := "../../"
6784
terraformFolderRelativeToRoot := "examples/complete"

0 commit comments

Comments
 (0)