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

Using depends_on in a module definition fails terraform plan when using data source aws_partition in the module #30340

Closed
watsonjm opened this issue Jan 11, 2022 · 2 comments
Labels
bug new new issue not yet triaged

Comments

@watsonjm
Copy link

When using a depends_on argument in a module definition for a module that uses the data source aws_partition, terraform plan will fail with an error due to not knowing the value until apply, like this:

The "for_each" value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created. To work around this, use the -target argument to first apply only the resources that the for_each depends on.

Terraform Version

Terraform v1.1.3
on linux_amd64
+ provider registry.terraform.io/hashicorp/aws v3.71.0
+ provider registry.terraform.io/hashicorp/cloudinit v2.2.0
+ provider registry.terraform.io/hashicorp/random v3.1.0
+ provider registry.terraform.io/hashicorp/tls v3.1.0

Terraform Configuration Files

https://github.com/watsonjm/depends_on-bug

Debug Output

https://gist.github.com/watsonjm/31bdebd61e02aa05f4d4ae2374ceac9e

Expected Behavior

terraform plan should show a successful plan

Actual Behavior

terraform plan fails with 1 or more errors depending on how many times this data source is referenced.

Steps to Reproduce

  1. terraform init -var-file=test.tfvars
  2. terraform plan -var-file=test.tfvars -out test.tfplan
    This will give you a successful plan, to see the error in action, uncomment the depends_on argument on line 30 of eks.tf and re-run terraform plan.

Additional Context

I have ran into this before with my own custom modules with the same requirements (depends_on argument in module definition, and the module using aws_partition data source), so this issue is not just with the eks module in use here.

References

terraform-aws-modules/terraform-aws-eks#1753

@watsonjm watsonjm added bug new new issue not yet triaged labels Jan 11, 2022
@jbardin
Copy link
Member

jbardin commented Jan 11, 2022

Hi @watsonjm,

The behavior you have described here is expected form the given configuration. Data sources using depends_on are always deferred until apply when there is a change in any of their dependencies. Because depends_on can't describe which part of the change is relevant, the entire change must be taken into account.

When you add depends_on to a module, you are effectively adding that to every object within the module. This can be a convenient shortcut in some cases, but we generally discourage using it on modules for this very reason, especially when that module contains data sources.

We use GitHub issues for tracking bugs and enhancements, rather than for questions. While we can sometimes help with certain simple problems here, it's better to use the community forum where there are more people ready to help.

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 Feb 11, 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
Projects
None yet
Development

No branches or pull requests

2 participants