Skip to content

Commit

Permalink
Compute unconfigured hcp_group description (#844)
Browse files Browse the repository at this point in the history
Why:

* When an hcp_group description is not configured in a Terraform file,
  then Terraform returns an error about the state's value of null not
  matching the provider's return value of "".

This change addresses the need by:

* Add failing test for hcpi_group description not being configured.
* Fix test by configuring the hcp_group description attribute to be
  computed.

Fixes #841
  • Loading branch information
squaresurf authored May 21, 2024
1 parent 3c18883 commit f442a53
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .changelog/844.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
```release-note:bug
Cloud Platform: fix issue where hcp_group without a description would cause a state error
1 change: 1 addition & 0 deletions internal/provider/iam/resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ The user or service account that is running Terraform when creating an %s resour
},
"description": schema.StringAttribute{
Description: "The group's description - maximum length of 300 characters",
Computed: true,
Optional: true,
Validators: []validator.String{
stringvalidator.LengthBetween(0, 300),
Expand Down
18 changes: 18 additions & 0 deletions internal/provider/iam/resource_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ func TestAccGroupResource(t *testing.T) {
PreCheck: func() { acctest.PreCheck(t) },
CheckDestroy: testAccCheckGroupDestroy(t, groupName),
Steps: []resource.TestStep{
{
Config: testAccGroupConfigResourceWithoutDescription(groupName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("hcp_group.example", "display_name", groupName),
resource.TestCheckResourceAttr("hcp_group.example", "description", ""),
resource.TestCheckResourceAttrSet("hcp_group.example", "resource_name"),
resource.TestCheckResourceAttrSet("hcp_group.example", "resource_id"),
testAccGroupExists(t, "hcp_group.example", &group),
),
},
{
Config: testAccGroupConfigResource(groupName, description),
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -75,6 +85,14 @@ func testAccGroupConfigResource(displayName, description string) string {
`, displayName, description)
}

func testAccGroupConfigResourceWithoutDescription(displayName string) string {
return fmt.Sprintf(`
resource "hcp_group" "example" {
display_name = %q
}
`, displayName)
}

// testAccGroupsExists queries the API and retrieves the matching
// group.
func testAccGroupExists(t *testing.T, resourceName string, sp *models.HashicorpCloudIamGroup) resource.TestCheckFunc {
Expand Down

0 comments on commit f442a53

Please sign in to comment.