Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions cloudstack/resource_cloudstack_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
82 changes: 79 additions & 3 deletions cloudstack/resource_cloudstack_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"},
},
},
})
Expand Down Expand Up @@ -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"
Expand Down
Loading