Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #556 from jack-w-shaw/JUJU-6545_ensure_constraints
#556 ## 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. 1) 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>` for `state.Constraints` through to Update, which is unequal to `<null>` 2) Our provider detects a difference between `<null>` and `<unknown>`, so attempts to set the constraints on the application to "". This fails for subordinates Resolve this by: 1) Since we know that subordinate applications cannot have constraints, on Create or Read we can easily 'compute' the constraints ourselves as `""` instead of leaving as `null`. 2) Changing the condition we set application constraints to not differentiate between `<null>`, `<unknown>` and `""`. ## Type of change - Bug fix (non-breaking change which fixes an issue) ## Environment - Juju controller version: 3.4.5 - Terraform version: v1.9.5 ## QA steps Manual QA steps should be done to test this PR. ```tf provider juju {} resource "juju_application" "telegraf" { name = "telegraf" model = "test" charm { name = "telegraf" revision = 75 } units = 0 } ``` ``` $ juju bootstrap lxd $ juju add-model test $ juju deploy ubuntu $ juju deploy telegraf --revision=72 --channel=latest/stable $ juju relate ubuntu telegraf # Wait for active/idle status on the two charms $ terraform init $ terraform import juju_application.telegraf test:telegraf $ terraform apply juju_application.telegraf: Refreshing state... [id=m:telegraf] Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: ~ update in-place Terraform will perform the following actions: # juju_application.telegraf will be updated in-place ~ resource "juju_application" "telegraf" { id = "m:telegraf" name = "telegraf" + principal = (known after apply) + storage = (known after apply) # (4 unchanged attributes hidden) ~ charm { name = "telegraf" ~ revision = 73 -> 75 # (3 unchanged attributes hidden) } } Plan: 0 to add, 1 to change, 0 to destroy. Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: yes juju_application.telegraf: Modifying... [id=m:telegraf] juju_application.telegraf: Modifications complete after 1s [id=m:telegraf] Apply complete! Resources: 0 added, 1 changed, 0 destroyed. ``` ^ notice that the apply runs successfully, and `constraints` do not appear as `(known after compute)`
- Loading branch information