@jim,
NOTE: This question left for reference, and self-answered in the EDIT below.
Above, you advise setting the region variable in the main.tf of the module.
But is it not the case that one creates modules to be reusable, i.e. deploying the same module code in more than one region? I have a vpc mod which I want to deploy exactly the same in more than one region, so in this case, I would want to avoid setting the region in the module. I’ve tried as the OP, and a few other ways, but because I had removed the region var instantiation in the module, like the OP, I’m getting an interactive for the region var when I do a tgp.
I moved my module main.tf (which only contained the provider “aws” block with the region in and the s3 backend) into my environment, but I’m now getting:
Acquiring state lock. This may take a few moments...
var.region
Region module deployed in
Enter a value:
instead of what @Jeff_Gray and I got first (as per the original post). I’m a bit stuck trying to get the region out of the module code but still be usable.
EDIT:
OK, rechecking the example gruntworks code
The terragrunt-infrastructure-modules-example and terragrunt-infrastructure-live-example are reasonable examples to follow.
I realised that in order to not force your (in my case, vpc) module to be deployed in a specific region in the module code itself, but instead specify the region in region-specific code outside of the module codebase, abstract the region variable in your region-specific environment terraform.tfvars file:
terragrunt = {
terraform {
source = "git::ssh://git@bitbucket.org/phosphre/my.modules.git//vpc"
}
include = {
path = "${find_in_parent_folders()}"
}
}
aws_region = "eu-west-1"
and then refer to this in your module code so that when terragrunt aggregates the config, the module code can use this reference.
And then move your main.tf back into your module code (don’t forget to check in, and do a terragrunt get --terragrunt-source-update
).