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

Improve depends_on error-reporting when used with interpolated resources #20846

Closed
dekimsey opened this issue Mar 27, 2019 · 3 comments
Closed

Comments

@dekimsey
Copy link
Contributor

Current Terraform Version

terraform -v
Terraform v0.11.11
+ provider.aws v1.60.0
+ provider.azuread v0.2.0
+ provider.null v1.0.0
+ provider.random v2.0.0
+ provider.template v1.0.0
+ provider.tls v1.2.0

Use-cases

Improve error-reporting when depends_on, which has a somewhat special syntax, is used incorrectly. This is to provide helpful hint to the editor as to how depends_on must be used. I know I stared at this blankly for a bit before I realized my mistake.

Proposal

Given an input like ...

resource "aws_lb" "foo" {
   ...
   depends_on = ["${aws_s3_bucket.lb-access-logs}"]
}

We encounter the following error during apply:

$ terraform apply

Error: aws_lb.foo: resource depends on non-existent resource '${aws_s3_bucket.lb-access-logs}'

The depends_on syntax is unusual in that it requires un-interpolated values. It's one of the few places that references another resource by it's literal name.
This request is that the error message be improved to something like:

$ terraform apply

Error: aws_lb.foo: resource depends on non-existent value '${aws_s3_bucket.lb-access-logs}'. Note, interpolated values cannot be used in depends_on, did you mean 'aws_s3_bucket.lb-access-logs'?

References

None.

@jbardin
Copy link
Member

jbardin commented Mar 27, 2019

Hi @dekimsey,

Thanks for filing the issue!

This is covered by the configuration enhancements in the next release.
The new error output would look like this if you attempt to reference an attribute:

Error: Invalid depends_on reference

  on main.tf line 5, in resource "aws_lb" "foo":
   5:   depends_on = [aws_s3_bucket.lb-access-logs.id]
References in depends_on must be to a whole object (resource, etc), not to an
attribute of an object.

Since the "${} interpolation strings are no longer needed, and there shouldn't be any existing working configuration with that value, the exact case above shouldn't be encountered in the new version or by the upgrade tool.

@jbardin jbardin closed this as completed Mar 27, 2019
@dekimsey
Copy link
Contributor Author

That's perfect, thank you! I looked around and didn't see any mention of it.

@ghost
Copy link

ghost commented Aug 13, 2019

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 and limited conversation to collaborators Aug 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants