-
Notifications
You must be signed in to change notification settings - Fork 119
elasticstack_kibana_space
: flag initials
and color
as optional-computed
#606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@tobio, it looks like the failures are unrelated to my changes 🤷 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you fixup the link here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm 🎉 Thanks for fixing this one up.
When creating a space without specifying the optional
initials
andcolor
fields, 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.