From 8da2248bc76052b831fde27bf2057b1968f199f6 Mon Sep 17 00:00:00 2001 From: dheeraj12347 Date: Tue, 1 Sep 2026 14:18:35 +0000 Subject: [PATCH] test: cover project display_text compatibility --- cloudstack/resource_cloudstack_project.go | 16 +++- .../resource_cloudstack_project_test.go | 82 ++++++++++++++++++- 2 files changed, 91 insertions(+), 7 deletions(-) diff --git a/cloudstack/resource_cloudstack_project.go b/cloudstack/resource_cloudstack_project.go index db004af1..58092804 100644 --- a/cloudstack/resource_cloudstack_project.go +++ b/cloudstack/resource_cloudstack_project.go @@ -358,10 +358,18 @@ func resourceCloudStackProjectRead(d *schema.ResourceData, meta any) error { d.Set("name", project.Name) d.Set("domain", project.Domain) - // Both fields are Computed, so setting both unconditionally reflects the - // API value without creating a diff for a config that only sets one. - d.Set("displaytext", project.Displaytext) - d.Set("display_text", project.Displaytext) + // Only refresh whichever of displaytext (deprecated) / display_text the + // config is actually using, so a config that only sets one of them + // doesn't see a perpetual diff on the other. + _, legacyFieldConfigured := d.GetOk("displaytext") + _, newFieldConfigured := d.GetOk("display_text") + + if legacyFieldConfigured { + d.Set("displaytext", project.Displaytext) + } + if newFieldConfigured { + d.Set("display_text", project.Displaytext) + } // Handle owner information more safely // Only set the account, accountid, and userid if they were explicitly set in the configuration diff --git a/cloudstack/resource_cloudstack_project_test.go b/cloudstack/resource_cloudstack_project_test.go index b4d60c89..5b23d7aa 100644 --- a/cloudstack/resource_cloudstack_project_test.go +++ b/cloudstack/resource_cloudstack_project_test.go @@ -51,6 +51,63 @@ func TestAccCloudStackProject_basic(t *testing.T) { }) } +func TestAccCloudStackProject_displayText(t *testing.T) { + var project cloudstack.Project + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCloudStackProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCloudStackProject_displayText, + Check: resource.ComposeTestCheckFunc( + testAccCheckCloudStackProjectExists( + "cloudstack_project.foo", &project), + resource.TestCheckResourceAttr( + "cloudstack_project.foo", "name", "terraform-test-project-display-text"), + resource.TestCheckResourceAttr( + "cloudstack_project.foo", "display_text", "Terraform Test Project Display Text"), + ), + }, + }, + }) +} + +func TestAccCloudStackProject_displayTextMigration(t *testing.T) { + var project cloudstack.Project + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCloudStackProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCloudStackProject_displayTextLegacy, + Check: resource.ComposeTestCheckFunc( + testAccCheckCloudStackProjectExists( + "cloudstack_project.foo", &project), + resource.TestCheckResourceAttr( + "cloudstack_project.foo", "name", "terraform-test-project-display-text-migration"), + resource.TestCheckResourceAttr( + "cloudstack_project.foo", "displaytext", "Old Display Text"), + ), + }, + { + Config: testAccCloudStackProject_displayTextMigration, + Check: resource.ComposeTestCheckFunc( + testAccCheckCloudStackProjectExists( + "cloudstack_project.foo", &project), + resource.TestCheckResourceAttr( + "cloudstack_project.foo", "name", "terraform-test-project-display-text-migration"), + resource.TestCheckResourceAttr( + "cloudstack_project.foo", "display_text", "New Display Text"), + ), + }, + }, + }) +} + func TestAccCloudStackProject_update(t *testing.T) { var project cloudstack.Project @@ -95,9 +152,10 @@ func TestAccCloudStackProject_import(t *testing.T) { Config: testAccCloudStackProject_basic, }, { - ResourceName: "cloudstack_project.foo", - ImportState: true, - ImportStateVerify: true, + ResourceName: "cloudstack_project.foo", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"displaytext", "display_text"}, }, }, }) @@ -406,6 +464,24 @@ resource "cloudstack_project" "foo" { displaytext = "Terraform Test Project" }` +const testAccCloudStackProject_displayText = ` +resource "cloudstack_project" "foo" { + name = "terraform-test-project-display-text" + display_text = "Terraform Test Project Display Text" +}` + +const testAccCloudStackProject_displayTextLegacy = ` +resource "cloudstack_project" "foo" { + name = "terraform-test-project-display-text-migration" + displaytext = "Old Display Text" +}` + +const testAccCloudStackProject_displayTextMigration = ` +resource "cloudstack_project" "foo" { + name = "terraform-test-project-display-text-migration" + display_text = "New Display Text" +}` + const testAccCloudStackProject_update = ` resource "cloudstack_project" "foo" { name = "terraform-test-project-updated"