-
Notifications
You must be signed in to change notification settings - Fork 21
Set attribute defaults conditionally #259
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
base: main
Are you sure you want to change the base?
Conversation
83e1780
to
cdda6cd
Compare
This should cover all occurrences of this bug in the provider. I made a few extra changes:
@maveonair Let me know what you think! |
cdda6cd
to
f3e75d0
Compare
Nice!
LGTM and I am looking forward to review the pull request when it is ready. |
Tests are failing because of this bug: lxc/incus#2185 |
f3e75d0
to
d3d2e82
Compare
Signed-off-by: Wim de With <[email protected]>
d3d2e82
to
09ecc61
Compare
The CI failure appears unrelated to my changes; test failures are all in code I didn't touch in this PR. |
Signed-off-by: Wim de With <[email protected]>
Signed-off-by: Wim de With <[email protected]>
Signed-off-by: Wim de With <[email protected]>
Signed-off-by: Wim de With <[email protected]>
Signed-off-by: Wim de With <[email protected]>
Signed-off-by: Wim de With <[email protected]>
Signed-off-by: Wim de With <[email protected]>
Signed-off-by: Wim de With <[email protected]>
09ecc61
to
be031cd
Compare
I've reordered the commits so that the tests come after the changes to the code to prevent commits with failing tests on main. It's now ready for review. |
Rationale
(Based on discoveries in #257.)
When importing resources from backup files (or an ISO file in case of storage volumes) or copying them from existing resources, Incus and therefore the provider will determine ('compute' in Terraform terms) a number of attributes from the source file or resource, instead of the Terraform configuration. In the current state of the provider, this leads to two problems:
config
) together with thesource_file
(orsource_volume
, etc.) in their configuration. When the provider then 'computes' these attributes based on the source, their values may not match the user's configuration. This leads to errors such as the following.Solving the first problem is straightforward: we can just make the offending attributes mutually exclusive with
source_file
(orsource_volume
, etc.) withvalidators.ConflictsWith
.The second problem is unfortunately harder to solve. We have to remove the defaults from the attributes and only set them if
source_file
(orsource_volume
, etc.) are not specified. There are broadly two ways to achieve this, as far as I can see:source_file
(orsource_volume
, etc.) are not configured. This is the solution I went with in this PR. One small disadvantage is that plan modifiers need to be implemented per attribute type, so there is some duplication.TODO
incus_storage_volume
.incus_storage_volume
.source_file
source_volume
incus_storage_bucket
incus_image
incus_instance