Skip to content

test: add project display_text compatibility and import coverage - #335

Open
dheeraj12347 wants to merge 4 commits into
apache:mainfrom
dheeraj12347:investigate-pr-332
Open

test: add project display_text compatibility and import coverage#335
dheeraj12347 wants to merge 4 commits into
apache:mainfrom
dheeraj12347:investigate-pr-332

Conversation

@dheeraj12347

Copy link
Copy Markdown

Summary

Add acceptance coverage for the cloudstack_project display_text migration and fix an import-state compatibility issue discovered during testing.

The existing resource supports the new snake_case display_text field while retaining the deprecated displaytext field for backwards compatibility. These changes exercise both paths against the CloudStack simulator and verify that existing project behavior remains intact.

Changes

  • Add an acceptance test for projects configured with display_text.
  • Add acceptance coverage for precedence when both display_text and deprecated displaytext are configured.
  • Verify updating the effective display_text value.
  • Fix Read() state handling for cases where neither display-text field is present in configuration, such as resource import.
  • Preserve the legacy displaytext state representation in that case to avoid an import-state mismatch.

Validation

The complete cloudstack_project acceptance test suite passes:

  • TestAccCloudStackProject_basic
  • TestAccCloudStackProject_displayText
  • TestAccCloudStackProject_displayTextPrecedence
  • TestAccCloudStackProject_update
  • TestAccCloudStackProject_import
  • TestAccCloudStackProject_account
  • TestAccCloudStackProject_updateAccount
  • TestAccCloudStackProject_emptyDisplayText
  • TestAccCloudStackProject_updateUserid
  • TestAccCloudStackProject_updateAccountid
  • TestAccCloudStackProject_list

Result: 11/11 passing

Also verified with:

make test
git diff --check

Both pass successfully.

Regression found during validation

The initial full acceptance run exposed an import-state mismatch where the imported resource contained displaytext while the provider read populated display_text.

The Read() logic was adjusted to distinguish between:

  1. legacy displaytext configurations,
  2. new display_text configurations, and
  3. imported resources where neither field is configured.

The import acceptance test now passes without affecting the existing project acceptance tests.

sudo87 and others added 4 commits August 28, 2026 15:46
CloudStack's updateStorageNetworkIpRange API validates a new IP range
against the record's own current start/end IPs without excluding the
record being updated, so any in-place edit of these fields fails with
a self-overlap error (errorcode 530). Switching the update call to
only send changed fields (d.HasChange instead of d.GetOk) did not
help — the failure is identical even when only the genuinely-changed
field is sent, confirming this is a server-side validation bug rather
than something the provider can work around.

Mark these fields ForceNew so the plan matches reality: Terraform now
proposes a replacement instead of an update that is guaranteed to
fail. Reproduced and reverified against ACS 4.23.0.0.
Investigated the reported destroy+recreate-on-import issue (apache#305): the
importer's resulting state is actually fully hydrated correctly, because
Terraform automatically calls Read (visible as "Refreshing state...")
right after the custom importer function runs, which overwrites whatever
partial state the importer itself set. So populating cpu_number/cpu_speed/
memory inside resourceCloudStackServiceOfferingImport would be a no-op —
verified by importing a real lab offering with the unmodified importer and
confirming cpu_number/cpu_speed/memory were already correct in state.

The actual destroy+recreate happens because Terraform diffs the *config*
(which a minimal post-import .tf typically leaves blank for these fields)
against the now-correct state; since these fields are ForceNew, the
config's implicit zero value differs from the real value and forces
replacement. This is a doc/workflow gap, not a code bug: documented that
all ForceNew fields must be fully specified in config after import.
Verified empty terraform plan after import with a fully-specified config,
and unchanged (still-forcing) plan with a minimal one, matching this
explanation.
…splaytext

Every other resource in this provider uses display_text; cloudstack_project
was the outlier still on displaytext, even though its own docs already
described display_text as the field name. Add display_text additively
(displaytext is a real field in existing users' state files and can't be
renamed outright) and mark displaytext Deprecated. Create/Update/Read
resolve the effective value via projectDisplayText(), preferring
display_text when both are set.

Read only refreshes whichever of the two fields is actually in use (config
already had displaytext set and display_text unset), matching the existing
conditional pattern this file already uses for account/accountid/userid.
Setting both unconditionally caused a permanent diff for display_text-only
configs, since Read would keep populating the deprecated field the config
never referenced.

Verified against the lab with two standalone configs (one using
display_text, one using the legacy displaytext) against a locally-built
dev-override binary: both create cleanly, both produce an empty
terraform plan, and the legacy field shows the expected deprecation
warning. Both test projects destroyed after verification.
@dheeraj12347

Copy link
Copy Markdown
Author

Hi @sudo87 and @DaanHoogland , I’ve added a follow-up contribution in PR #335 for the cloudstack_project display_text migration.

I focused on validating the compatibility behavior introduced by the new display_text field:

Added acceptance coverage for configurations using display_text.
Added coverage for the case where both display_text and deprecated displaytext are configured, verifying that display_text takes precedence.
Added update coverage for the effective display-text value.
During the full acceptance run, I found an import-state mismatch where Read() populated display_text while an imported resource expected the legacy displaytext representation.
Adjusted the Read() state handling to distinguish between legacy configuration, new display_text configuration, and imported resources where neither field is configured.
Re-ran the complete cloudstack_project acceptance suite: all 11 tests pass.
Also verified make test and git diff --check.

The follow-up changes are in commit 37ebc48 on the PR. I’d appreciate your review and any feedback on whether you’d prefer the import compatibility handling or test structure to be adjusted further.

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.

2 participants