-
Notifications
You must be signed in to change notification settings - Fork 43
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
fix(constraints): ensure constraints are non-null #556
Conversation
99148bc
to
4a47025
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Base on the conventional commits, this should be a fix, not a chore. Please update the commit message and PR title.
This statement from the PR description is incorrect.
Since the constraints schema marks constraints as a computed field, this means if we insert null into state it will be considered uncomputed & on the next apply terraform will attempt to compute the constraints by setting them.
The plan listed in the QA steps should really have revision = 72
based on the juju deploy
step. Then:
$ terraform plan
juju_application.telegraf: Refreshing state... [id=test:telegraf]
No changes. Your infrastructure matches the configuration.
Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.
Yes thanks, I forgot that
How so?
I don't think so. This won't verify the bug reported (#466) will be fixed. The point of these QA steps are to verify that we can run a charm refresh on an imported subordinate. As we see above, if we set the revision to 72 in the plan no upgrade is run |
4a47025
to
253b365
Compare
Perhaps misleading is the word instead. In the reported but scenario, even if terraform didn't believe the computed value must be set, the Update method still would have been called and the equality check could have been false - leading to an incorrect attempt to set nil constraints. I still believe that
Thus even if the constraints come up with Unknown vs Null, vs EmptyString, the provider will no attempt to set them and cause havoc. It will also be a good reminder for the future of this type of problem. |
253b365
to
81ac502
Compare
Happy to apply this change. But it is actually impossible for constraints to be null or unknown here now, since So the only value this change will provide is documentary. Still valuable though! |
b999ee5
to
159ab0d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you for the updates.
/merge |
Fixes: juju#466 Juju does not distinguish between null constraints and empty-string constraints. However, null is not considered by terraform to be a computed value, whereas the empty string is. Since the constraints schema marks constraints as a computed field, this means if we insert null into state it will be considered uncomputed & on the next apply terraform will attempt to compute the constraints by setting them. This leads to bugs since subordinate applications cannot have constraints applied. Since we know that subordinate applications cannot have constraints, on Create or Read we can easily 'compute' the constraints ourselves as "".
159ab0d
to
fc09948
Compare
/merge |
Description
Fixes: #466
This bug is two-sided, stemming from the fact that Juju does not distinguish between null constraints and empty-string constraints. However, null is not considered by terraform to be a computed value, whereas the empty string is.
Since the constraints schema marks constraints as a computed field, this means if we insert null into state it will be considered unknown & will need to be set on the next
Update
call. Terraform signals this by passing value<unknown>
forstate.Constraints
through to Update, which is unequal to<null>
Our provider detects a difference between
<null>
and<unknown>
, so attempts to set the constraints on the application to "". This fails for subordinatesResolve this by:
Since we know that subordinate applications cannot have constraints, on Create or Read we can easily 'compute' the constraints ourselves as
""
instead of leaving asnull
.Changing the condition we set application constraints to not differentiate between
<null>
,<unknown>
and""
.Type of change
Environment
Juju controller version: 3.4.5
Terraform version: v1.9.5
QA steps
Manual QA steps should be done to test this PR.
^ notice that the apply runs successfully, and
constraints
do not appear as(known after compute)