#terragrunt (2020-07)

terragrunt

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

2020-07-30

jason einon avatar
jason einon

back again I’m trying to get a clean way to pass in a project var into the provider, as im splitting out my infrastructure across projects.

jason einon avatar
jason einon

has anyone done this before… this is in google cloud btw

jason einon avatar
jason einon

this is what i currently have

generate "provider" {
  path      = "[provider.tf](http://provider\.tf)"
  if_exists = "overwrite_terragrunt"
  contents  = <<EOF
  provider "google" {
  credentials = "account.json"
  region      = "europe-west2"
  project  = ${gcp_project}
}
EOF
}

remote_state {
  backend = "gcs"
  config = {
    project  = "${gcp_project}"
    location = "eu"
    bucket   = "bucket_name"
    prefix   = "${path_relative_to_include()}/terraform.tfstate"
    credentials = "account.json"


    gcs_bucket_labels = {
      owner = "terragrunt_test"
      name  = "terraform_state_storage"
    }
  }
    generate = {
    path      = "[backend.tf](http://backend\.tf)"
    if_exists = "overwrite_terragrunt"
  }
}
jason einon avatar
jason einon

error is allong these lines

terragrunt-gcp-infra/terragrunt.hcl:33,19-30: Unknown variable; There is no variable named "gcp_project"., and 2 other diagnostic(s)
loren avatar
loren

how is it that you are wanting to pass the value for gcp_project?

loren avatar
loren

at this stage in processing, you can read it from a yaml/json file, or pass it through an env

jason einon avatar
jason einon

thanks for prompt response.. i was looking to pass it in with a local var file within the module

loren avatar
loren

as in, a terraform variable?

jason einon avatar
jason einon

for example this would be within the terragrunt.hcl for the module

locals {
  # Automatically load environment-level variables
  environment_vars = read_terragrunt_config(find_in_parent_folders("env.hcl"))

  # Extract out common variables for reuse
  env = local.environment_vars.locals.environment
  project_gcp = local.environment_vars.locals.project_gcp
}
jason einon avatar
jason einon
08:28:52 PM

this would be the env.hcl file referenced

loren avatar
loren

ahh, then you have it already. for locals, terragrunt uses the same syntax as terraform, so instead of:

project  = ${gcp_project}

use:

project  = ${local.gcp_project}
loren avatar
loren

or actually, because this is hcl2 and we do not need the interpolation syntax for this use case:

project  = local.gcp_project
jason einon avatar
jason einon

awesome, thanks @loren i will give it a go!

jason einon avatar
jason einon

I was going around a bit trying to understand where these are passed in

:--1:1

2020-07-29

Milosb avatar
Milosb

Do you find it difficult to search through official terragrunt documentation ? When it was on git I could just ctrl+f easily, and find what I need in second.

jason einon avatar
jason einon

yes this is the resource i used

2020-07-28

2020-07-27

jason einon avatar
jason einon

hey all, just starting the journey with terragrunt, I have a look around, however cant find any great example repo’s that are using gcp and have a gcs as the backend, anyone have any good examples to share?

jason einon avatar
jason einon

Strategy defined and poc working… happy to help anyone who has similar starting out questions

1
ninja avatar
ninja

hi, i am getting started with terragrunt. do you mind sharing what helped you? thanks!

2020-07-23

Adrian avatar
Adrian

I’ve got Error: No valid credential sources found for AWS Provider. from yestarday, anyone else has that problem?

joshmyers avatar
joshmyers

Nope.

Adrian avatar
Adrian
Terraform Cloud AWS provider unable to find credentials which works fine local · Issue #14191 · terraform-providers/terraform-provider-aws

When tried to migrate terraform code to terraform cloud using a chain of aws cli profiles, which assumes a role, the terraform cloud AWS provider fails to find credentials file, as the same credent…

joshmyers avatar
joshmyers

Ah, you didn’t mention Terraform cloud. Not using that.

Adrian avatar
Adrian

downgrading aws.provider from 2.70 to 2.69 solve the issue


\# Generate an AWS provider block
generate "provider" {
  path      = "[provider.tf](http://provider\.tf)"
  if_exists = "overwrite_terragrunt"
  contents  = <<EOF
provider "aws" {
  region  = "${local.vars.aws_region}"
  profile = "${local.aws_profile}"
  version = "<= 2.69"
  # Only these AWS Account IDs may be operated on by this template
  # allowed_account_ids = ["${local.vars.aws_account_id}"]
}
EOF
}
Adrian avatar
Adrian

and I’m using local terraform/terragrunt setup

som.ban.mca avatar
som.ban.mca
08:48:15 PM

@ has joined the channel

2020-07-22

Josh Hudson avatar
Josh Hudson

Has anyone tried using terragrunt with tf 0.13.x? I’m curious how the module count/each will incorporate w/ terragrunt’s wrapping of tf modules.

Josh Hudson avatar
Josh Hudson

Since terragrunt handles module instantiation, rather you than defining module "my_module {, how would we pass in a count/each?

Josh Hudson avatar
Josh Hudson

Presumably by extending https://terragrunt.gruntwork.io/docs/reference/config-blocks-and-attributes/#terraform to handle count/for_each, but curious if anyone has any details.

    keyboard_arrow_up