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

core: Specialized errors for incorrect indexes in resource reference #19727

Merged
merged 1 commit into from
Dec 20, 2018

Conversation

apparentlymart
Copy link
Contributor

@apparentlymart apparentlymart commented Dec 20, 2018

In prior versions of Terraform we permitted inconsistent use of indexes in resource references, but in as of 0.12 the index usage must correlate properly with whether count is set on the resource.

Since users are likely to have existing configurations with incorrect usage, here we introduce some specialized error messages for situations where we can detect such issues statically. This seems to cover all of the common patterns we've seen in practice.

Some usage patterns will fall back on a less-helpful dynamic error here, but no configurations coming from 0.11 can end up that way because 0.11 did not permit forms such as aws_instance.no_count[count.index].bar that this validation would not be able to "see".

Our configuration upgrade tool also contains a fix for this already, but it takes a more conservative approach of adding the index [0] rather than [count.index] because it can't be sure (without human help) if correlation of indices is what was intended.

This addresses #19216 in two ways:

  • It gives a more helpful error message for what is in practice a usage error rather than an evaluation error.
  • By implementing it as a static check, it will be returned even on the initial terraform apply in that example, whereas in alpha1 we'd catch it only after the resources were initially created and so we could see the incorrect "each mode" in state.

@apparentlymart apparentlymart added this to the v0.12.0 milestone Dec 20, 2018
@apparentlymart apparentlymart self-assigned this Dec 20, 2018
@apparentlymart apparentlymart requested a review from a team December 20, 2018 20:24
In prior versions of Terraform we permitted inconsistent use of indexes
in resource references, but in as of 0.12 the index usage must correlate
properly with whether "count" is set on the resource.

Since users are likely to have existing configurations with incorrect
usage, here we introduce some specialized error messages for situations
where we can detect such issues statically. This seems to cover all of the
common patterns we've seen in practice.

Some usage patterns will fall back on a less-helpful dynamic error here,
but no configurations coming from 0.11 can end up that way because 0.11
did not permit forms such as aws_instance.no_count[count.index].bar that
this validation would not be able to "see".

Our configuration upgrade tool also contains a fix for this already, but
it takes a more conservative approach of adding the index [1] rather than
[count.index] because it can't be sure (without human help) if correlation
of indices is what was intended.
@ghost
Copy link

ghost commented Jul 24, 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 Jul 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants