Skip to content

Commit

Permalink
Add terragrunt example as a first class example on terratest.gruntwor…
Browse files Browse the repository at this point in the history
…k.io (#994)

* Add terragrunt example as a first class example on terratest.gruntwork.io

* Fix web tags in go test
  • Loading branch information
yorinasub17 authored Sep 29, 2021
1 parent a319947 commit 2053af4
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ env: &env
MODULE_GCP_CI_VERSION: v0.1.1
TERRAFORM_VERSION: 1.0.3
PACKER_VERSION: 1.7.4
TERRAGRUNT_VERSION: v0.31.4
TERRAGRUNT_VERSION: v0.32.3
GO_VERSION: 1.16.3
GO111MODULE: auto
K8S_VERSION: v1.15.0 # Same as EKS
Expand Down
15 changes: 15 additions & 0 deletions docs/_data/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@
- name: Kubernetes Hello, World
url: https://github.com/gruntwork-io/terratest/tree/master/examples/kubernetes-hello-world-example

- id: terragrunt-hello-world
name: Terragrunt Example
image: /assets/img/logos/terragrunt-logo.png
files:
- url: /examples/terragrunt-example/terragrunt.hcl
id: terragrunt_code
- url: /examples/terragrunt-example/main.tf
id: terraform_code
- url: /test/terragrunt_example_test.go
id: test_code
default: true
learn_more:
- name: Terragrunt
url: https://github.com/gruntwork-io/terratest/tree/master/examples/terragrunt-example

- id: aws-hello-world
name: AWS Hello, World Example
image: /assets/img/logos/aws-logo.png
Expand Down
Binary file added docs/assets/img/logos/terragrunt-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions examples/terragrunt-example/README.md
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`
28 changes: 28 additions & 0 deletions test/terragrunt_example_test.go
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)
}

0 comments on commit 2053af4

Please sign in to comment.