This section covers testing IBM Cloud Terraform modules using IBM Cloud Schematics Workspaces. The testschematic
package provides a comprehensive framework for testing your Terraform code in a fully managed IBM Cloud environment without needing to install and configure Terraform locally.
- Overview - Framework introduction and quick start
- Examples - Comprehensive examples for common scenarios
- Configuration - Complete configuration options and settings
- Testing Process - Detailed testing lifecycle explanation
- Troubleshooting - Common issues and solutions
The framework handles the complete testing lifecycle:
- Creates a test workspace in IBM Cloud Schematics
- Creates and uploads a TAR file of your Terraform project to the workspace
- Configures the workspace with your test variables
- Runs PLAN/APPLY/DESTROY steps on the workspace to provision and destroy resources
- Checks consistency by running an additional PLAN after APPLY
- Deletes the test workspace
package test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/testschematic"
)
func TestBasicSchematics(t *testing.T) {
t.Parallel()
options := testschematic.TestSchematicOptionsDefault(&testschematic.TestSchematicOptions{
Testing: t,
Prefix: "my-test",
TarIncludePatterns: []string{"*.tf", "examples/basic/*.tf"},
TemplateFolder: "examples/basic",
})
options.TerraformVars = []testschematic.TestSchematicTerraformVar{
{Name: "ibmcloud_api_key", Value: options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
{Name: "ibm_region", Value: options.Region, DataType: "string"},
{Name: "prefix", Value: options.Prefix, DataType: "string"},
}
err := options.RunSchematicTest()
assert.NoError(t, err, "Schematics test should complete without errors")
}
For detailed examples and advanced usage, see the Examples guide.