I’m writing the testing framework for a new provider, but don’t want to pass required attributes with environment variables. Instead, I want to set them directly inside the test framework.
I’ve tried configuring the provider with a ResourceConfig, and I can verify that the provider’s ConfigureFunc is parsing the ResourceData as expected. For example:
I’m not an expert on the current plugin SDK so I might not have all of the details exactly right here, but I believe that the test framework is designed to create a fresh configuration of your provider for each test, so that it’s less likely for the behavior of one test to inadvertently affect another.
Specifically, I think the test function in the test API is itself calling Configure on the provider based on what it found in the test configuration you provided.
Given that, I think the only way to get the result you were hoping for here would be to include a provider block in each of your test configurations which specifies this fixed configuration. To make that less repetitive, perhaps you could write a helper function which takes a configuration string and appends this hard-coded provider block to the end of it, and then use that function in each of your tests to make sure they all run with the expected configuration.
I’d love to see some code examples on how to do this exactly. I am having a lot of trouble set up tests on a provider that has a nested configuration structure, so that env vars can only be used for the inner vars. When initialising, the test framework complains the needed block(s) have not been specified.
For example below I can set the env var FOO_BAR, but the test framework will complain that “at least one” block named “foo” must be set.
provider "foobar" {
foo {
bar = "hello" //this can also be set with env var FOO_BAR
}
}