fix: implement Read/Update/Delete for stub resources#285
fix: implement Read/Update/Delete for stub resources#285kristofer-atlas wants to merge 5 commits into
Conversation
- Add Read, Update, Delete for account resource - Add Read, Update for disk_offering resource - Add Read, Delete for domain resource - Add Read for user resource
Add comprehensive and networking test configurations for validating the CloudStack Terraform Provider.
There was a problem hiding this comment.
Pull request overview
This PR implements previously stubbed CRUD functionality for several CloudStack Terraform provider resources to reduce state drift (notably for account/domain associations), and adds new Terraform configurations under tests/ for manual provider verification.
Changes:
- Implement
Read/Updateforcloudstack_account,cloudstack_domain,cloudstack_disk_offering, andcloudstack_user(plusDeletefor disk offering). - Adjust
cloudstack_accountschema to force recreation on immutable user/account fields. - Add new test configurations under
tests/comprehensiveandtests/networking(plus documentation) to exercise provider behavior.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/networking/variables.tf | Adds variables for the networking egress-rule test configuration. |
| tests/networking/terraform.tfvars.example | Example tfvars for the networking test suite. |
| tests/networking/main.tf | Networking test configuration demonstrating security group ingress + egress rules. |
| tests/comprehensive/versions.tf | Defines provider requirements for the comprehensive test suite. |
| tests/comprehensive/variables.tf | Adds variables for the comprehensive test suite inputs. |
| tests/comprehensive/terraform.tfvars.example | Example tfvars for the comprehensive test suite. |
| tests/comprehensive/main.tf | Comprehensive manual test configuration covering many resources. |
| tests/comprehensive/README.md | Documents the comprehensive manual test suite. |
| tests/README.md | Top-level documentation for running the manual test suites. |
| cloudstack/resource_cloudstack_user.go | Implements user Update and Read logic. |
| cloudstack/resource_cloudstack_domain.go | Implements domain Read and Update logic. |
| cloudstack/resource_cloudstack_disk_offering.go | Implements disk offering Read/Update/Delete and adds needed imports. |
| cloudstack/resource_cloudstack_account.go | Adds ForceNew to immutable fields and implements account Read/Update. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@kristofer-atlas We already have some tests here: https://github.com/apache/cloudstack-terraform-provider/blob/main/cloudstack/resource_cloudstack_disk_test.go How are the new tests helping us here? |
bcc0576 to
17fcf46
Compare
- Domain: add Computed+ForceNew to domain_id and parent_domain_id to fix perpetual diffs causing 19 acceptance test failures - Account: remove unnecessary ForceNew from email/first_name/last_name/ password; implement user-level updates via updateUser API; add Sensitive to password field - Disk offering: mark disk_size as ForceNew since updateDiskOffering does not support size changes - User: mark account and username as ForceNew to prevent silent drift; add Sensitive to password; wrap Update error with resource context - Remove tests/ directory (manual TF configs, not Go acceptance tests) which also fixes Apache RAT check failures from missing headers
|
@vishesh92, the intent of the tests was to be a sort of end-to-end test. Removed for now. Hadn't noticed the tests you point to. Wondering, though, whether we should have some sort of end-to-end tests similar tor what I had... In some cases I have had issues with create -> destroy -> recreate, where the destroy was incomplete, or some assumptions about state and lingering resources. |
| }, | ||
| "domain_id": { | ||
| Type: schema.TypeString, | ||
| Optional: true, |
|
@kristofer-atlas left some comments. |
Account resource: - Drop ForceNew on username; the username belongs to the user inside the account and is updatable via updateUser, so changing it should not recreate the account. - Make account_type Optional+Computed instead of Required+ForceNew. The account type is derived from the role and cannot be set directly through updateAccount, so it should track the role rather than force recreation. Create only sends account_type when explicitly configured. - Read/Update now select the managed user by username rather than User[0], so accounts with multiple users operate on the correct user. User resource: - Drop ForceNew on username and apply username changes via updateUser.
Follow-up from the review loop on the account resource: - Mark account and domain_id as Computed (in addition to Optional). Create defaults the account name to the username and the API resolves an omitted domain to the caller's domain; Read writes those server-side values back, which produced a perpetual diff whenever the fields were omitted. - Only send domainid to createAccount when one is configured, instead of passing an empty value. - Gate account_type on explicit presence in config via GetRawConfig so an explicit 0 (a valid account type) is honored while an omitted value stays role-derived; GetOk treats 0 as unset. - Drop the Read fallback to the first user; selecting an arbitrary user could bind state to the wrong user on multi-user accounts. - Guard the account rename so an empty new name is never sent.
|
@vishesh92, addressed your comments :) |
Implements the previously stubbed Read/Update/Delete functions for cloudstack_account, cloudstack_disk_offering, cloudstack_domain, and cloudstack_user, whose empty implementations caused state drift. It also addresses the review feedback: username is no longer ForceNew on the account and user resources (changes are applied via updateUser), account_type is now role-derived (Optional+Computed) since it cannot be set through updateAccount, account and domain_id on the account resource are marked Computed to avoid perpetual diffs, and Read/Update select the managed user by username instead of an arbitrary index. Passes make build and make test, and partially addresses #133 since the account domain association is now reflected through the Read function.