Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
terratest basic skelleton
package tests
import (
"github.com/gruntwork-io/terratest/modules/aws"
"github.com/gruntwork-io/terratest/modules/terraform"
"github.com/stretchr/testify/assert"
"testing"
)
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{
"AWS_DEFAULT_REGION": awsRegion,
},
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