Skip to content

Commit

Permalink
fix elasticstack_kibana_security_role tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mholttech committed Aug 22, 2024
1 parent e42addc commit dbc18d4
Showing 1 changed file with 56 additions and 10 deletions.
66 changes: 56 additions & 10 deletions internal/kibana/role_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import (

"github.com/elastic/terraform-provider-elasticstack/internal/acctest"
"github.com/elastic/terraform-provider-elasticstack/internal/utils"
"github.com/elastic/terraform-provider-elasticstack/internal/versionutils"
"github.com/hashicorp/go-version"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccDataSourceKibanaSecurityRole(t *testing.T) {
minSupportedRemoteIndicesVersion := version.Must(version.NewSemver("8.10.0"))
resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProtoV6ProviderFactories: acctest.Providers,
Expand All @@ -24,6 +27,22 @@ func TestAccDataSourceKibanaSecurityRole(t *testing.T) {
utils.TestCheckResourceListAttr("data.elasticstack_kibana_security_role.test", "kibana.0.spaces", []string{"default"}),
),
},
{
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minSupportedRemoteIndicesVersion),
Config: testAccDataSourceSecurityRoleRemoteIndices,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.elasticstack_kibana_security_role.test", "name", "data_source_test2"),
resource.TestCheckNoResourceAttr("data.elasticstack_kibana_security_role.test", "kibana.0.feature.#"),
resource.TestCheckNoResourceAttr("data.elasticstack_kibana_security_role.test", "elasticsearch.0.indices.0.field_security.#"),
utils.TestCheckResourceListAttr("data.elasticstack_kibana_security_role.test", "elasticsearch.0.run_as", []string{"elastic", "kibana"}),
utils.TestCheckResourceListAttr("data.elasticstack_kibana_security_role.test", "kibana.0.base", []string{"all"}),
utils.TestCheckResourceListAttr("data.elasticstack_kibana_security_role.test", "kibana.0.spaces", []string{"default"}),
utils.TestCheckResourceListAttr("data.elasticstack_kibana_security_role.test", "elasticsearch.0.remote_indices.0.clusters", []string{"test-cluster"}),
utils.TestCheckResourceListAttr("data.elasticstack_kibana_security_role.test", "elasticsearch.0.remote_indices.0.field_security.0.grant", []string{"sample"}),
utils.TestCheckResourceListAttr("data.elasticstack_kibana_security_role.test", "elasticsearch.0.remote_indices.0.names", []string{"sample"}),
utils.TestCheckResourceListAttr("data.elasticstack_kibana_security_role.test", "elasticsearch.0.remote_indices.0.privileges", []string{"create", "read", "write"}),
),
},
},
})
}
Expand All @@ -43,16 +62,43 @@ resource "elasticstack_kibana_security_role" "test" {
names = ["sample"]
privileges = ["create", "read", "write"]
}
// TODO: Move this to version constraint
// remote_indices {
// clusters = ["test-cluster"]
// field_security {
// grant = ["sample"]
// except = []
// }
// names = ["sample"]
// privileges = ["create", "read", "write"]
// }
run_as = ["kibana", "elastic"]
}
kibana {
base = [ "all" ]
spaces = ["default"]
}
}
data "elasticstack_kibana_security_role" "test" {
name = elasticstack_kibana_security_role.test.name
}
`

const testAccDataSourceSecurityRoleRemoteIndices = `
provider "elasticstack" {
elasticsearch {}
kibana {}
}
resource "elasticstack_kibana_security_role" "test" {
name = "data_source_test2"
elasticsearch {
cluster = [ "create_snapshot" ]
indices {
names = ["sample"]
privileges = ["create", "read", "write"]
}
remote_indices {
clusters = ["test-cluster"]
field_security {
grant = ["sample"]
except = []
}
names = ["sample"]
privileges = ["create", "read", "write"]
}
run_as = ["kibana", "elastic"]
}
kibana {
Expand Down

0 comments on commit dbc18d4

Please sign in to comment.