-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing Terragrunt? #122
Comments
Not currently, but that's a great idea. A |
@brikis98 I'd stick with a separate module to include additional functionalities of Terragrunt like apply-all. |
I think it would be cleaner to avoid duplicating all those code paths. To handle |
I'll try to work on this then. |
I'm confused here: doesn't gruntwork exclusively use terragrunt to work on infrastructure? And shouldn't all "dev" "staging" and "production" folders have terratests written for them (because that is what you seem to suggest in both of your books). So how does gruntwork actually test terragrunt - do you just write terratests for modules, and use another tool to do smoke tests on terragrunt deployments? @brikis98 |
Not exclusively. All of the modules in our IaC Library, where we do the majority of our testing, are written in pure Terraform and do NOT require Terragrunt at all. Also, many of the modules are written in Go, Python, Bash, etc too, as the IaC Library is designed to solve problems across the entire infrastructure, and not just those problems that can be solved by Terraform.
Terragrunt itself is tested in this repo. See the
Correct |
@brikis98 I want to take a docker image I have and get it running in ec2. So first I
Give me as much criticism as you feel like, I'm trying to learn the right way of doing things from you. I've been looking at your code, and half way done reading your book "hello startup". I really appreciate your work and writing. |
@brikis98 does that seem right or is that overkill? |
Sorry, been buried, will take a look when I get a chance |
@so87 Have you ever resolved unit testing (terratest) and terragrunt items mentioned above? Interested in any approach. Working through some of the same items you mentioned above. |
This is OT to the terragrunt testing workflow, but circling back on the OP, we've released a few functions since the issue was opened that help with testing Terragrunt:
|
I recently used the option |
As mentioned in this comment, you can now test Terragrunt. |
@kihahu @yorinasub17 @so87 @brikis98 Can any one of you share me piece of code which is written to invoke terragrunt(HCL) files from terratest(GO) script ? I am getting "github.com/gruntwork-io/terratest/modules/terraform.(*TgInvalidBinary).Error" error for below code Tryin hard to get some example code which helps me to invoke terragrunt files from terratest , please help |
Try setting the |
Exploring options to swap Terraform with Terragrunt via This is extremely useful while testing Terraform modules on different combinations of the providers at the same time. Think about safe and scalable provider upgrade story:
Basically, you do something like that:
and the you can run your test in parallel setting different env variables for
Running such tests in parallel with different env variable setup unlocks easy and scalable upgrade story, testing and also troubleshooting should providers have funky behaviors. All that is harder to do with native TF, not much options to override provider setup version (unless I miss something). |
Would be good to get sample docs for terragrunt with terratest as @pandu-bhojaraj-mf mentioned in its comments. There is literally no guide on such a simple swap out binary task |
Here's a quick Terragrunt test I got working using the existing example package test
import (
"testing"
"github.com/gruntwork-io/terratest/modules/terraform"
"github.com/stretchr/testify/assert"
)
func TestTerragruntExample(t *testing.T) {
// website::tag::2:: 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 Terraform code that will be tested.
TerraformDir: "../examples/terragrunt-example",
TerraformBinary: "terragrunt.exe", // ensure terragrunt is on your PATH, or provide the full path here
})
// website::tag::5:: Clean up resources with "terragrunt destroy" at the end of the test.
defer terraform.Destroy(t, terraformOptions)
// website::tag::3:: Run "terragrunt init" and "terragrunt apply". Fail the test if there are any errors.
terraform.InitAndApply(t, terraformOptions)
// website::tag::4:: Run `terragrunt 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)
}
|
Hi folks, I just merged in a terragrunt example that is exposed on our site, which is going to be very similar to the one above: https://terratest.gruntwork.io/examples/ (it's unfortunately in the overflow, hidden in the dropdown) Hopefully folks can use that going forward! |
still don't see it but thanks for the link. Screenshot would be good to find that dropdown |
Is it possible to swap executable that is used from
terraform
toterragrunt
?The text was updated successfully, but these errors were encountered: