Skip to content

Replaces it with the updated list-compatible syntax #10

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

Merged
Show file tree
Hide file tree
Changes from 3 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
32 changes: 32 additions & 0 deletions .github/workflows/terratest.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions src/modules/postgresql-user/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
29 changes: 29 additions & 0 deletions test/hello_world_test.go
Original file line number Diff line number Diff line change
@@ -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")
}