Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
terratest basic skelleton
package tests
import (
func TestTerraformAwsEnvironment(t *testing.T) {
myVarToInject := "my-var"
awsRegion := "eu-west-1"
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
// Variables to pass to our Terraform code using -var options
Vars: map[string]interface{}{
"my_variable": myVarToInject,
EnvVars: map[string]string{
TerraformDir: "../environments/base-example",
// cleanup created resources at the end of the test
defer terraform.Destroy(t, terraformOptions)
// run terraform init & apply
terraform.InitAndApply(t, terraformOptions)
// Perform assertions ...
expected := "some-id"
result := terraform.Output(t, terraformOptions, "some_output")
assert.Equal(t, expected, result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment