-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add terragrunt example as a first class example on terratest.gruntwor…
…k.io (#994) * Add terragrunt example as a first class example on terratest.gruntwork.io * Fix web tags in go test
- Loading branch information
1 parent
a319947
commit 2053af4
Showing
5 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Terragrunt Example | ||
|
||
This folder contains the simplest possible Terragrunt module—one that just passes inputs to terraform-to demonstrate how | ||
you can use Terratest to write automated tests for your Terragrunt code. | ||
|
||
Check out [test/terragrunt_example_test.go](/test/terragrunt_example_test.go) to see how you can | ||
write automated tests for this simple module. | ||
|
||
Note that this module doesn't do anything useful; it's just here to demonstrate the simplest usage pattern for | ||
Terratest. | ||
|
||
|
||
|
||
|
||
## Running this module manually | ||
|
||
1. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH`. | ||
1. Install [Terragrunt](https://terragrunt.gruntwork.io/) and make sure it's on your `PATH`. | ||
1. Run `terragrunt apply`. | ||
1. When you're done, run `terragrunt destroy`. | ||
|
||
|
||
|
||
|
||
## Running automated tests against this module | ||
|
||
1. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH`. | ||
1. Install [Terragrunt](https://terragrunt.gruntwork.io/) and make sure it's on your `PATH`. | ||
1. Install [Golang](https://golang.org/) and make sure this code is checked out into your `GOPATH`. | ||
1. `cd test` | ||
1. `go test -v -run TestTerragruntExample` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gruntwork-io/terratest/modules/terraform" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestTerragruntExample(t *testing.T) { | ||
// website::tag::3:: Construct the terraform options with default retryable errors to handle the most common retryable errors in terraform testing. | ||
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{ | ||
// website::tag::1:: Set the path to the Terragrunt module that will be tested. | ||
TerraformDir: "../examples/terragrunt-example", | ||
// website::tag::2:: Set the terraform binary path to terragrunt so that terratest uses terragrunt instead of terraform. You must ensure that you have terragrunt downloaded and available in your PATH. | ||
TerraformBinary: "terragrunt", | ||
}) | ||
|
||
// website::tag::6:: Clean up resources with "terragrunt destroy" at the end of the test. | ||
defer terraform.Destroy(t, terraformOptions) | ||
|
||
// website::tag::4:: Run "terragrunt apply". Under the hood, terragrunt will run "terraform init" and "terraform apply". Fail the test if there are any errors. | ||
terraform.Apply(t, terraformOptions) | ||
|
||
// website::tag::5:: Run `terraform output` to get the values of output variables and check they have the expected values. | ||
output := terraform.Output(t, terraformOptions, "output") | ||
assert.Equal(t, "one input another input", output) | ||
} |