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:
func testAccPreCheck(t *testing.T) {
testAccProviderConfigure.Do(func() {
raw := map[string]interface{}{
"broker_password": "pass",
"broker_username": "user",
"broker_url": "http://localhost:1234/",
}
err := testAccProvider.Configure(context.Background(), terraform.NewResourceConfigRaw(raw))
if err != nil {
t.Fatal(err)
}
})
}
and
provider.ConfigureFunc = func(d *schema.ResourceData) (interface{}, error) {
// broker_user prints as expected (without env vars)
fmt.Println(d.Get("broker_user").(string))
}
Though I’m still getting “The argument FOO is required, but was not set” error when running the test. For example:
➜ TF_LOG=DEBUG TF_ACC=1 go test path/to/provider/tests -v
...
Error: Missing required argument
The argument "user" is required, but was not set.
I noticed it wasn’t the configuration that throws this error, and I’ve tentatively traced it back to github.com/hashicorp/hcl
which makes me wonder:
- Is it even possible to configure a provider for acceptance test without providing required attributes via environment variables.
- What am I overlooking?