Terraform Configuration
The configuration used during the execution of an acceptance test can be specified at the TestStep level by populating one of the following mutually exclusive fields:
Terraform configuration can be used in conjunction with Terraform variables defined via TestStep.ConfigVariables.
TestStep Config
The TestStep.Config
field accepts a string containing valid Terraform configuration.
In the following example, the Config
field specifies a resource which is used in combination with ExternalProviders
to specify the version and source for the provider:
TestStep ConfigDirectory
The TestStep.ConfigDirectory
field accepts a TestStepConfigFunc which is a function that accepts a TestStepConfigRequest and returns a string containing a path to a directory containing Terraform configuration files. The path can be a relative or absolute path.
There are helper methods available for generating a TestStepConfigFunc including:
Note: TestStep.ExternalProviders
cannot be specified when using ConfigDirectory. It is expected that required_providers are defined within the configuration files.
Custom functions can be written and used in the TestStep.ConfigDirectory
field as long as the function is a TestStepConfigFunc type.
StaticDirectory
The StaticDirectory(directory string) function accepts a string specifying a path to a directory containing Terraform configuration.
For example:
In this instance, the testing configuration is expected to be in the testdata/directory_containing_config
directory relative to the file containing the Test_ConfigDirectory_StaticDirectory
test.
TestNameDirectory
The TestNameDirectory() function will use the name of the executing test to specify a path to a directory containing Terraform configuration.
For example:
In this instance, the testing configuration is expected to be in the testdata/Test_ConfigDirectory_TestNameDirectory
directory relative to the file containing the Test_ConfigDirectory_TestNameDirectory
test.
TestStepDirectory
The TestStepDirectory() function will use the name of the executing test and the current test step number to specify a path to a directory containing Terraform configuration.
For example:
In this instance, because this is the first test step in the test, the testing configuration is expected to be in the testdata/Test_ConfigDirectory_TestStepDirectory/1
directory relative to the file containing the Test_ConfigDirectory_TestStepDirectory
test.
TestStep ConfigFile
The TestStep.ConfigFile
field accepts a TestStepConfigFunc which is a function that accepts a TestStepConfigRequest and returns a string containing a path to a file containing Terraform configuration. The path can be a relative or absolute path.
There are helper methods available for generating a TestStepConfigFunc including:
Note: TestStep.ExternalProviders
cannot be specified when using ConfigFile
. It is expected that required_providers are defined within the configuration file.
Custom functions can be written and used in the TestStep.ConfigFile
field as long as the function is a TestStepConfigFunc type.
StaticFile
The StaticFile(file string) function accepts a string specifying a path to a file containing Terraform configuration.
For example:
In this instance, the testing configuration is expected to be in the testdata/directory_containing_config/main.tf
file relative to the file containing the Test_ConfigFile_StaticFile
test.
TestNameFile
The TestNameFile(file string) function will use the name of the executing test to specify a path to a file containing Terraform configuration.
For example:
In this instance, the testing configuration is expected to be in the testdata/Test_ConfigFile_TestNameFile
directory relative to the file containing the Test_ConfigFile_TestNameFile
test.
TestStepFile
The TestStepFile(file string) function will use the name of the executing test and the current test step number to specify a path to a file containing Terraform configuration.
For example:
In this instance, because this is the first test step in the test, the testing configuration is expected to be in the testdata/Test_ConfigFile_TestStepFile/1/main.tf
file relative to the file containing the Test_ConfigDirectory_TestNameDirectory
test.
TestStep ConfigVariables
Terraform input variables allow customization of a Terraform configuration without altering the configuration itself.
The TestStep.ConfigVariables
field accepts a Variables type which is a key-value map of string to Variable.
The following functions return types implementing Variable that correlate with the Terraform type constraints:
- BoolVariable(value bool)
- FloatVariable[T constraints.Float](value T)
- IntegerVariable[T constraints.Integer](value T)
- func ListVariable(value ...Variable)
- MapVariable(value map[string]Variable)
- ObjectVariable(value map[string]Variable)
- SetVariable(value ...Variable)
- StringVariable(value string)
- TupleVariable(value ...Variable)
The following example shows the usage of TestStep.ConfigVariables
in conjunction with TestStep.ConfigFile
:
The configuration would be expected to be in the testdata/Test_ConfigFile_TestNameFile/random.tf
file, for example: