generated from geekcell/terraform-aws-module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from geekcell/feat/terraform-tests
- Loading branch information
Showing
4 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
variables { | ||
name = "test-budget" | ||
recipients = ["[email protected]"] | ||
|
||
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%." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = { | ||
|