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: Error message for unknown error_message in variable validation #35400

Merged
merged 1 commit into from
Jul 11, 2024

Conversation

apparentlymart
Copy link
Contributor

@apparentlymart apparentlymart commented Jun 28, 2024

In cases where the condition is known but the error_message is not, we were previously returning the generic error about the error message not being evaluable.

This is an interim change to give better feedback for the unfortunate situation described in #35397, so we can give authors better guidance in the meantime while we're designing a better solution.

In the long run we'll want to do something better here to minimize the chances of this situation arising -- reporting an error that we don't know how to describe is a poor user experience. But for now this at least acknowledges that an unknown value is the problem, and annotates the error message with the "caused by unknown" marking so that the UI will specify which of the contributing values was unknown.

╷
│ Error: Invalid error message
│ 
│   on child/validation-error-message-vars-child.tf line 11, in variable "test_input":
│   11:     error_message = var.error_message
│     ├────────────────
│     │ var.error_message is a string, known only after apply
│ 
│ Unsuitable value for error message: expression refers to values that won't be
│ known until the apply phase.
╵

(In this particular case the message is not fully accurate: var.error_message would be known during the plan phase, but isn't yet known during the validation phase. However, I've written it this way in anticipation of a future solution to #35397 that would avoid this error message being returned for anything that is unknown during the validate phase but yet would be known during the planning phase.)

…tion

In cases where the "condition" is known but the "error_message" is not,
we were previously returning the generic error about the error message
not being evaluable.

In the long run we'll want to do something better here to minimize the
chances of this situation arising -- reporting an error that we don't
know how to describe is a poor user experience -- but this is a temporary
intervention to at least make the error message more relevant in the
meantime, while we design how Terraform actually ought to behave in this
awkward situation.
@apparentlymart apparentlymart merged commit eb7f58c into main Jul 11, 2024
10 checks passed
Copy link

Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch.

@apparentlymart
Copy link
Contributor Author

Oh, whoops... this should have had the v1.9 backport label on it before I merged it. I'll manually prepare a backport branch in a little while and push that up for review too.

Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, 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 Aug 23, 2024
This pull request was closed.
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