You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to be able to exercise the module under test with multiple distinct executions, all within a single tftest.hcl file. For example, consider the following:
./tests/multiple_tests.tftest.hcl:
# this setup module may take a significant period of time# to launch, but can be used by multiple instances of the# module under testrun"setup_backend" {
module {
source="./tests/modules/setup"
}
variables {
cluster_members=4
}
}
run"first" {
variables {
input1="first"
}
assert { ... }
}
run"second" {
variables {
input1="second"
}
assert { ... }
}
In the above scenario, the "second" run block modifies the "first" run block's state. While that is desirable in many circumstances, I would like to be able to instruct the second run block to use it's own state configuration, rather than using the same as from the "first" run block. If I could tell subsequent run blocks to use their own state configuration then I could write a variety of test cases which all utilized the resources created by the "setup_backend" module.
Another use case is when module invocations can be chained, such that the output of one module is used as input for another. This requires that tests maintain separate state for each.
Attempted Solutions
I can work-around this limitation with the following, less than ideal solution.
> mkdir -p tests/modules
>cd tests/modules
# create a symlink to the module under test> ln -s ../../ loopback01
> ln -s ../../ loopback02
Then, I can modify the original config, like so:
./tests/multiple_tests.tftest.hcl:
# this setup module may take a significant period of time# to launch, but can be used by multiple instances of the# module under testrun"setup_backend" {
module {
source="./tests/modules/setup"
}
variables {
cluster_members=4
}
}
run"first" {
variables {
input1="first"
}
assert { ... }
}
run"second" {
module {
source="./tests/modules/loopback01"
}
variables {
input1="second"
}
assert { ... }
}
run"third" {
module {
source="./tests/modules/loopback02"
}
variables {
input1="third"
}
assert { ... }
}
This does work, but it requires creating a symlink back to the module root directory for each individual state configuration that is needed. It isn't difficult, but it clutters the module repository unnecessarily.
Proposal
Add a state_alias or other keyword to the terraform test syntax to allow something like:
./tests/multiple_tests.tftest.hcl:
# this setup module may take a significant period of time# to launch, but can be used by multiple instances of the# module under testrun"setup_backend" {
module {
source="./tests/modules/setup"
}
variables {
cluster_members=4
}
}
run"first" {
variables {
input1="first"
}
assert { ... }
}
run"second" {
state_alias="second"variables {
input1="second"
}
assert { ... }
}
run"third" {
state_alias="third"variables {
input1="third"
}
assert { ... }
}
Where each run block that shared the same state_alias value would operate in the same way as the normal run block but with its own dedicated state.
References
No response
The text was updated successfully, but these errors were encountered:
Thanks for this feature request! If you are viewing this issue and would like to indicate your interest, please use the 👍 reaction on the issue description to upvote this issue. We also welcome additional use case descriptions. Thanks again!
I'm having another use case for a state alias in run blocks :
I'm trying to make a breaking_change terraform test.
The purpose of this test is to make the test fail if the module upgrade from one version to another is not possible without manual code or state alteration.
I need to :
Run a first apply run using a specified version of the module
Run a second apply run using new module code proposal
Terraform Version
Use Cases
I would like to be able to exercise the module under test with multiple distinct executions, all within a single
tftest.hcl
file. For example, consider the following:./tests/multiple_tests.tftest.hcl:
In the above scenario, the "second" run block modifies the "first" run block's state. While that is desirable in many circumstances, I would like to be able to instruct the second run block to use it's own state configuration, rather than using the same as from the "first" run block. If I could tell subsequent run blocks to use their own state configuration then I could write a variety of test cases which all utilized the resources created by the "setup_backend" module.
Another use case is when module invocations can be chained, such that the output of one module is used as input for another. This requires that tests maintain separate state for each.
Attempted Solutions
I can work-around this limitation with the following, less than ideal solution.
Then, I can modify the original config, like so:
./tests/multiple_tests.tftest.hcl:
This does work, but it requires creating a symlink back to the module root directory for each individual state configuration that is needed. It isn't difficult, but it clutters the module repository unnecessarily.
Proposal
Add a
state_alias
or other keyword to the terraform test syntax to allow something like:./tests/multiple_tests.tftest.hcl:
Where each run block that shared the same
state_alias
value would operate in the same way as the normal run block but with its own dedicated state.References
No response
The text was updated successfully, but these errors were encountered: