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

Terraform Test unable to resolve implicit dependencies #30071

Closed
drewmullen opened this issue Dec 2, 2021 · 11 comments
Closed

Terraform Test unable to resolve implicit dependencies #30071

drewmullen opened this issue Dec 2, 2021 · 11 comments
Labels
bug new new issue not yet triaged waiting-response An issue/pull request is waiting for a response from the community

Comments

@drewmullen
Copy link
Contributor

drewmullen commented Dec 2, 2021

Note: see comments. i started this PR thinking it was just related to a data_source but it turns out to be more broad

Terraform Version

$ terraform -v
Terraform v1.0.8
on darwin_amd64

Terraform Configuration Files

data "aws_region" "current" {}

resource "aws_vpc_ipam" "example" {
  operating_regions {
    region_name = data.aws_region.current.name
  }
}

Debug Output

please LMK if you want this - i have to scrape the logs

Expected Behavior

test should pass

Actual Behavior

│ Error: Failed to clean up after tests
│ 
│ Due to errors during destroy, test suite "examples_ipam_vpc" has left behind an object for aws_vpc_ipam.example. You will need to delete this object manually in the remote system, or else it may have an ongoing cost.

Steps to Reproduce

put hcl above in root module. place boilerplate test directory/provider definition
terraform test

Additional Context

References

@drewmullen drewmullen added bug new new issue not yet triaged labels Dec 2, 2021
@drewmullen
Copy link
Contributor Author

drewmullen commented Dec 2, 2021

note: the presence of the data source does not cause the error. just the usage:

this works fine

data "aws_region" "current" {}

resource "aws_vpc_ipam" "example" {
  operating_regions {
    region_name = "us-east-1"
  }
}

@drewmullen
Copy link
Contributor Author

more details to add here. it seems to be related to implicit dependencies? here is the branch im using. you'll see a lot of commented code in main.tf thats because i was trying to chase back the issue.

basically, the aws_vpc_ipam is created (see the id below) but the aws_vpc_ipam_pool fails to create. note that it has a dependency on it to aws_vpc_ipam 😐

╷
│ Error: Failed to clean up after tests
│ 
│ Due to errors during destroy, test suite "examples_ipam_vpc" has left behind an object for aws_vpc_ipam.example, with the following identity:
│     id = "ipam-012ddd4da9d2ddfdc"
│ 
│ You will need to delete this object manually in the remote system, or else it may have an ongoing cost.
╵
─── Error: examples_ipam_vpc (terraform destroy) 
failed to destroy objects created during test (NOTE: leftover remote objects may still exist)
╷
│ Error: error deleting IPAM: (ipam-012ddd4da9d2ddfdc): DependencyViolation: The specified action is not valid for ipam-scope-0499f1afbd6931db7. The scope is either default scope or there are one or more pools attached to the scope.
│   status code: 400, request id: 7dfffc45-fa54-4cd9-bd40-205def6895cc

@drewmullen drewmullen changed the title Terraform Test fails if you attempt to use data "aws_region" "current" {} Terraform Test has problems with implicit dependencies Dec 2, 2021
@drewmullen drewmullen changed the title Terraform Test has problems with implicit dependencies Terraform Test unable to resolve implicit dependencies Dec 2, 2021
@drewmullen
Copy link
Contributor Author

Some how it escaped me entirely that terraform test has its own repo. Probably because it's a command on core... ?

Anyways - if you'd prefer I can move these over to: https://github.com/apparentlymart/terraform-provider-testing/issues

@apparentlymart
Copy link
Contributor

Hi @drewmullen,

That repository is not related to the terraform test command, so this is the right place to open this issue. Thanks!

@jbardin
Copy link
Member

jbardin commented Dec 3, 2021

Hi @drewmullen,

Thanks for filing the issue and trying out the testing functionality!

You mention in the follow-up the problem is that the aws_vpc_ipam_pool fails to create, but the error being shown is that aws_vpc_ipam.example is failing to be deleted. Is there another case where the creation is failing?

Terraform has no notion of "implied dependency", any interdependency between resources must be declared in the configuration; from what I see though, the only needed dependency between the aws_vpc_ipam and the aws_vpc_ipam_pool is in the configuration. Outside of the extra checks added by the test provider, the operation should be identical to applying and destroying the same configuration. Can you verify that manually testing the same config works as expected?

You can also try with the latest v1.1.0-rc release, which has some bug fixes that could be applicable here. I'm not able to replicate the problem here with basic test using the default aws_vpc_ipam_pool example configuration.

@jbardin jbardin added the waiting-response An issue/pull request is waiting for a response from the community label Dec 3, 2021
@drewmullen
Copy link
Contributor Author

drewmullen commented Dec 3, 2021

@jbardin sure i dont mind trying on 1.10-rc. i download the zip and ran go install from the dir and im getting an error:

internal/backend/remote/backend.go:15:2: github.com/hashicorp/[email protected]: invalid version: unknown revision e52963e079d0

do you happen to have a compiled binary for darwin that i can use or a doc i can reference that might resolve?

i said "implied dependency" only because thats how terraform's docs use the jargon - i agree though... its not really "implicit". what is more accurate wording i can use here?

Implicit dependencies are the primary way that Terraform understands the relationships between your resources.

I can confirm that this terraform builds 100% fine :) i actually wrote it and it was released yesterday :) Here is an acceptance test that looks almost identical

the reason i suggested the implicit dependency is the problem is because i saw 2 examples where resource interdependencies have failed with similar errors. but youre right it could be something else entirely!

  1. with the data source
  2. with the ipam resources

@jbardin
Copy link
Member

jbardin commented Dec 3, 2021

Ah thanks for the reminder about the docs, I see what you mean. Users often use the "implicit dependency" term to denote when they have resources that should somehow be dependent even when there is no reference between them, so I often default to that source of confusion.

The releases are all published on releases.hashicorp.com, the v1.1.0-rc1 is here: https://releases.hashicorp.com/terraform/1.1.0-rc1/

@drewmullen
Copy link
Contributor Author

drewmullen commented Dec 3, 2021

Looks like that fixed it. Any idea when this will go GA?

Latest Version (1.1 rc)

tf test
╷
│ Warning: The "terraform test" command is experimental
│
│ We'd like to invite adventurous module authors to write integration tests for their modules using this command, but all of the
│ behaviors of this command are currently experimental and may change based on feedback.
│
│ For more information on the testing experiment, including ongoing research goals and avenues for feedback, see:
│     https://www.terraform.io/docs/language/modules/testing-experiment.html
╵
Success! All of the test assertions passed.

Previous Version:

$ /usr/local/stow/terraform_1.0.8/bin/terraform test
╷
│ Warning: The "terraform test" command is experimental
│
│ We'd like to invite adventurous module authors to write integration tests for their modules using this command, but all of the
│ behaviors of this command are currently experimental and may change based on feedback.
│
│ For more information on the testing experiment, including ongoing research goals and avenues for feedback, see:
│     https://www.terraform.io/docs/language/modules/testing-experiment.html
╵
╷
│ Error: Failed to clean up after tests
│
│ Due to errors during destroy, test suite "examples_ipam_vpc" has left behind an object for aws_vpc_ipam.example, with the
│ following identity:
│     id = "ipam-0532d5a26c8aad247"
│
│ You will need to delete this object manually in the remote system, or else it may have an ongoing cost.
╵
─── Error: examples_ipam_vpc (terraform destroy) ───────────────────────────────────────────────────────────────────────────────────
failed to destroy objects created during test (NOTE: leftover remote objects may still exist)
╷
│ Error: error deleting IPAM: (ipam-0532d5a26c8aad247): DependencyViolation: The specified action is not valid for ipam-scope-092a5fda4e0553a6a. The scope is either default scope or there are one or more pools attached to the scope.
│ 	status code: 400, request id: f556e3e9-e335-4152-8558-583768be83f0

@jbardin
Copy link
Member

jbardin commented Dec 3, 2021

Thanks for confirming @drewmullen!

We don't have any specific dates for release since there is always the chance of last minute bugs or scheduling conflicts, but each branch's releases have been every 2 weeks on average.

@jbardin jbardin closed this as completed Dec 3, 2021
@drewmullen
Copy link
Contributor Author

1 more note for completeness the data source related issue was also resolved. i only tested the ipam interdependencies in my last msg.

thanks!

@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug new new issue not yet triaged waiting-response An issue/pull request is waiting for a response from the community
Projects
None yet
Development

No branches or pull requests

3 participants