I've included the output in a gist showing the different outcomes and the example Terraform configs.
When you _don't_ have the AWS_REGION or AWS_DEFAULT_REGION set as an environment variable, Terraform exhibits odd behavior between terraform plan's related to the AWS region within a module.
To reproduce in Terraform 0.6.3...
cd terraformterraform getterraform plan (multiple times)You should see output similar to the output in this gist. Almost every terraform plan has a different outcome even though nothing changed. Sometimes it fails with the error * module.network.module.vpc.provider.aws: "region": required field is not set, sometimes it asks you to enter the region on the command line (even though it's set as a default variable) then actually plans successfully.
After a successful plan with no errors, if you run terraform plan again it shows the region error again. Sometimes it errors a few times in a row, sometimes it plans successfully a few times in a row, sometimes it's every other, but it's not consistent.
I've also tried with setting region in a terraform.tfvars file with the same behavior, however sometimes it plans successfully _without_ asking me to enter the region at the command line. Without the terraform.tfvars file it always ask for you to enter the region at the command line even though it's set as a default.
So 2 potential issues.
region at the command line when you've already included it in a variableterraform plan has a different outcome between plans in which nothing changedI'm seeing this too with 0.6.9. Terraform ignores the region setting when the provider is in a module.
Update: Blowing away my .terraform directory fixed the problem. Seems like a bug in there, but I'm not sure how to reproduce it.
+1 I'm seeing this behaviour in versions from 0.6.3 up to 0.6.11, if I don't have any of the env variables set. Sometimes (usually after a change, such as removing the .terraform dir, or commenting out a module) the plan executes successfuly, but if I run terraform plan again, I'm being asked for region input. I think I only encountered this error with nested modules, eg. if I simply include a module directly from my main.tf file it works even if I run terraform plan multiple times, but if I include a module which references a "sub-module" then the region value is not being passed down to the second module.
+1 I'm also seeing this with 0.6.11, and only with nested modules. If I add the AWS_REGION env var, then running the plan works consistently...otherwise I'm prompted 3 out of 4 times for the region, even if I pass in the region as a variable to the plan command.
+1, seeing issue with 0.6.12, just as how @toddrosner described.
+1, just hit this issue with 0.6.14. Everything was working when I had module A depending on module B. But when I added a 3rd level of modules, so that A depended on B, which in turn depended on C, I started getting errors like module.A.module.B.provider.aws: "region": required field is not set.
BTW, a workaround that seems to work is to explicitly specify the provider and set its region in all of the modules. It's repetitive and feels unnecessary, but I'm not sure what else to do until this bug is fixed.
I'm seeing this behavior even without nested modules. My main.tf references 3 modules which each contain a single provider "aws" {} stanza. Passing a region variable directly into the modules from main.tf doesn't work, even explicitly setting the region as a string in the provider stanza doesn't work. It still asks me for a region every time. So weird. It seems like it's just ignoring region entirely within a module.
Terraform was working fine, but suddenly we are having the same problem with 0.6.16 and 0.6.14 as well.
Our setup:
Here are my findings:
It feels like terraform it's quite sensitive in it's state when removing a module?
@koenijn Your description seems to be related to/the same as #1447.
This may be unrelated but I've noticed I can reliably reproduce this by adding provider = "aws.private" to any resource in a file where that provider is not defined, even with no modules.
I experienced this suddenly today. I'm not sure exactly what did it, but after nuking .terraform folder and running terraform get my plan could execute
Hey @bensojona, I ran your configuration could never get the bad behavior. I remember fixing issues related to this so your specific case may be fixed. I have a feeling there are still weirdness in edges related to provider inheritance though.
@mewm since your comment was very recent: if you can get a reproduction could you open a new issue please? Thanks!
Running into this today. Really appreciative for terraform, but wanted to surface that I believe this bug still exists.
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Most helpful comment
Running into this today. Really appreciative for
terraform, but wanted to surface that I believe this bug still exists.