hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.81k stars 9.16k forks source link

dx_gateway association import throws error #8956

Closed aacecandev closed 5 years ago

aacecandev commented 5 years ago

Community Note

Terraform Version

Terraform v0.11.14

The detected bug behaves different depending on the aws provider version

Affected Resource(s)

Terraform Configuration Files

resource "aws_dx_connection" "my-conn" {
  name      = "conn-name"
  bandwidth = "1Gbps"
  location  = "location"

  tags = "${map(
      ...
  )}"
}

resource "aws_dx_gateway" "my-dx-gw" {
  name            = "dxg-name"
  amazon_side_asn = "64512"
}

resource "aws_dx_gateway_association" "my-dx-gw-association" {
  dx_gateway_id         = "${aws_dx_gateway.dxgw-control.id}"
  associated_gateway_id = "${data.terraform_remote_state.remote_state_vpc.vpc_private_gateway_id}"
}

Debug Output

Importing the resource and making a terraform plan later using v2.11.0 would throw the following result

https://gist.github.com/aacecandev/3c15b3848126bc4b09a2c5c0cff4fde2#file-planl

Also, using v2.<12-13-14>.0 and making the same operation would fail importing the existing resources (I think it is related to some concat doing bad it's job but I'm don't feel comfortable yet with GO)

https://gist.github.com/aacecandev/e314042e8915ab32b302d91e52d46edf

Expected Behavior

Terraform's AWS latetest provider version should import successfully the current existing dx_gateway infrastructure, so when doing a terrafom plan, anything should be marked to destroy

Actual Behavior

I can import sucessfully a dx_gateway_association using provider's v2.11.0, :

aws_dx_gateway.dxgw-control: Importing from ID "313449a8-7ef4-4018-b78a-47c7db25f359"... aws_dx_gateway.dxgw-control: Import complete! Imported aws_dx_gateway (ID: 313449a8-7ef4-4018-b78a-47c7db25f359) Imported aws_dx_gateway_association (ID: ga-313449a8-7ef4-4018-b78a-47c7db25f359vgw-0248c762c28e26447) Imported aws_dx_gateway_association (ID: ga-313449a8-7ef4-4018-b78a-47c7db25f359vgw-0e7f7af297281a5ab) Imported aws_dx_gateway_association (ID: ga-313449a8-7ef4-4018-b78a-47c7db25f359vgw-0af34dba6dc9bbd1f) aws_dx_gateway_association.dxgw-control-1: Refreshing state... (ID: ga-313449a8-7ef4-4018-b78a-47c7db25f359vgw-0e7f7af297281a5ab) aws_dx_gateway_association.dxgw-control: Refreshing state... (ID: ga-313449a8-7ef4-4018-b78a-47c7db25f359vgw-0248c762c28e26447) aws_dx_gateway_association.dxgw-control-2: Refreshing state... (ID: ga-313449a8-7ef4-4018-b78a-47c7db25f359vgw-0af34dba6dc9bbd1f) aws_dx_gateway.dxgw-control: Refreshing state... (ID: 313449a8-7ef4-4018-b78a-47c7db25f359)

Error: aws_dx_gateway.dxgw-control (import id: 313449a8-7ef4-4018-b78a-47c7db25f359): 3 errors occurred:

Steps to Reproduce

  1. log to your AWS account -> aws-vault
  2. terraform init
  3. terraform import dx_gateway
  4. terraform plan
ewbankkit commented 5 years ago

@aacecandev Sorry about the problem here. It looks like I missed updating the resource import code in aws_dx_gateway that also imports associations when implementing https://github.com/terraform-providers/terraform-provider-aws/pull/8528. The symptom (error message) is similar to https://github.com/terraform-providers/terraform-provider-aws/issues/8773 and the solution should be similar. As a workaround you should be able to pin the AWS provider version to 2.11.0 as it looks like your associated gateway is a VGW.

ewbankkit commented 5 years ago

The acceptance tests for aws_dx_gateway show the error:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAwsDxGateway_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -parallel 20 -run=TestAccAwsDxGateway_ -timeout 120m
=== RUN   TestAccAwsDxGateway_importBasic
=== PAUSE TestAccAwsDxGateway_importBasic
=== RUN   TestAccAwsDxGateway_importComplex
=== PAUSE TestAccAwsDxGateway_importComplex
=== RUN   TestAccAwsDxGateway_basic
=== PAUSE TestAccAwsDxGateway_basic
=== CONT  TestAccAwsDxGateway_importBasic
=== CONT  TestAccAwsDxGateway_basic
=== CONT  TestAccAwsDxGateway_importComplex
--- PASS: TestAccAwsDxGateway_basic (39.35s)
--- PASS: TestAccAwsDxGateway_importBasic (42.12s)
--- FAIL: TestAccAwsDxGateway_importComplex (1408.90s)
    testing.go:568: Step 1 error: 2 problems:

        - error reading Direct Connect gateway association (ga-70e3def4-f9ae-41b5-81b0-add441cfeabavgw-00390591958ada8c6): DirectConnectClientException: Association ID  has an invalid format.
                status code: 400, request id: c471cce1-8d3b-11e9-818c-29febb0b2708
        - error reading Direct Connect gateway association (ga-70e3def4-f9ae-41b5-81b0-add441cfeabavgw-0fd030f037255fd03): DirectConnectClientException: Association ID  has an invalid format.
                status code: 400, request id: c4715881-8d3b-11e9-afd5-038f18e4c385
FAIL
FAIL    github.com/terraform-providers/terraform-provider-aws/aws       1408.986s
make: *** [testacc] Error 1
bflad commented 5 years ago

The fix for this regression has been merged and will release with version 2.16.0 of the Terraform AWS Provider, likely later this week.

bflad commented 5 years ago

This has been released in version 2.16.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

ghost commented 4 years ago

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!