Skip to content

0.12.0-rc1 - import fails if default provider is missing #21330

@a13xb

Description

@a13xb

Summary

Import of an AWS resource will fail if a default (non-aliased) provider is not present, even if all resources are using a valid aliased provider.

Import of the same resource succeeds if:

  1. a default provider is added, even if it is completely unrelated and unused, e.g. configured with a different region than the resource imported
  2. AWS_DEFAULT_REGION environment variable is set to any region value, even if it's a different region than the resource imported

0.11 has a slightly different behaviour in that it's blocking on an interactive prompt asking for a region value. I can specify any region value and the import will proceed. I am assuming it's related, but in 0.12 it's immediate "hard" failure.

Terraform Version

Terraform v0.12.0-rc1
+ provider.aws v1.60.0-dev20190216h00-dev

Terraform Configuration Files

provider aws {
  alias = "sydney"
  region = "ap-southeast-2"
  profile = "development"
}

resource aws_vpc main {
  provider = "aws.sydney"
  cidr_block = "10.0.0.0/24"
}

resource aws_route_table main {
  provider = "aws.sydney"
  vpc_id = aws_vpc.main.id
}

Steps to Reproduce

  1. Create resources outside of Terraform
  2. terraform init
  3. terraform import -provider=aws.sydney aws_route_table.main rtb-XXX

Expected Behavior

Import finishes successfully.

Actual Behavior

After refreshing the resource state correctly, import fails anyway.

aws_route_table.main: Importing from ID "rtb-XXX"...
aws_route_table.main: Import complete!
  Imported aws_route_table
  Imported aws_route
  Imported aws_route
  Imported aws_route
  Imported aws_route
  Imported aws_route_table_association
aws_route_table_association.main: Refreshing state... [id=rtbassoc-YYY]
aws_route.main: Refreshing state... [id=r-rtb-XXX1111111111]
aws_route.main-2: Refreshing state... [id=r-rtb-XXX222222222]
aws_route.main-3: Refreshing state... [id=r-rtb-XXX3333333333]
aws_route_table.main: Refreshing state... [id=rtb-XXX]
aws_route.main-1: Refreshing state... [id=r-rtb-XXX555555555]

Error: Missing required argument

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

Debug Output

The only excerpt that seems to be relevant happens before the import starts:

...
BuiltinEvalContext: Initialized "aws" provider for provider.aws
<root>: eval: *terraform.EvalOpFilter
<root>: eval: *terraform.EvalSequence
<root>: eval: *terraform.EvalGetProvider
 [INFO]  plugin: configuring client automatic mTLS
...
BuiltinEvalContext: Initialized "aws" provider for provider.aws.sydney
<root>: eval: *terraform.EvalOpFilter
<root>: eval: *terraform.EvalSequence
<root>: eval: *terraform.EvalGetProvider
...
<root>: eval: *terraform.EvalSequence
<root>: eval: *terraform.EvalConfigProvider
buildProviderConfig for provider.aws: no configuration at all
GRPCProvider: GetSchema
buildProviderConfig for provider.aws.sydney: using explicit config only
GRPCProvider: GetSchema
<root>: eval: *terraform.EvalConfigProvider, non-fatal err: Missing required argument: The argument "region" is required, but was not set.
<root>: eval: *terraform.EvalSequence, err: Missing required argument: The argument "region" is required, but was not set.
<root>: eval: *terraform.EvalOpFilter, err: Missing required argument: The argument "region" is required, but was not set.
<root>: eval: *terraform.EvalSequence, err: Missing required argument: The argument "region" is required, but was not set.
[walkImport] Exiting eval tree: provider.aws
vertex "provider.aws": visit complete
dag/walk: upstream of "aws_vpc.main" errored, so skipping
dag/walk: upstream of "aws_route_table.main" errored, so skipping
dag/walk: upstream of "provider.aws (close)" errored, so skipping

And then a few seconds later after the import has finished:

[walkImport] Exiting eval tree: provider.aws.sydney (close)
vertex "provider.aws.sydney (close)": visit complete
dag/walk: upstream of "root" errored, so skipping

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions