Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportState acceptance test step fails with multiple providers #521

Closed
ewbankkit opened this issue Aug 3, 2020 · 3 comments · Fixed by #522
Closed

ImportState acceptance test step fails with multiple providers #521

ewbankkit opened this issue Aug 3, 2020 · 3 comments · Fixed by #522
Labels
bug Something isn't working

Comments

@ewbankkit
Copy link
Contributor

SDK version

v1.14.0

Relevant provider source code

...

Terraform Configuration Files

// Requester's side of the connection.
resource "aws_vpc_peering_connection_options" "test" {
  # As options can't be set until the connection has been accepted
  # create an explicit dependency on the accepter.
  vpc_peering_connection_id = "${aws_vpc_peering_connection_accepter.peer.id}"

  requester {
    allow_remote_vpc_dns_resolution = true
  }
}

// Accepter's side of the connection.
resource "aws_vpc_peering_connection_options" "peer" {
  provider = "awsalternate"

  vpc_peering_connection_id = "${aws_vpc_peering_connection_accepter.peer.id}"

  accepter {
    allow_remote_vpc_dns_resolution = true
  }
}

Failing Acceptance Test

resourceName := "aws_vpc_peering_connection_options.test"         // Requester

...

			{
				Config:            testAccVpcPeeringConnectionOptionsConfig_differentRegion_sameAccount(rName),
				ResourceName:      resourceName,
				ImportState:       true,
				ImportStateVerify: true,
			},
$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSVpcPeeringConnectionOptions_sameRegionDifferentAccount'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSVpcPeeringConnectionOptions_sameRegionDifferentAccount -timeout 120m
=== RUN   TestAccAWSVpcPeeringConnectionOptions_sameRegionDifferentAccount
=== PAUSE TestAccAWSVpcPeeringConnectionOptions_sameRegionDifferentAccount
=== CONT  TestAccAWSVpcPeeringConnectionOptions_sameRegionDifferentAccount
    testing.go:684: Step 1 error: ImportStateVerify attributes not equivalent. Difference is shown below. Top is actual, bottom is expected.
        
        (map[string]string) (len=4) {
         (string) (len=11) "requester.#": (string) (len=1) "1",
         (string) (len=44) "requester.0.allow_classic_link_to_remote_vpc": (string) (len=5) "false",
         (string) (len=43) "requester.0.allow_remote_vpc_dns_resolution": (string) (len=4) "true",
         (string) (len=44) "requester.0.allow_vpc_to_remote_classic_link": (string) (len=5) "false"
        }
        
        
        (map[string]string) (len=4) {
         (string) (len=10) "accepter.#": (string) (len=1) "1",
         (string) (len=43) "accepter.0.allow_classic_link_to_remote_vpc": (string) (len=5) "false",
         (string) (len=42) "accepter.0.allow_remote_vpc_dns_resolution": (string) (len=4) "true",
         (string) (len=43) "accepter.0.allow_vpc_to_remote_classic_link": (string) (len=5) "false"
        }
        
--- FAIL: TestAccAWSVpcPeeringConnectionOptions_sameRegionDifferentAccount (33.37s)
FAIL
FAIL	github.com/terraform-providers/terraform-provider-aws/aws	33.453s
FAIL
GNUmakefile:26: recipe for target 'testacc' failed
make: *** [testacc] Error 1

Expected Behavior

The import test step should have passed.

Actual Behavior

The actual state is correct - The imported resource, using the default aws provider, is the requester.
The expected state is incorrect - This is for the accepter resource which has the same ID but is using the awsalternate provider.
Both resources are of the same type, aws_vpc_peering_connection_options, and have the same ID (the resource ID is the underlying VPC peering connection ID which is the same for both requester and accepter options resources).

Steps to Reproduce

References

hashicorp/terraform-provider-aws#12126

@bflad
Copy link
Contributor

bflad commented Aug 7, 2020

This Terraform AWS Provider acceptance test failure on SDK v2 is likely related:

TestAccAWSDynamoDbGlobalTable_multipleRegions: resource_aws_dynamodb_global_table_test.go:60: ImportStateVerify attributes not equivalent. Difference is shown below. Top is actual, bottom is expected.
(map[string]string) (len=3) {
(string) (len=3) "arn": (string) (len=63) "arn:aws:dynamodb:us-west-2:*******:table/tf-acc-test-eq331",
(string) (len=10) "stream_arn": (string) (len=94) "arn:aws:dynamodb:us-west-2:*******:table/tf-acc-test-eq331/stream/2020-07-31T05:06:41.241",
(string) (len=12) "stream_label": (string) (len=23) "2020-07-31T05:06:41.241"
}
(map[string]string) (len=3) {
(string) (len=3) "arn": (string) (len=63) "arn:aws:dynamodb:us-east-1:*******:table/tf-acc-test-eq331",
(string) (len=10) "stream_arn": (string) (len=94) "arn:aws:dynamodb:us-east-1:*******:table/tf-acc-test-eq331/stream/2020-07-31T05:06:41.696",
(string) (len=12) "stream_label": (string) (len=23) "2020-07-31T05:06:41.696"
}
--- FAIL: TestAccAWSDynamoDbGlobalTable_multipleRegions (87.55s)

With its configuration:

func testAccDynamoDbGlobalTableConfig_multipleRegions_dynamodb_tables(tableName string) string {
	return testAccAlternateRegionProviderConfig() + fmt.Sprintf(`
data "aws_region" "alternate" {
  provider = "awsalternate"
}

data "aws_region" "current" {}

resource "aws_dynamodb_table" "test" {
  hash_key         = "myAttribute"
  name             = %[1]q
  stream_enabled   = true
  stream_view_type = "NEW_AND_OLD_IMAGES"
  read_capacity    = 1
  write_capacity   = 1

  attribute {
    name = "myAttribute"
    type = "S"
  }
}

resource "aws_dynamodb_table" "alternate" {
  provider = "awsalternate"

  hash_key         = "myAttribute"
  name             = %[1]q
  stream_enabled   = true
  stream_view_type = "NEW_AND_OLD_IMAGES"
  read_capacity    = 1
  write_capacity   = 1

  attribute {
    name = "myAttribute"
    type = "S"
  }
}
`, tableName)
}

@paddycarver
Copy link
Contributor

paddycarver commented Aug 10, 2020

Ugh, ok, I have a Thought on what this is. I think when importing we don't have access to the configuration, so the provider = awsalternate override isn't actually happening. We can resolve this by adding an ImportProvider string property to test steps, which can be passed to the -provider flag of the terraform import command. So the command would be terraform import -provider=awsalternate $RESOURCE_ADDR instead of terraform import $RESOURCE_ADDR.

I haven't investigated, but I have a hunch that could be the issue.

[edit] I'm seeing #522 now as well, and that could potentially be the issue, as well, though I think ID-only imports would still be broken even then.

@ghost
Copy link

ghost commented Oct 13, 2020

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked as resolved and limited conversation to collaborators Oct 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants