elasticstack_kibana_space: flag initials and color as optional-computed#606
Merged
tobio merged 2 commits intoelastic:mainfrom Apr 17, 2024
Merged
Conversation
Member
Author
|
@tobio, it looks like the failures are unrelated to my changes 🤷 |
tobio
reviewed
Apr 17, 2024
Member
There was a problem hiding this comment.
It would be nice if we could add a test case which covers this behaviour. I tried pushing this to this branch but GH wouldn't let me. This changes the update step to explicitly set the color, and then re-runs the plan without color set to check that it's not seen as a change.
in space_test.go
package kibana_test
import (
"fmt"
"testing"
"github.com/elastic/terraform-provider-elasticstack/internal/acctest"
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)
func TestAccResourceSpace(t *testing.T) {
spaceId := sdkacctest.RandStringFromCharSet(22, sdkacctest.CharSetAlphaNum)
resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
CheckDestroy: checkResourceSpaceDestroy,
ProtoV6ProviderFactories: acctest.Providers,
Steps: []resource.TestStep{
{
Config: testAccResourceSpaceCreate(spaceId),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("elasticstack_kibana_space.test_space", "space_id", spaceId),
resource.TestCheckResourceAttr("elasticstack_kibana_space.test_space", "name", fmt.Sprintf("Name %s", spaceId)),
resource.TestCheckResourceAttr("elasticstack_kibana_space.test_space", "description", "Test Space"),
),
},
{
Config: testAccResourceSpaceUpdate(spaceId),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("elasticstack_kibana_space.test_space", "space_id", spaceId),
resource.TestCheckResourceAttr("elasticstack_kibana_space.test_space", "name", fmt.Sprintf("Updated %s", spaceId)),
resource.TestCheckResourceAttr("elasticstack_kibana_space.test_space", "description", "Updated space description"),
resource.TestCheckTypeSetElemAttr("elasticstack_kibana_space.test_space", "disabled_features.*", "ingestManager"),
resource.TestCheckTypeSetElemAttr("elasticstack_kibana_space.test_space", "disabled_features.*", "enterpriseSearch"),
resource.TestCheckResourceAttr("elasticstack_kibana_space.test_space", "color", "#FFFFFF"),
),
},
{
Config: testAccResourceSpaceCreate(spaceId),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("elasticstack_kibana_space.test_space", "space_id", spaceId),
resource.TestCheckResourceAttr("elasticstack_kibana_space.test_space", "name", fmt.Sprintf("Name %s", spaceId)),
resource.TestCheckResourceAttr("elasticstack_kibana_space.test_space", "description", "Test Space"),
resource.TestCheckResourceAttr("elasticstack_kibana_space.test_space", "color", "#FFFFFF"),
),
},
},
})
}
func testAccResourceSpaceCreate(id string) string {
return fmt.Sprintf(`
provider "elasticstack" {
kibana {}
}
resource "elasticstack_kibana_space" "test_space" {
space_id = "%s"
name = "%s"
description = "Test Space"
}
`, id, fmt.Sprintf("Name %s", id))
}
func testAccResourceSpaceUpdate(id string) string {
return fmt.Sprintf(`
provider "elasticstack" {
kibana {}
}
resource "elasticstack_kibana_space" "test_space" {
space_id = "%s"
name = "%s"
description = "Updated space description"
disabled_features = ["ingestManager", "enterpriseSearch"]
color = "#FFFFFF"
}
`, id, fmt.Sprintf("Updated %s", id))
}
func checkResourceSpaceDestroy(s *terraform.State) error {
client, err := clients.NewAcceptanceTestingClient()
if err != nil {
return err
}
for _, rs := range s.RootModule().Resources {
if rs.Type != "elasticstack_kibana_space" {
continue
}
kibanaClient, err := client.GetKibanaClient()
if err != nil {
return err
}
res, err := kibanaClient.KibanaSpaces.Get(rs.Primary.ID)
if err != nil {
return err
}
if res != nil {
return fmt.Errorf("Space (%s) still exists", rs.Primary.ID)
}
}
return nil
}
CHANGELOG.md
Outdated
| ### Fixed | ||
|
|
||
| - Prevent a provider panic when an `elasticstack_elasticsearch_template` or `elasticstack_elasticsearch_component_template` includes an empty `template` (`template {}`) block. ([#598](https://github.com/elastic/terraform-provider-elasticstack/pull/598)) | ||
| - Prevent `elasticstack_kibana_space` to attempt the space recreation if `initials` and `color` are not provided. ([TODO](TODO)) |
tobio
approved these changes
Apr 17, 2024
Member
tobio
left a comment
There was a problem hiding this comment.
Lgtm 🎉 Thanks for fixing this one up.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When creating a space without specifying the optional
initialsandcolorfields, terraform always attempts to recreate the space, as it receives some server-generated values for those properties.This PR flags those fields as computed, at the same time as keeping them optional. According to hashicorp/terraform#21278, this is the way.