Skip to content

Commit

Permalink
add terraform test
Browse files Browse the repository at this point in the history
  • Loading branch information
janvt committed Oct 25, 2023
1 parent c8b5d29 commit 81c91fc
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 1 deletion.
57 changes: 57 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
###############
## Run tests ##
###############

#
# Documentation:
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
#

name: Test
on:
pull_request:
push:
branches: [ main ]

##########################
# Prevent duplicate jobs #
##########################
concurrency:
group: ${{ github.repository }}
cancel-in-progress: false

permissions:
id-token: write
contents: read

###############
# Run the job #
###############
jobs:
terraform-test:
name: Terraform Test
runs-on: ubuntu-latest
steps:
############################
# Checkout the source code #
############################
- name: Checkout
uses: actions/checkout@v3

#############################
# Configure AWS credentials #
#############################
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: arn:aws:iam::${{ vars.AWS_TESTING_ACCOUNT_ID }}:role/${{ vars.AWS_TESTING_ROLE }}
aws-region: ${{ vars.AWS_TESTING_REGION }}
mask-aws-account-id: false

#############
# Run tests #
#############
- name: Run Tests
timeout-minutes: 30
run: terraform init && terraform test
Empty file removed test/.gitignore
Empty file.
68 changes: 68 additions & 0 deletions tests/basic.tftest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
variables {

Check failure on line 1 in tests/basic.tftest.hcl

View workflow job for this annotation

GitHub Actions / FMT

File is not in canonical format (terraform fmt)
name = "test-budget"
recipients = ["tommy.tester@test.com"]

budgets = [{
name = "test-budget-1",

budget_type = "COST"
limit_amount = 50
limit_unit = "EUR"

time_period_start = "2023-01-01_00:00"
time_period_end = "2087-06-15_00:00"
time_unit = "MONTHLY"

notification = {
comparison_operator = "GREATER_THAN"
threshold = "69"
threshold_type = "PERCENTAGE"
notification_type = "FORECASTED"
}
}]
}

run "basic_budget" {
command = plan

assert {
condition = length(aws_budgets_budget.main) == 1
error_message = "Expected one budget to be created."
}

assert {
condition = contains(keys(aws_budgets_budget.main), "test-budget-1")
error_message = "Expected test-budget-1 to exist."
}

assert {
condition = length(aws_budgets_budget.main["test-budget-1"].notification) == 1
error_message = "Expected test-budget-1 to have one notification."
}

assert {
condition = alltrue([
for n in aws_budgets_budget.main["test-budget-1"].notification : can(length(n.subscriber_email_addresses) == 1)
])

error_message = "Expected test-budget-1 notification to have one recipient."
}

assert {
condition = aws_budgets_budget.main["test-budget-1"].limit_amount == "50"
error_message = "Expected test-budget-1 limit amount to be 50."
}

assert {
condition = aws_budgets_budget.main["test-budget-1"].limit_unit == "EUR"
error_message = "Expected test-budget-1 limit unit to be EUR."
}

assert {
condition = alltrue([
for n in aws_budgets_budget.main["test-budget-1"].notification : can(n.threshold == 69)
])

error_message = "Expected test-budget-1 threshold to be 69%."
}
}
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = ">= 1.3"
required_version = ">= 1.6"

required_providers {
aws = {
Expand Down

0 comments on commit 81c91fc

Please sign in to comment.