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 mock calculated attributes on resources in unit tests. By unit tests I mean the command = plan in the run blocks set, because I just want to test conditionals and loops inside my Terraform manifests. In the assert condition of the run block, it should be possible to use the mocked values on the resources.
Attempted Solutions
The resource gitlab_user_runner exposes the computed attribute token, which I use as input for other resources. In my unit test I want to mock the value of this token.
When executing the test, I get the following error:
│ Error: Unknown condition value
│
│ on tests/gitlab.tftest.hcl line 12, in run "test_mock_token":
│ 12: condition = gitlab_user_runner.test_runner.token == "mocked-token"
│
│ Condition expression could not be evaluated at this time. This means you have executed a `run` block with `command = plan` and one of the values your condition depended
│ on is not known until after the plan has been applied. Either remove this value from your condition, or execute an `apply` command from this `run` block.
│
When I run the test with command = plan everything works fine. But in this case I just want to have a unit test, without any resources provisioned.
Proposal
To write proper unit tests it would be a great benefit if one could supply mocked values already during the planning stage.
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!
Terraform Version
Use Cases
I would like to mock calculated attributes on resources in unit tests. By unit tests I mean the
command = plan
in the run blocks set, because I just want to test conditionals and loops inside my Terraform manifests. In the assert condition of the run block, it should be possible to use the mocked values on the resources.Attempted Solutions
The resource
gitlab_user_runner
exposes the computed attributetoken
, which I use as input for other resources. In my unit test I want to mock the value of this token.The main Terraform manifest:
Testfile where I want to override the token value on
gitlab_user_runner.test_runner
When executing the test, I get the following error:
When I run the test with command = plan everything works fine. But in this case I just want to have a unit test, without any resources provisioned.
Proposal
To write proper unit tests it would be a great benefit if one could supply mocked values already during the planning stage.
References
No response
The text was updated successfully, but these errors were encountered: