Terrragrunt working example of passing providers to modules

162 views Asked by At

I have some Terraform code that I use to provision Transit Gateway attachments where the Transit Gateway is in one account and the VPC is a different account.

I use the following block within my module:

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = ">= 2.7.0"
      configuration_aliases = [ aws.src, aws.dst ]
    }
  }
}

I'm trying to convert this project into Terragrunt and I'm not sure how to accomplish this. There is mention of using generate here, but I don't know where to start.

How do I generate providers.tf file in the working directory that can be passed to Terragrunt during plan/apply?

1

There are 1 answers

0
v-rosa On

Just create the providers, e.g.

generate "provider" {
  path = "provider.tf"
  if_exists = "overwrite_terragrunt"
  contents = <<EOF
provider "aws" {
  alias  = "dst"
  ...
}

provider "aws" {
  alias  = "src"
  ...
}
EOF
}