How infra-tester Works Internally¶
infra-tester uses terratest internally to run Terraform tests. Once infra-tester parses the test configuration, for each test:
- If at least one plan assertion is found, it'll run
terraform plan
with the input variables if defined. - It then runs all the assertions under the plan step.
- If any of the plan step assertions fails, it skips the apply assertions for the test. This can be considered a "fail fast" mechanism to prevent unnecessary cost and time wastage when the plan tests have failed.
- If all the plan assertions were successful, it then proceeds to apply assertions.
- infra-tester runs
terraform plan
with the input variables if defined. Note that a destroy won't be called before running the apply unlesswith_clean_state
is set to true. This is for efficiency reasons, seetest_plan.tests.with_clean_state
. - Once all the tests are run, infra-tester proceeds to destroy all resources as a final cleanup procedure.
%%{init: {'theme':'neutral'}}%%
flowchart TB
subgraph TestPlan[<b>Test Plan</b>]
direction TB
subgraph Test1[<b>Test 1</b>]
direction LR
Plan1(Plan\nResource\nCreation) --> AssertP1(Plan\nAssertions\n1..N<sub>1</sub>) --> Create1(Resource\nCreation) --> Assert1(Assertions\n1..M<sub>1</sub>)
end
subgraph Test2[<b>Test 2</b>]
direction LR
Plan2(Plan\nResource\nModification) --> AssertP2(Plan\nAssertions\n1..N<sub>2</sub>) --> Create2(Resource\nModification) --> Assert2(Assertions\n1..M<sub>2</sub>)
end
subgraph TestN[<b>Test N</b>]
direction LR
PlanN(Plan\nResource\nModification) --> AssertPN(Plan\nAssertions\n1..N<sub>k</sub>) --> CreateN(Resource\nModification) --> AssertN(Assertions\n1..M<sub>k</sub>)
end
Test1 --> Test2
Test2 --> dots((...))
dots((...)) --> TestN
end
Start:::term --> Test1
TestN --> destroy(Destroy\nResources) --> End:::term