Terraform-provider-aws: terraform tells me The argument "region" is required, but was not set.

Created on 4 Sep 2019  ·  19Comments  ·  Source: hashicorp/terraform-provider-aws

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
bug upstream-terraform

Most helpful comment

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"
}

All 19 comments

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.

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.

Getting the same error in our pipelines.

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

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

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.

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.

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.

@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.

@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

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"
}

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

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.

still happening in 0.12.16 :(

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

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.

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 https://github.com/hashicorp/terraform/issues/21313 and https://github.com/hashicorp/terraform/pull/22811. There also still may be additional issues that need to be addressed upstream as well, such as a response to https://github.com/hashicorp/terraform/issues/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!

I was facing the same issue in TF Cloud,

Adding AWS_DEFAULT_REGION as an environment variable fixed the issue.

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

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!

Was this page helpful?
0 / 5 - 0 ratings