#terragrunt (2020-03)

terragrunt

Terragrunt discussions Archive: https://archive.sweetops.com/terragrunt/

2020-03-30

David avatar
David

I just wrote and released https://github.com/transcend-io/terragrunt-atlantis-config if anyone is interested. It generates atlantis.yaml content for terragrunt repos by analyzing the dependency blocks (and some other stuff)

Hopefully someone else finds it useful, I’ll gladly take feature requests

transcend-io/terragrunt-atlantis-config

Generates Atlantis repo level config yaml content for Terragrunt projects - transcend-io/terragrunt-atlantis-config

1

2020-03-27

Erik Osterman (Cloud Posse) avatar
Erik Osterman (Cloud Posse)

Adding @ bot

discourse_forum avatar
discourse_forum
10:07:39 PM

@ has joined the channel

2020-03-26

2020-03-25

2020-03-24

David avatar
David

How have people managed terragrunt commands taking a really long time to run? Some of my plans take >10 minutes because the module dependency tree gets really large, where the module may depend on 10 other modules each of which has a few dependencies of their own.

As an example, running terragrunt plan > test.out 2>&1 on one of my modules, then cat test.out | grep 'output -json' | wc -l tells me that it runs terraform output -json on 53 modules before actually doing the final terraform plan. Some of these modules are quite a ways down the chain and I feel like should not be necessary to lookup the state of. In fact, I’m not sure I understand why anything other than top level dependencies have their state looked up (though I very well may be missing something).

I’ve cached all my providers so that is not an issue

Adrian avatar
Adrian

I didn’t find any solution, maybe instead of dependency feature we should use old style data to get stuff from remote state?

MattyB avatar
MattyB

@Erik Osterman (Cloud Posse) any input on this?

David avatar
David

I added support to terragrunt to concurrently lookup remote output in https://github.com/gruntwork-io/terragrunt/pull/1114

It just released in terragrunt https://github.com/gruntwork-io/terragrunt/releases/tag/v0.23.5

Lookup remote outputs concurrently by dmattia · Pull Request #1114 · gruntwork-io/terragrunt

At transcend-io, we have >300 terragrunt modules with fairly deep dependency chains. In fact, our primary backend ECS module requires looking up the terraform output -json of 52 modules (after c…

2020-03-18

jeffrey avatar
jeffrey

Hi all, how does Terragrunt call into modules with multiple providers? I’m going with the approach of keeping the code DRY and keeping only terragrunt.hcl files in my directories, which is partitioned by environment and component.

For example, AWS VPC peering is a common component that requires 2 providers as there’s both a requester and a provider. In regular Terraform, I’d do something like

module "vpc_peering" {
  source = "../path/vpc-peer"
  ... (arguments)

  providers = {
    aws.requester = aws.default
    aws.accepter = aws.peer
  }
}

However, if I’m using a root level terragrunt.hcl and then a directory level terragrunt.hcl that includes the root level one and has terraform and input blocks, I’d have something like:


\# root level terragrunt.hcl
remote_state {
  backend "s3"
  (some config)
}

generate "provider" {
  (provider config for both aws.default and aws.peer)
}


\# directory level terragrunt.hcl
terraform {
  source = "../path/vpc-peer"
}

include {
  path = find_in_parent_folders()
}

inputs = {
  (arguments)
}

How would one pass multiple providers to the module?

loren avatar
loren

you just set the alias name in your provider config and it just works

loren avatar
loren

are you running into an actual error, or just asking for confirmation that this should work?

jeffrey avatar
jeffrey

i’m running into an error because i was hoping i’d be able to rename the provider alias, such as how in standard terraform you can do aws.requester = aws.default. so you’re saying if i’m to use Terragrunt, then the provider would have to have an alias of requester already, instead of default? the reason why i wanted to keep the name default is because i have other modules that use the same provider

jeffrey avatar
jeffrey

@loren whoops forgot to tag you

loren avatar
loren

I guess I don’t understand how you’re setting it up. You’re module needs to use the same provider aliases that you set in the provider config. If your modules are changing the aliases, then you either need a meta-root module to manage the aliases, or you need to define more providers to cover each alias (even if they are otherwise the same)

:--1:1

2020-03-13

Brij S avatar
Brij S

Does anyone know if I can use a module output in the terragrunt hcl file, right I’ve got

remote_state {
  backend = "s3"

  config = {
    bucket         = "${local.prefix}-state"
    dynamodb_table = "${local.prefix}-locks"
    key            = "terraform.tfstate"
    region         = local.region
    encrypt        = true
  }
}

is it possible to pass in module.something.something instead?

Brij S avatar
Brij S

i just tried and it said it wasnt expecting module here

David avatar
David

You can, but terragrunt handles this slightly differently than terraform would.

Check out https://terragrunt.gruntwork.io/docs/features/execute-terraform-commands-on-multiple-modules-at-once/#passing-outputs-between-modules and let me know if you still have any questions

Execute Terraform commands on multiple modules at once

Learn how to avoid tedious tasks of running commands on each module separately.

2020-03-05

Jesse avatar
Jesse

Has anyone regularly used --terragrunt-include-dir? I am struggling to get it to work, but my expectations may be incorrect

Jesse avatar
Jesse

Exclude worked for me as expected

Jesse avatar
Jesse

terragrunt-info has this for the working dir:

  "WorkingDir": "<redacted>/terraform-infra-live/internal-devops"
$ pwd
<redacted as above>/terraform-infra-live/internal-devops
$ ls -l 
total 16
-rw-r--r--  1 user  staff   744 Jan 30 23:57 README.md
-rw-r--r--  1 user  staff  2570 Mar  5 11:22 terragrunt.hcl
drwxr-xr-x  6 user  staff   192 Mar  5 11:22 us-east-1
$ ls -l us-east-1/
total 8
drwxr-xr-x  7 user  staff  224 Mar  5 11:22 cloud
drwxr-xr-x  7 user  staff  224 Mar  5 11:22 dev
-rw-r--r--  1 user  staff  860 Mar  5 11:22 region.yaml

When I attempt to run

terragrunt plan-all --terragrunt-exclude-dir "us-east-1/cloud/**"

Everything in cloud is still excluded.

Jesse avatar
Jesse

We’re following the Terragrunt example repos model pretty closely

2020-03-01

Andrea avatar
Andrea

hi, I’ve banging my head against terragrunt to get an environment up and running, with some common variables (eg environment = “staging”)

Andrea avatar
Andrea

in a resource I refer to this variable as

var.common_vars["environment"]

, and it works ok until…

Andrea avatar
Andrea

until I try using it in the resource name definition like:

resource "aws_vpc" "vpc_"var.common_vars["environment"] {
Andrea avatar
Andrea

now tell me that variables are not allowed in resource name definitions, so that I’m doomed…

Andrea avatar
Andrea

the purpose here, is to get

resource "aws_vpc" "vpc_staging" {
Andrea avatar
Andrea

if you have any tips please give me a shout, thanks

wattiez.morgan avatar
wattiez.morgan

I dont use environment specific resource names, especially as I want my code to be the same for all environnements. Instead I use those environment specific values inside resource definitions, e.g for vpc names etc.

Andrea avatar
Andrea

Mmm ok - I suppose I’ll have to change my strategy as I move from tf files to tf modules (with terragrunt in the mix), removing the env. from the resource names… hopefully I won’t find anymore “surprises”

Andrea avatar
Andrea

Thanks @wattiez.morgan for the input

:--1:1
    keyboard_arrow_up