Skip to content

Instantly share code, notes, and snippets.

@diogoaurelio
Created March 22, 2021 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diogoaurelio/53cb1f70173399341cc95df52015e6d8 to your computer and use it in GitHub Desktop.
Save diogoaurelio/53cb1f70173399341cc95df52015e6d8 to your computer and use it in GitHub Desktop.
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