2

I'm trying to work out my AWS infrastructure and have the following structure:

regions
└── us-east-2_Ohio
    ├── terragrunt.hcl
    ├── variables.tf
    └── vpcs
        ├── myVPC
            ├── terragrunt.hcl
            ├── variables.tf
            └── vpc.tf

In the variables.tf at the us-east-2_Ohio level I have the provider and region set:

provider "aws" {
  region = "us-east-2"
}

When I run terragrunt plan-all, I get prompted by the myVPC module for provider.aws.region by the vpc module. I'd like to have that be passed from the parent module, but no matter what I try it won't work. Either it complains the block type is not expected or that the target module has not been applied. I even created a main.tf at the us-east-2_Ohio that only has

output "provider_region" {
  value = "us-east-2a"
}

and that didn't work.

Any suggestions would be greatly appreciated.

Thanks

Norm
  • 23
  • 3

1 Answers1

0

When using Terragrunt, ideally you should stick to Terragrunt configuration in your Terragrunt hierarchy, and reference Terraform code in a separate repository. For an example of this, see the Terragrunt infrastructure-live and Terragrunt infrastructure-modules repositories. These demonstrate a few concepts that may help you make more sense of how to structure your code.

As demonstrated in the repositories I linked above, you would define the region in a regions.hcl file that would look like this:

locals {
  aws_region = "us-east-1"
}

In your module-level terragrunt.hcl (the myVPC module in your example), you'd have a block such as this one:

include {
  path = find_in_parent_folders()
}

This will include the aws_region variable and pass it to your Terraform module, where you can set it up in a provider{} block.

Ben Whaley
  • 32,811
  • 7
  • 87
  • 85