terraform-provider-aws: Invalid AWS Region
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.11.13
+ provider.aws v2.2.0
Terraform Configuration Files
provider "aws" {
region = "us-west-2"
alias = "bridge"
version = "~> 2.2.0"
}
data "aws_caller_identity" "bridge" {
provider = "aws.bridge"
}
data "aws_iam_policy_document" "s3_changeme_terraform" {
statement {
#sid = "1"
actions = [
"s3:GetBucketLocation",
"s3:GetBucketVersioning",
"s3:GetObject",
"s3:GetObjectVersion",
"s3:ListBucket",
]
effect = "Allow"
resources = [
"arn:aws:s3:::changeme-terraform",
]
principals {
type = "AWS"
identifiers = [
"arn:aws:iam::${data.aws_caller_identity.bridge.account_id}:root",
]
}
}
}
Debug Output
Plan: https://gist.github.com/scalp42/c847168667233b4bf5b89e79dbaa7c0c
Apply: https://gist.github.com/scalp42/cd7644708890dfed55080c6d870a8b1f
Expected Behavior
- it should not ask for the region
- it should pick up the region from the provider
Actual Behavior
- will ask for AWS region
- will not create any resource mentioning an invalid AWS region
Steps to Reproduce
terraform plan -out terraformterraform plan apply terraform
References
This issue relates to the region being asked: https://github.com/hashicorp/terraform/issues/20599
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 100
- Comments: 32 (8 by maintainers)
I had the same problem when using
terraform importwith a-var-fileand aws provider like:Error output:
I had to replace the variable with a hard-coded region in order to get it to work.
The annoying thing about it is that it appears (far as I can tell) to work just fine when doing plan/apply, and then surprises you with problems if you ever happen to use import.
Region name must be like this other wise you will get error for region ok region= “us-west-1a” you need to remove a this is the right way to keep your regino name region = “us-west-1”
happy
I don’t know if it is related, but the error is the same, at least. Still happen on v0.15.0 + AWS v3.37.0
If I plan, it goes well
But if I try to destroy
It works if I force the region through env variable:
But I don’t think it’s expected behavior as the region is specified in the provider.
faced the same issue during import of resources with terraform v0.12.8 and AWS provider v2.26.0 and v2.27.0
This seems to be a deep terraform bug in the way
importruns vsplanorapply. https://github.com/hashicorp/terraform/issues/13018The same problem with “profile” too, not only “region”. I couldn’t do import until hardcoded profile name.
Error message:
terraform = 0.12.20, through tfenv. provider.aws 2.49
seems it was fixed in 0.15.1
Seeing the same issue.
applyworks fine, but ondestroy, any nestedproviderblock withregionset to a variable gives an “Invalid AWS Region” error.It looks like this is a bug upstream in Terraform CLI version 0.15.0 (https://github.com/hashicorp/terraform/issues/28428 / https://github.com/hashicorp/terraform/pull/28444), which could be addressed next Terraform CLI release.
Looks like for import context is initialized with some short circuit. If variable used for region doesn’t have default value, import fails with
Error: Invalid AWS Region:as described above. But if default value added for this variable, import operation uses this value instead of given to module’s parameter.main.tf:
tst/main.tf:
terraform import module.tst.resource resource_idfails like this:UPD: same error with Terraform v0.12.9
Same issue with provider.aws v2.29.0
In the off chance this helps someone who has the same issue but for a different reason, I accidentally had underscores instead of dashes.
Still happening for me on
terraform-0.12.1andterraform-provider-aws-2.13.0seems to have resurfaced in 1.1.7 with aws provider 4.4.0.
terraform planfails when the region is set from the provider config, but will proceed if I set an env var:Error: error configuring Terraform AWS Provider: error validating provider credentials: error calling sts:GetCallerIdentity: operation error STS: GetCallerIdentity, failed to resolve service endpoint, an AWS region is required, but was not foundI have run into this a few times now - I end up manually editing all the providers in all my modules inside
.terraformfromto
and then
tf importagain.I tried with 0.15.4 and it workd. So; with 0.15.0 I can init and plan, but not destroy. Bug seems fixed in the subsequent patch 🤷‍♀️
Underscores and dashes in what?
AWS_REGIONis the correct format with underscores.