From a6b41826aea66870e9a6fd460d2afc8bfd159851 Mon Sep 17 00:00:00 2001 From: Musthaq101 Date: Tue, 31 Dec 2024 17:55:29 +0530 Subject: [PATCH 1/8] Replaces it with the updated list-compatible syntax --- src/modules/postgresql-user/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/postgresql-user/main.tf b/src/modules/postgresql-user/main.tf index 0cb4c2b..47424ce 100644 --- a/src/modules/postgresql-user/main.tf +++ b/src/modules/postgresql-user/main.tf @@ -2,7 +2,7 @@ locals { enabled = module.this.enabled db_user = length(var.db_user) > 0 ? var.db_user : var.service_name - db_password = length(var.db_password) > 0 ? var.db_password : join("", random_password.db_password.*.result) + db_password = length(var.db_password) > 0 ? var.db_password : join("", random_password.db_password[*].result) save_password_in_ssm = local.enabled && var.save_password_in_ssm @@ -45,7 +45,7 @@ resource "postgresql_role" "default" { # Apply the configured grants to the user resource "postgresql_grant" "default" { count = local.enabled ? length(var.grants) : 0 - role = join("", postgresql_role.default.*.name) + role = join("", postgresql_role.default[*].name) database = var.grants[count.index].db schema = var.grants[count.index].schema object_type = var.grants[count.index].object_type From 084111d72d1118fcdec6893b91c32d2d859dcdd3 Mon Sep 17 00:00:00 2001 From: Musthaq101 Date: Tue, 31 Dec 2024 18:53:27 +0530 Subject: [PATCH 2/8] local testing of terratest --- src/outputs.tf | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/outputs.tf b/src/outputs.tf index c2a4080..df0f086 100644 --- a/src/outputs.tf +++ b/src/outputs.tf @@ -17,3 +17,9 @@ output "additional_grants" { value = keys(module.additional_grants) description = "Additional grants" } + +# Add a Hello World output for Terratest +output "hello_world" { + value = "Hello, Terratest!" + description = "A simple Hello World output for Terratest validation." +} \ No newline at end of file From 41bec5e3d66957ba49a34438bbb8900cbdb05425 Mon Sep 17 00:00:00 2001 From: Musthaq101 Date: Tue, 31 Dec 2024 18:59:10 +0530 Subject: [PATCH 3/8] local testing of terratest --- .github/workflows/terratest.yml | 32 ++++++++++++++++++++++++++++++++ test/hello_world_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 .github/workflows/terratest.yml create mode 100644 test/hello_world_test.go diff --git a/.github/workflows/terratest.yml b/.github/workflows/terratest.yml new file mode 100644 index 0000000..0f347e2 --- /dev/null +++ b/.github/workflows/terratest.yml @@ -0,0 +1,32 @@ +name: Terratest + +on: + pull_request: + branches: + - main + push: + branches: + - main + +jobs: + terratest: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.20' + + - name: Install dependencies + run: | + cd test + go mod tidy + + - name: Run Terratest + run: | + cd test + go test -v \ No newline at end of file diff --git a/test/hello_world_test.go b/test/hello_world_test.go new file mode 100644 index 0000000..03c0e31 --- /dev/null +++ b/test/hello_world_test.go @@ -0,0 +1,29 @@ +package test + +import ( + "testing" + + "github.com/gruntwork-io/terratest/modules/terraform" + "github.com/stretchr/testify/assert" +) + +func TestHelloWorld(t *testing.T) { + t.Parallel() + + // Define Terraform options + terraformOptions := &terraform.Options{ + TerraformDir: "../", // Path to the Terraform module directory + } + + // Clean up resources at the end + defer terraform.Destroy(t, terraformOptions) + + // Initialize and apply Terraform + terraform.InitAndApply(t, terraformOptions) + + // Retrieve the "hello_world" output + helloWorldOutput := terraform.Output(t, terraformOptions, "hello_world") + + // Validate the output + assert.Equal(t, "Hello, Terratest!", helloWorldOutput, "Output does not match expected value") +} \ No newline at end of file From 7b093f3c85c25579335723102ac795955a7d7550 Mon Sep 17 00:00:00 2001 From: Musthaq101 Date: Tue, 31 Dec 2024 19:05:54 +0530 Subject: [PATCH 4/8] local testing of terratest --- src/outputs.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/outputs.tf b/src/outputs.tf index df0f086..67440dc 100644 --- a/src/outputs.tf +++ b/src/outputs.tf @@ -20,6 +20,6 @@ output "additional_grants" { # Add a Hello World output for Terratest output "hello_world" { - value = "Hello, Terratest!" + value = local.enabled ? "Hello, Terratest!" : null description = "A simple Hello World output for Terratest validation." -} \ No newline at end of file +} From 69d6fdca579f7f1265fd3ecf909e15b632f7e334 Mon Sep 17 00:00:00 2001 From: Musthaq101 Date: Tue, 31 Dec 2024 21:26:37 +0530 Subject: [PATCH 5/8] local testing of terratest --- .github/workflows/terratest.yml | 32 -------------------------------- src/outputs.tf | 5 ----- test/hello_world_test.go | 29 ----------------------------- 3 files changed, 66 deletions(-) delete mode 100644 .github/workflows/terratest.yml delete mode 100644 test/hello_world_test.go diff --git a/.github/workflows/terratest.yml b/.github/workflows/terratest.yml deleted file mode 100644 index 0f347e2..0000000 --- a/.github/workflows/terratest.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Terratest - -on: - pull_request: - branches: - - main - push: - branches: - - main - -jobs: - terratest: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.20' - - - name: Install dependencies - run: | - cd test - go mod tidy - - - name: Run Terratest - run: | - cd test - go test -v \ No newline at end of file diff --git a/src/outputs.tf b/src/outputs.tf index 67440dc..885e61f 100644 --- a/src/outputs.tf +++ b/src/outputs.tf @@ -18,8 +18,3 @@ output "additional_grants" { description = "Additional grants" } -# Add a Hello World output for Terratest -output "hello_world" { - value = local.enabled ? "Hello, Terratest!" : null - description = "A simple Hello World output for Terratest validation." -} diff --git a/test/hello_world_test.go b/test/hello_world_test.go deleted file mode 100644 index 03c0e31..0000000 --- a/test/hello_world_test.go +++ /dev/null @@ -1,29 +0,0 @@ -package test - -import ( - "testing" - - "github.com/gruntwork-io/terratest/modules/terraform" - "github.com/stretchr/testify/assert" -) - -func TestHelloWorld(t *testing.T) { - t.Parallel() - - // Define Terraform options - terraformOptions := &terraform.Options{ - TerraformDir: "../", // Path to the Terraform module directory - } - - // Clean up resources at the end - defer terraform.Destroy(t, terraformOptions) - - // Initialize and apply Terraform - terraform.InitAndApply(t, terraformOptions) - - // Retrieve the "hello_world" output - helloWorldOutput := terraform.Output(t, terraformOptions, "hello_world") - - // Validate the output - assert.Equal(t, "Hello, Terratest!", helloWorldOutput, "Output does not match expected value") -} \ No newline at end of file From c7a56be380aa279e0aaeda45a5dd0e270631f493 Mon Sep 17 00:00:00 2001 From: Musthaq101 Date: Tue, 31 Dec 2024 21:27:44 +0530 Subject: [PATCH 6/8] local testing of terratest --- src/outputs.tf | 1 - 1 file changed, 1 deletion(-) diff --git a/src/outputs.tf b/src/outputs.tf index 885e61f..c2a4080 100644 --- a/src/outputs.tf +++ b/src/outputs.tf @@ -17,4 +17,3 @@ output "additional_grants" { value = keys(module.additional_grants) description = "Additional grants" } - From 8b97c43a18d0591018d8f8e8b8a051dbc8f5bfe7 Mon Sep 17 00:00:00 2001 From: Musthaq101 Date: Thu, 2 Jan 2025 13:49:15 +0530 Subject: [PATCH 7/8] updating hello world test --- src/outputs.tf | 6 ++++++ test/hello_world_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 test/hello_world_test.go diff --git a/src/outputs.tf b/src/outputs.tf index c2a4080..6cc28f0 100644 --- a/src/outputs.tf +++ b/src/outputs.tf @@ -17,3 +17,9 @@ output "additional_grants" { value = keys(module.additional_grants) description = "Additional grants" } + +# Add a Hello World output for Terratest +output "hello_world" { + value = local.enabled ? "Hello, Terratest!" : null + description = "A simple Hello World output for Terratest validation." +} \ No newline at end of file diff --git a/test/hello_world_test.go b/test/hello_world_test.go new file mode 100644 index 0000000..03c0e31 --- /dev/null +++ b/test/hello_world_test.go @@ -0,0 +1,29 @@ +package test + +import ( + "testing" + + "github.com/gruntwork-io/terratest/modules/terraform" + "github.com/stretchr/testify/assert" +) + +func TestHelloWorld(t *testing.T) { + t.Parallel() + + // Define Terraform options + terraformOptions := &terraform.Options{ + TerraformDir: "../", // Path to the Terraform module directory + } + + // Clean up resources at the end + defer terraform.Destroy(t, terraformOptions) + + // Initialize and apply Terraform + terraform.InitAndApply(t, terraformOptions) + + // Retrieve the "hello_world" output + helloWorldOutput := terraform.Output(t, terraformOptions, "hello_world") + + // Validate the output + assert.Equal(t, "Hello, Terratest!", helloWorldOutput, "Output does not match expected value") +} \ No newline at end of file From 759b13483691ae04c88c02ccad0f3ae45d30fef1 Mon Sep 17 00:00:00 2001 From: Musthaq101 Date: Mon, 6 Jan 2025 13:01:51 +0530 Subject: [PATCH 8/8] dropping the test due to its not following the testing pattern --- src/outputs.tf | 6 ------ test/hello_world_test.go | 29 ----------------------------- 2 files changed, 35 deletions(-) delete mode 100644 test/hello_world_test.go diff --git a/src/outputs.tf b/src/outputs.tf index 6cc28f0..dc66317 100644 --- a/src/outputs.tf +++ b/src/outputs.tf @@ -16,10 +16,4 @@ output "additional_schemas" { output "additional_grants" { value = keys(module.additional_grants) description = "Additional grants" -} - -# Add a Hello World output for Terratest -output "hello_world" { - value = local.enabled ? "Hello, Terratest!" : null - description = "A simple Hello World output for Terratest validation." } \ No newline at end of file diff --git a/test/hello_world_test.go b/test/hello_world_test.go deleted file mode 100644 index 03c0e31..0000000 --- a/test/hello_world_test.go +++ /dev/null @@ -1,29 +0,0 @@ -package test - -import ( - "testing" - - "github.com/gruntwork-io/terratest/modules/terraform" - "github.com/stretchr/testify/assert" -) - -func TestHelloWorld(t *testing.T) { - t.Parallel() - - // Define Terraform options - terraformOptions := &terraform.Options{ - TerraformDir: "../", // Path to the Terraform module directory - } - - // Clean up resources at the end - defer terraform.Destroy(t, terraformOptions) - - // Initialize and apply Terraform - terraform.InitAndApply(t, terraformOptions) - - // Retrieve the "hello_world" output - helloWorldOutput := terraform.Output(t, terraformOptions, "hello_world") - - // Validate the output - assert.Equal(t, "Hello, Terratest!", helloWorldOutput, "Output does not match expected value") -} \ No newline at end of file