My terragrunt.tfvars file specifies my provider as follows:
terragrunt {
terraform {
source = "git::ssh://git@..."
# define region for aws
# security connection will be pulled from credentials file
provider "aws" {
version = "~> 1.54"
region = "us-west-2"
}
# for data_file resource
provider "template" {
version = "~> 1.0"
}
}
include {
path = "${find_in_parent_folders()}"
}
}
However, when I run terragrunt plan I see this:
Initializing the backend...
Successfully configured the backend "s3"! Terraform will automatically
use this backend unless the backend configuration changes.
Initializing provider plugins...
- Checking for available provider plugins on https://releases.hashicorp.com...
- Downloading plugin for provider "template" (1.0.0)...
- Downloading plugin for provider "aws" (1.54.0)...
The following providers do not have any version constraints in configuration,
so the latest version was installed.
To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.
* provider.aws: version = "~> 1.54"
* provider.template: version = "~> 1.0"
Terraform has been successfully initialized!
Furthermore, despite my specifying the region in the awsprovider, it still prompts me for a value:
[terragrunt] 2019/01/05 01:20:46 Running command: terraform plan
provider.aws.region
The region where AWS operations will take place. Examples
are us-east-1, us-west-2, etc.
Default: us-east-1
Enter a value: us-west-2
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
I can overwrite it with an environment variable, however this shouldn't happen. I'm trying to keep things DRY and not put the provider info inside the source module, but is that really not possible?
You don't define the provider code in terraform.tfvars. It goes into your .tf code.
if anyone else stumbled on this issue, this community post has the full answer you are looking for.
I'm having a separate but related issue.
When using Terraform to include a Terraform module you can pass or override providers of the modules.
https://www.terraform.io/docs/configuration/modules.html#passing-providers-explicitly
This seems impossible with Terragrunt?
I came across a use case that is a great fit for the feature @ericfrederich cited above.
To give you guys a better grasp of it, we got more than one provider on our provider.tf, which is propagated to child folders via generators.
We could use the ability of referencing one or another provider via explicit passing:
module "a_module" {
source = ...
providers = {
aws = aws.account_a
}
}
Or even more than one provider at once:
module "complex_module" {
source = ...
providers = {
aws.primary = aws.region_a
aws.secondary = aws.region_b
}
}
Lemme know if you guys need some extra details on it.
Unfortunately, there isn't a way to support this in terragrunt because there is no way to do this through CLI args or environment variables in Terraform at the current moment.
You will have to figure out a way to do this through conditional generators (e.g., update the contents of the provider.tf file generated by generate blocks to be dynamically determined in terragrunt), or variables that configure the provider in the module.
Most helpful comment
I'm having a separate but related issue.
When using Terraform to include a Terraform module you can pass or override providers of the modules.
https://www.terraform.io/docs/configuration/modules.html#passing-providers-explicitly
This seems impossible with Terragrunt?