-
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.
AB#76 tests: add test for safe to apply global actions
- Loading branch information
1 parent
228f628
commit 1c836cf
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
e2e-tests/suites/safe_to_apply/global_actions/artifacts/.terraapprove.yaml
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,4 @@ | ||
global: | ||
safeToApply: | ||
allResources: | ||
actions: [ "CREATE" ] |
13 changes: 13 additions & 0 deletions
13
e2e-tests/suites/safe_to_apply/global_actions/artifacts/main.tf
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,13 @@ | ||
resource "null_resource" "safe_tp_apply" { | ||
triggers = { | ||
always_run = timestamp() | ||
} | ||
} | ||
|
||
terraform { | ||
required_providers { | ||
null = { | ||
source = "hashicorp/null" | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
e2e-tests/suites/safe_to_apply/global_actions/global_actions.bats
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,43 @@ | ||
setup() { | ||
# Copy files to a read/write directory. This is necessary because | ||
# Terraform generates a lock file in the working directory. | ||
export ORIGINAL_DIR=$(pwd) | ||
cp -r "$BATS_TEST_DIRNAME/artifacts/." $BATS_TEST_TMPDIR | ||
cd $BATS_TEST_TMPDIR | ||
terraform init > /dev/null | ||
} | ||
|
||
teardown() { | ||
cd $ORIGINAL_DIR | ||
|
||
# Print additional information when a test fails | ||
echo "$status" | ||
echo "$output" | ||
} | ||
|
||
@test "should return 1 if the plan contains resources that are not safe to apply" { | ||
# Given | ||
terraform apply -auto-approve > /dev/null | ||
|
||
# A second apply should trigger the re-creation of the resource | ||
terraform plan -out test.tfplan > /dev/null | ||
terraform show -json test.tfplan > ${BATS_TEST_TMPDIR}/test.tfplan.json | ||
|
||
# When | ||
run "/code/terraapprove" "." "./test.tfplan.json" "--reverse" | ||
|
||
# Expect | ||
[ "$status" -eq 1 ] | ||
} | ||
|
||
@test "should return 0 if the only resource in the plan is safe to apply" { | ||
# Given | ||
terraform plan -out test.tfplan > /dev/null | ||
terraform show -json test.tfplan > ${BATS_TEST_TMPDIR}/test.tfplan.json | ||
|
||
# When | ||
run "/code/terraapprove" "." "./test.tfplan.json" | ||
|
||
# Expect | ||
[ "$status" -eq 0 ] | ||
} |