Skip to content

Commit

Permalink
Add Terraform tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hammerhead committed Oct 25, 2023
1 parent f261cf8 commit 2255bab
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/tflint.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
name: TFLint
on: [push]

jobs:
terraform_fmt:
terraform_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v2
- run: terraform fmt -check -recursive
with:
terraform_version: "1.6.2"
- name: init
run: terraform init
- name: test
working-directory: aws
run: terraform test
- name: fmt
run: terraform fmt -check -recursive

lint_aws:
runs-on: ubuntu-latest
Expand Down
46 changes: 46 additions & 0 deletions aws/tests/variables.tftest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
variables {
vpc_id = "vpc-123"
ssh_keypair = "test_keypair"
subnet_ids = ["subnet-1"]
availability_zones = ["az-1"]
}

run "no password" {
command = plan

variables {
cratedb_password = null
}
}

run "provided password" {
command = plan

variables {
cratedb_password = "zie6aeya9ooMeey0yai5"
}
}

run "password with double dollar signs" {
command = plan

variables {
cratedb_password = "ab$$cd"
}

expect_failures = [
var.cratedb_password,
]
}

run "password with double quote" {
command = plan

variables {
cratedb_password = "ab\"cd"
}

expect_failures = [
var.cratedb_password,
]
}
2 changes: 1 addition & 1 deletion aws/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ variable "cratedb_password" {
sensitive = true
description = "The password to use for the CrateDB database user. If null, a random password will be assigned."
validation {
condition = var.cratedb_password == null || (!strcontains(var.cratedb_password, "$$") && !strcontains(var.cratedb_password, "\""))
condition = var.cratedb_password == null || (!try(strcontains(var.cratedb_password, "$$"), false) && !try(strcontains(var.cratedb_password, "\""), false))
error_message = "The CrateDB password must not contain any of the following character sequences: $$, \""
}
}
Expand Down

0 comments on commit 2255bab

Please sign in to comment.