-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Description
Terraform Version
1.14.1Use Cases
While the ability to have tests inherit state from each other is useful, my team has found that the majority of tests we write do not need any state inheritance, and thus can be run in parallel. Right now it is somewhat tedious and error prone to set that up, as each test requires a unique state key.
Attempted Solutions
The workaround right now is to give each test a unique state key.
test {
parallel = true
}
run "test1" {
state_key = "test1"
# ...
}
run "test2" {
state_key = "test2"
# ...
}
run "test3" {
state_key = "test3"
# ...
}This proves to be easy to forget and prone to copy/paste errors (almost submitted this issue with all the state keys as test1). This gets particularly bad as we add a large number of tests.
Proposal
One solution could be to allow the test block to have an optional attribute along the lines of default_unique_state_keys. This would cause each run block to automatically generate a unique state key by default (which could just be the name of the test though it could also be randomly generated)
test {
parallel = true
default_unique_state_keys = true
}
run "test1" {
# implicit state key: test1
# ...
}
run "test2" {
# implicit state key: test2
# ...
}
run "test3" {
# implicit state key: test3
# ...
}
run "test3a" {
# inherits state from test3
state_key = "test3"
# ...
}
run "test3b" {
# inherits state from test3a
state_key = "test3"
# ...
}
run "test4" {
state_key = "unique"
# ...
}
run "test4a" {
# inherits state from test4
state_key = "unique"
# ...
}
run "test4b" {
# inherits state from test4a
state_key = "unique"
# ...
}Alternately, when default_unique_state_keys (or whatever it would end up being named) is enabled, test state inheritance could be declared explicitly, e.g. :
test {
parallel = true
default_unique_state_keys = true
}
run "test1" {
# ...
}
run "test2" {
# ...
}
run "test3" {
# ...
}
run "test3a" {
inherit_state = "test3"
# ...
}
run "test3b" {
inherit_state = "test3a"
# ...
}I'm not too opinionated about the specifics of the solution.
References
No response