Skip to content

fix: implement Read/Update/Delete for stub resources#285

Open
kristofer-atlas wants to merge 5 commits into
apache:mainfrom
RunAtlas-is:feature/stub-resource-fixes
Open

fix: implement Read/Update/Delete for stub resources#285
kristofer-atlas wants to merge 5 commits into
apache:mainfrom
RunAtlas-is:feature/stub-resource-fixes

Conversation

@kristofer-atlas

@kristofer-atlas kristofer-atlas commented Mar 9, 2026

Copy link
Copy Markdown

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.

- 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.
Comment thread cloudstack/resource_cloudstack_account.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/Update for cloudstack_account, cloudstack_domain, cloudstack_disk_offering, and cloudstack_user (plus Delete for disk offering).
  • Adjust cloudstack_account schema to force recreation on immutable user/account fields.
  • Add new test configurations under tests/comprehensive and tests/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.

Comment thread cloudstack/resource_cloudstack_domain.go
Comment thread cloudstack/resource_cloudstack_disk_offering.go
Comment thread cloudstack/resource_cloudstack_user.go
Comment thread cloudstack/resource_cloudstack_user.go
Comment thread cloudstack/resource_cloudstack_account.go
Comment thread tests/comprehensive/versions.tf Outdated
Comment thread tests/comprehensive/main.tf Outdated
Comment thread tests/comprehensive/main.tf Outdated
@vishesh92

Copy link
Copy Markdown
Member

@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?

@kristofer-atlas kristofer-atlas force-pushed the feature/stub-resource-fixes branch from bcc0576 to 17fcf46 Compare March 10, 2026 22:04
- 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
@kristofer-atlas

Copy link
Copy Markdown
Author

@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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

},
"domain_id": {
Type: schema.TypeString,
Optional: true,
Comment thread cloudstack/resource_cloudstack_account.go Outdated
Comment thread cloudstack/resource_cloudstack_account.go Outdated
Comment thread cloudstack/resource_cloudstack_account.go
Comment thread cloudstack/resource_cloudstack_account.go Outdated
Comment thread cloudstack/resource_cloudstack_account.go Outdated
Comment thread cloudstack/resource_cloudstack_user.go Outdated
Comment thread cloudstack/resource_cloudstack_user.go
@vishesh92

Copy link
Copy Markdown
Member

@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.
@kristofer-atlas

Copy link
Copy Markdown
Author

@vishesh92, addressed your comments :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants