Terraform-provider-aws: Invalid AWS Region

Created on 21 Mar 2019  路  18Comments  路  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.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

  1. terraform plan -out terraform
  2. terraform plan apply terraform

References

This issue relates to the region being asked: https://github.com/hashicorp/terraform/issues/20599

bug provider

Most helpful comment

I had the same problem when using terraform import with a -var-file and aws provider like:

provider "aws" {
  region = var.region
}

Error output:

Error: Invalid AWS Region: 

  on ../terraform/modules/cluster/main.tf line 1, in provider "aws":
   1: provider "aws" {

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.

All 18 comments

It works if I force the region through env variable:

AWS_REGION=us-west-2 terraform xxx

But I don't think it's expected behavior as the region is specified in the provider.

Still happening for me on terraform-0.12.1 and terraform-provider-aws-2.13.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.

In the off chance this helps someone who has the same issue but for a different reason, I accidentally had underscores instead of dashes.

Same issue, i had used underscore instead of -, thanks

In the off chance this helps someone who has the same issue but for a different reason, I accidentally had underscores instead of dashes.

Underscores and dashes in what? AWS_REGION is the correct format with underscores.

In the off chance this helps someone who has the same issue but for a different reason, I accidentally had underscores instead of dashes.

Underscores and dashes in what? AWS_REGION is the correct format with underscores.

If I recall correctly I did us_west_2 instead of us-west-2.

I had the same problem when using terraform import with a -var-file and aws provider like:

provider "aws" {
  region = var.region
}

Error output:

Error: Invalid AWS Region: 

  on ../terraform/modules/cluster/main.tf line 1, in provider "aws":
   1: provider "aws" {

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.

faced the same issue during import of resources with terraform v0.12.8 and AWS provider v2.26.0 and v2.27.0

Same issue with provider.aws v2.29.0

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:

module "tst" {
  source = "./tst"
  region = "aws-ie"
}

tst/main.tf:

variable "region" {
   default = "WAT?"
}

local {
   regions = { "aws-ie" = "eu-west-1" }
}

provider "aws" {
  region = local.regions[var.region]
}
...

terraform import module.tst.resource resource_id fails like this:

Error: Invalid index

  on tst/main.tf line 2, in provider "aws":
   2:   region = local.regions[var.region]
    |----------------
    | local.regions is object with 10 attributes
    | var.region is "WAT?"

The given key does not identify an element in this collection value.
Terraform v0.12.7
+ provider.aws v2.29.0

UPD: same error with Terraform v0.12.9

In the off chance this helps someone who has the same issue but for a different reason, I accidentally had underscores instead of dashes.

I was passing an undeclared and uninitialized Linux variable when running an Apply like so:
TF_VAR_aws_region=$AWS_REGION Terraform apply

After setting my variable AWS_REGION with the right region - I was able to proceed with the build.

faced the same issue terraform = 0.12.20
"aws" version = "~> 2.45.0"

this works for me 馃憞

I had to replace the variable with a hard-coded region in order to get it to work.

Same here with "aws" version 2.40.0

The same problem with "profile" too, not only "region". I couldn't do import until hardcoded profile name.

Error message:

Error: No valid credential sources found for AWS Provider.
    Please see https://terraform.io/docs/providers/aws/index.html for more information on
    providing credentials for the AWS Provider

terraform = 0.12.20, through tfenv.
provider.aws 2.49

This seems to be a deep terraform bug in the way import runs vs plan or apply . https://github.com/hashicorp/terraform/issues/13018

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
ERROR MSG TO LOGIN ECT IN TERRAFORM

I have run into this a few times now - I end up manually editing all the providers in all my modules inside .terraform from

provider "aws" {
  region = var.region
}

to

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

and then tf import again.

Was this page helpful?
0 / 5 - 0 ratings