From c7b4aac2ef41c881e5e43bdfb44c45c0dbacb2d4 Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Thu, 18 Apr 2024 16:16:17 -0600 Subject: [PATCH 1/4] add test for alb module --- test/alb.tf | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/alb.tf diff --git a/test/alb.tf b/test/alb.tf new file mode 100644 index 0000000..af55316 --- /dev/null +++ b/test/alb.tf @@ -0,0 +1,40 @@ +# Using required inputs +module "alb-test" { + source = "../aws/alb" + + app_name = "test_name1" + app_env = "test_env1" + vpc_id = "vpc-0123abcd" + security_groups = ["sg-1234bcde"] + subnets = ["subnet-2345cdef"] + certificate_arn = "arn:aws:acm:us-east-1:0123456789012:certificate/44f68dac-d9f1-4d2f-94e6-a8231965f8ed" +} + +# Using required and optional inputs +module "alb-test2" { + source = "../aws/alb" + + app_name = "test_name1" + app_env = "test_env1" + vpc_id = "vpc-0123abcd" + security_groups = ["sg-1234bcde"] + subnets = ["subnet-2345cdef"] + certificate_arn = "arn:aws:acm:us-east-1:0123456789012:certificate/44f68dac-d9f1-4d2f-94e6-a8231965f8ed" + port = "80" + protocol = "HTTP" + alb_name = "alb-test2" + internal = false + ssl_policy = "ELBSecurityPolicy-2016-08" + tg_name = "tg-test2" + health_check_interval = "30" + health_check_path = "/" + health_check_port = "traffic-port" + health_check_protocol = "HTTP" + health_check_timeout = "5" + healthy_threshold = "5" + unhealthy_threshold = "2" + health_check_status_codes = "200" + idle_timeout = "60" + load_balancer_type = "application" + enable_ipv6 = true +} From a270758143bc81c1f6566425a95aebad9c8194c8 Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Thu, 18 Apr 2024 16:17:44 -0600 Subject: [PATCH 2/4] add a test script for convenience --- .github/workflows/terraform.yml | 14 +++----------- test.sh | 11 +++++++++++ 2 files changed, 14 insertions(+), 11 deletions(-) create mode 100755 test.sh diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index d37e973..7b555b3 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -31,14 +31,6 @@ jobs: - name: Setup Terraform uses: hashicorp/setup-terraform@v2 - # Checks that all Terraform configuration files adhere to a canonical format - - name: Terraform Format - run: terraform fmt -check -diff -recursive - - # Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc. - - name: Terraform Init - run: terraform -chdir=test init - - # Validate the files, referring only to the configuration and not accessing any remote services - - name: Terraform Validate - run: terraform -chdir=test validate + # Run terraform tests + - name: Terraform tests + run: ./test.sh diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..fcb7439 --- /dev/null +++ b/test.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env sh + +# exit if any step fails +set -e + +# echo command lines as they are run +set -x + +terraform fmt -check -diff -recursive +terraform -chdir=test init +terraform -chdir=test validate From 8fc5beec648cdb61c720aa9c6cccb9076af7585c Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Thu, 18 Apr 2024 16:18:17 -0600 Subject: [PATCH 3/4] fix syntax error in alb module --- aws/alb/vars.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/alb/vars.tf b/aws/alb/vars.tf index f7ccc26..edf6e39 100644 --- a/aws/alb/vars.tf +++ b/aws/alb/vars.tf @@ -101,7 +101,7 @@ variable "load_balancer_type" { } variable "enable_ipv6" { - description = "Set to `true` to enable IPv6. Changes the ALB `ip_address_type` to `"dualstack"`." + description = "Set to `true` to enable IPv6. Changes the ALB `ip_address_type` to `\"dualstack\"`." type = bool default = false } From d848ba0a30cba8d6ee8baace37d8ffd2cc53dfe7 Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Thu, 18 Apr 2024 16:37:24 -0600 Subject: [PATCH 4/4] use latest versions of checkout and setup-terraform actions --- .github/workflows/terraform.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 7b555b3..32a75d9 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -25,11 +25,11 @@ jobs: steps: # Checkout the repository to the GitHub Actions runner - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 # Install the latest version of Terraform CLI - name: Setup Terraform - uses: hashicorp/setup-terraform@v2 + uses: hashicorp/setup-terraform@v3 # Run terraform tests - name: Terraform tests