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
In the Terraform AWS provider, we frequently have acceptance tests which share common setup infrastructure across tests. To avoid repeating the setup, we have a helper function (acctest.ConfigCompose) which composes a variable number of configuration strings into a single string which is then passed to the TestStep.Config argument. The setup is roughly:
funcTestAccSomeResource_basic(t*testing.T) {
resource.ParallelTest(t, resource.TestCase{
// Other setupSteps: []resource.TestStep{
{
Config: testAccSomeResource_basic(rName),
// Other checks
},
},
})
}
functestAccSomeResourceConfigBase(rNamestring) string {
returnfmt.Sprintf(`data "aws_other_resource" "test" { name = %[1]q}`, rName)
}
functestAccSomeResourceConfig_basic(rNamestring) string {
returnacctest.ConfigCompose(
testAccSomeResourceConfigBase(rName),
fmt.Sprintf(`resource "aws_some_resource" "test" { name = %[1]q other_arn = aws_other_resource.test.arn}`, rName))
}
// Composition is repeated for additional test configurations
As we are investigating adoption of the new ConfigDirectory test step option, we're finding that migrating from the pattern above requires copying the "setup" configuration into the testdata subdirectory for each test. If we need to make a change to the setup, we now have to apply that change several times (each testdata subdirectory), rather than in a single location.
Attempted solutions
Copying "setup" configuration into each testdata directory
Proposal
A helper function to compose directories would allow us to replicate this pattern while gaining the benefits of ConfigDirectory/ConfigFile over HCL strings embedded within our Go source code.
terraform-plugin-testing version
Use cases
In the Terraform AWS provider, we frequently have acceptance tests which share common setup infrastructure across tests. To avoid repeating the setup, we have a helper function (
acctest.ConfigCompose
) which composes a variable number of configuration strings into a single string which is then passed to theTestStep.Config
argument. The setup is roughly:As we are investigating adoption of the new
ConfigDirectory
test step option, we're finding that migrating from the pattern above requires copying the "setup" configuration into thetestdata
subdirectory for each test. If we need to make a change to the setup, we now have to apply that change several times (eachtestdata
subdirectory), rather than in a single location.Attempted solutions
testdata
directoryProposal
A helper function to compose directories would allow us to replicate this pattern while gaining the benefits of
ConfigDirectory
/ConfigFile
over HCL strings embedded within our Go source code.Composing files may also be a viable option which avoids complexities such as file name collisions across directories.
References
resource.Test()
andresource.TestStep
level #82 are similar, but to the best of my understanding those requests are for setup/teardown hooks which span the entire lifecycle of acceptance test execution. This request is focused more narrowly on an individual test (potentially across multiple steps, but still a single test).The text was updated successfully, but these errors were encountered: