Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terraform tells me The argument "region" is required, but was not set. #9989

Closed
grimm26 opened this issue Sep 4, 2019 · 19 comments
Closed
Labels
bug Addresses a defect in current functionality. upstream-terraform Addresses functionality related to the Terraform core binary.

Comments

@grimm26
Copy link
Contributor

grimm26 commented Sep 4, 2019

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

Terraform v0.12.7

  • provider.aws v2.26.0

Affected Resource(s)

unknown

Terraform Configuration Files

provider "aws" {
  region  = "us-east-2"
  alias   = "oh"
  profile = "aws_account_profile"
}

provider "aws" {
  region  = "us-east-1"
  alias   = "va"
  profile = "aws_account_profile"
}

....

Debug Output

https://gist.github.com/grimm26/41ab564a415361bfe6dfb3a6ce1b3a47

Expected Behavior

Work without complaining.

Actual Behavior

worked? but also:
Error: Missing required argument

The argument "region" is required, but was not set.

Steps to Reproduce

  1. terraform apply

sometimes it happens, sometimes it does not. My providers are always defined with a region and a profile. FYI, the profile is an assumed role and I have AWS_SDK_LOAD_CONFIG=1 set.

Important Factoids

My providers are always defined with a region and a profile. FYI, the profile is an assumed role and I have AWS_SDK_LOAD_CONFIG=1 set.

References

  • #0000
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Sep 4, 2019
@n-kyriakopoulos
Copy link

n-kyriakopoulos commented Sep 4, 2019

Are you running this from your local machine? I get the same exact error when I run terraform plan through Jenkins but it works fine locally with the same terraform version.

@grimm26
Copy link
Contributor Author

grimm26 commented Sep 5, 2019

Are you running this from your local machine? I get the same exact error when I run terraform plan through Jenkins but it works fine locally with the same terraform version.

I'm running terragrunt/terraform on my local machine.

@DanielMarquard
Copy link

Getting the same error in our pipelines.

terraform destroy -force -input=false -auto-approve -state=$STATE

@alexpekurovsky
Copy link

I faced similar issue. My problem was that I used terraform state rm to remove some module from state (as I was moving it to another module). But in remote state this module still was mentioned, even terraform told No matching resource instances found. while trying to delete again.
Downloading state file, manually removing removed modules from there and uploading state file back solved the issue

@grimm26
Copy link
Contributor Author

grimm26 commented Sep 11, 2019

I faced similar issue. My problem was that I used terraform state rm to remove some module from state (as I was moving it to another module). But in remote state this module still was mentioned, even terraform told No matching resource instances found. while trying to delete again.
Downloading state file, manually removing removed modules from there and uploading state file back solved the issue

That is it exactly. I ran an apply with TF_LOG=TRACE and found where there was a provider.aws that errorred and what resource that was attached to.
in my case:

2019/09/11 13:17:53 [WARN] <root>: eval: *terraform.EvalConfigProvider, non-fatal err: Missing required argument: The argument "region" is required, but was not set.
2019/09/11 13:17:53 [ERROR] <root>: eval: *terraform.EvalSequence, err: Missing required argument: The argument "region" is required, but was not set.
2019/09/11 13:17:53 [ERROR] <root>: eval: *terraform.EvalOpFilter, err: Missing required argument: The argument "region" is required, but was not set.
2019/09/11 13:17:53 [ERROR] <root>: eval: *terraform.EvalSequence, err: Missing required argument: The argument "region" is required, but was not set.
2019/09/11 13:17:53 [TRACE] [walkApply] Exiting eval tree: provider.aws
2019/09/11 13:17:53 [TRACE] vertex "provider.aws": visit complete
2019/09/11 13:17:53 [TRACE] dag/walk: upstream of "module.app-cluster.module.asg.aws_autoscaling_group.b (clean up state)" errored, so skipping
2019/09/11 13:17:53 [TRACE] dag/walk: upstream of "provider.aws (close)" errored, so skipping

I had updated that module at one point and removed module.app-cluster.module.asg.aws_autoscaling_group.b and instead made module.app-cluster.module.asg.aws_autoscaling_group.a more flexible now that terraform 0.12 can do cool things like null and dynamic blocks.

@scumola
Copy link

scumola commented Sep 30, 2019

I had this issue, but when I killed the stack, nuked the state file and then re-built the stack, everything was fine. Has something to do with the state file, I think.

@grimm26
Copy link
Contributor Author

grimm26 commented Oct 2, 2019

This is related to hashicorp/terraform#21313 and should be fixed by hashicorp/terraform#22811

@neysofu
Copy link

neysofu commented Oct 21, 2019

I'm running into the same issue whenever I execute terraform plan inside a new project.

Terraform v0.12.12
+ provider.aws v2.33.0

Any suggestions? I thought this was fixed.

@BarnumD
Copy link

BarnumD commented Oct 21, 2019

@neysofu Another reason that can happen with a new project is that you don't have the aws provider configured. Try configuring in providers.tf.

@scooberu
Copy link
Contributor

@neysofu Another reason that can happen with a new project is that you don't have the aws provider configured. Try configuring in providers.tf.

OP posted their provider code and it lgtm

@jonathortense
Copy link

jonathortense commented Oct 31, 2019

Not sure if this is fixed on newer versions, but the temporary solution that works for me is:

  • Add an empty default AWS provider (without the alias and profile)
provider "aws" {
  region  = "us-east-1"
}

@abergmeier
Copy link

abergmeier commented Nov 4, 2019

Still have this problem with 0.12.13. Workaround of @jonathortense checks out.
Would be good to have a proper fix, though.

@prashant0085
Copy link

I was facing the same issue for the region even after providing the default region = "us-east-1" in vars.tf. What fixed this issue was I re-ran terraform apply with my sso profile (OKTA) as it has the region set as us-east-1.

@sdickhoven
Copy link

sdickhoven commented Nov 21, 2019

still happening in 0.12.16 :(

...and manually removing offending module from state still fixes the problem. 👍

@ronjarrell
Copy link

For me this seems to be hashicorp/terraform/21313 as my state file was full of resources with empty instance arrays after I did a destroy of the entire environment. I have a lot of optional building in my config where I'll generate count = length(variable) instances, and that may well be 0.

@bflad bflad added upstream-terraform Addresses functionality related to the Terraform core binary. bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Nov 22, 2019
@bflad
Copy link
Contributor

bflad commented Nov 22, 2019

Hi folks 👋 Sorry for this frustrating behavior and thank you for reporting it here. It appears this issue report may be diverging due to several consequences for this type of error message.

One important piece to note is that all Terraform configuration that references any Terraform AWS Provider resource or data source must include some form of a region configuration. This can be either configured in the form of an environment variable such as AWS_DEFAULT_REGION, the shared AWS configuration file such as ~/.aws/config, or a Terraform provider configuration such as the below for the "default" AWS provider instance:

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

This is true even for a Terraform configuration that does not physically use any AWS APIs, such as those using the aws_iam_policy_document data source. If you are using multiple provider instances, each provider instance must have its region configured as mentioned above. The maintainers have seen complex configurations/modules that intend to require only provider aliases (no default provider), but omit the provider argument from data sources like the above, which means that data source falls back to the "default" provider and would cause this same potentially confusing error in that scenario.

Another cause for this type of issue is the Terraform CLI logic, when calling terraform destroy or terraform apply, is not appropriately cleaning up resources/modules in the Terraform state during operations, which further runs of Terraform are unable to retrieve the now missing provider configuration for those resources. This issue type should be at least partially resolved with Terraform 0.12.11 and later as part of hashicorp/terraform#21313 and hashicorp/terraform#22811. There also still may be additional issues that need to be addressed upstream as well, such as a response to hashicorp/terraform#22758.

Our best recommendation here will be try upgrading your Terraform CLI version to 0.12.11 or later (0.12.16 is most recent as of this writing) and trying again. If you are still having trouble after then, we would suggest opening a bug report upstream at https://github.com/hashicorp/terraform/issues/new?template=bug_report.md, filling out the requested details in the issue template so that team can triage further. If your issue really does appear to be an issue within the Terraform AWS Provider initialization when it tries to determine the region based on the provider configuration, AWS shared configuration files, or environment variable, then filing a new bug report in this repository would be appropriate and we can take a fresh look for your situation.

My apologies if this answer does not seem sufficient in this case as these issues that straddle between the two codebases are sometimes misdiagnosed and hopefully either upgrading the Terraform CLI or future potential bug fixes based off fresh reports can help narrow this down better. Thank you!

@bflad bflad closed this as completed Nov 22, 2019
@libert-xyz
Copy link

I was facing the same issue in TF Cloud,

Adding AWS_DEFAULT_REGION as an environment variable fixed the issue.

@anujshankar-mck
Copy link

@bflad Exactly, faced the issue you mentioned while using 0.12.6 and fixed by passing provider

@ghost
Copy link

ghost commented Jan 2, 2020

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Jan 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. upstream-terraform Addresses functionality related to the Terraform core binary.
Projects
None yet
Development

No branches or pull requests