Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: transit_gateway_enabled is true resource routetable propagation null value #51

Merged
merged 5 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ locals {
transit_gateway_enabled = local.enabled && var.transit_gateway_enabled

transit_gateway_attachment_id = join("", aws_vpn_connection.default[*].transit_gateway_attachment_id)
vpn_gateway_id = join("", aws_vpn_gateway.default[*].id)
vpn_gateway_id = one(aws_vpn_gateway.default[*].id)
customer_gateway_id = join("", aws_customer_gateway.default[*].id)
vpn_connection_id = join("", aws_vpn_connection.default[*].id)
}
Expand All @@ -20,11 +20,12 @@ resource "aws_vpn_gateway" "default" {

# https://www.terraform.io/docs/providers/aws/r/customer_gateway.html
resource "aws_customer_gateway" "default" {
count = local.enabled && var.customer_gateway_ip_address != null ? 1 : 0
bgp_asn = var.customer_gateway_bgp_asn
ip_address = var.customer_gateway_ip_address
type = "ipsec.1"
tags = module.this.tags
count = local.enabled && var.customer_gateway_ip_address != null ? 1 : 0
device_name = module.this.id
bgp_asn = var.customer_gateway_bgp_asn
ip_address = var.customer_gateway_ip_address
type = "ipsec.1"
tags = module.this.tags
}

module "logs" {
Expand Down Expand Up @@ -96,7 +97,7 @@ resource "aws_vpn_connection" "default" {

# https://www.terraform.io/docs/providers/aws/r/vpn_gateway_route_propagation.html
resource "aws_vpn_gateway_route_propagation" "default" {
count = local.enabled ? length(var.route_table_ids) : 0
count = local.enabled && !var.transit_gateway_enabled ? length(var.route_table_ids) : 0
vpn_gateway_id = local.vpn_gateway_id
route_table_id = element(var.route_table_ids, count.index)
}
Expand Down
21 changes: 19 additions & 2 deletions test/src/examples_complete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package test

import (
"os"
"os/exec"
"strings"
"testing"

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

func detectPlatform() string {
cmd := exec.Command("terraform", "--version")
out, _ := cmd.CombinedOutput()
platform := ""
if strings.Contains(string(out), "Terraform") {
platform = "tf"
} else if strings.Contains(string(out), "OpenTofu") {
platform = "tofu"
} else {
platform = "unknown"
}
return platform
}

// Test the Terraform module in examples/complete using Terratest.
func TestExamplesComplete(t *testing.T) {
t.Parallel()
randID := strings.ToLower(random.UniqueId())
attributes := []string{randID}
platform := detectPlatform()
attributes := []string{randID, platform}

rootFolder := "../../"
terraformFolderRelativeToRoot := "examples/complete"
Expand Down Expand Up @@ -61,7 +77,8 @@ func TestExamplesComplete(t *testing.T) {
func TestExamplesCompleteDisabled(t *testing.T) {
t.Parallel()
randID := strings.ToLower(random.UniqueId())
attributes := []string{randID}
platform := detectPlatform()
attributes := []string{randID, platform}

rootFolder := "../../"
terraformFolderRelativeToRoot := "examples/complete"
Expand Down