Skip to content

Commit

Permalink
Support description in role data source
Browse files Browse the repository at this point in the history
  • Loading branch information
tobio committed Oct 28, 2024
1 parent 78faa31 commit cc1beb8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/elasticsearch/security/role_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ func DataSourceRole() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"description": {
Description: "The description of the role.",
Type: schema.TypeString,
Computed: true,
},
"applications": {
Description: "A list of application privilege entries.",
Type: schema.TypeSet,
Expand Down
52 changes: 52 additions & 0 deletions internal/elasticsearch/security/role_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ func TestAccDataSourceSecurityRole(t *testing.T) {
resource.TestCheckTypeSetElemAttr("data.elasticstack_elasticsearch_security_role.test", "remote_indices.*.names.*", "sample2"),
),
},
{
Config: testAccDataSourceSecurityRoleWithDescription,
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minSupportedDescriptionVersion),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.elasticstack_elasticsearch_security_role.test", "name", "data_source_test"),
resource.TestCheckTypeSetElemAttr("data.elasticstack_elasticsearch_security_role.test", "cluster.*", "all"),
utils.TestCheckResourceListAttr("data.elasticstack_elasticsearch_security_role.test", "indices.0.names", []string{"index1", "index2"}),
resource.TestCheckTypeSetElemAttr("data.elasticstack_elasticsearch_security_role.test", "indices.0.privileges.*", "all"),
resource.TestCheckResourceAttr("data.elasticstack_elasticsearch_security_role.test", "indices.0.allow_restricted_indices", "true"),
resource.TestCheckResourceAttr("data.elasticstack_elasticsearch_security_role.test", "applications.0.application", "myapp"),
utils.TestCheckResourceListAttr("data.elasticstack_elasticsearch_security_role.test", "applications.0.privileges", []string{"admin", "read"}),
resource.TestCheckTypeSetElemAttr("data.elasticstack_elasticsearch_security_role.test", "applications.0.resources.*", "*"),
resource.TestCheckTypeSetElemAttr("data.elasticstack_elasticsearch_security_role.test", "run_as.*", "other_user"),
resource.TestCheckResourceAttr("data.elasticstack_elasticsearch_security_role.test", "metadata", `{"version":1}`),
resource.TestCheckResourceAttr("data.elasticstack_elasticsearch_security_role.test", "description", `Test data source`),
),
},
},
})
}
Expand Down Expand Up @@ -86,6 +103,41 @@ data "elasticstack_elasticsearch_security_role" "test" {
}
`

const testAccDataSourceSecurityRoleWithDescription = `
provider "elasticstack" {
elasticsearch {}
}
resource "elasticstack_elasticsearch_security_role" "test" {
name = "data_source_test"
cluster = ["all"]
indices {
names = ["index1", "index2"]
privileges = ["all"]
allow_restricted_indices = true
}
applications {
application = "myapp"
privileges = ["admin", "read"]
resources = ["*"]
}
run_as = ["other_user"]
metadata = jsonencode({
version = 1
})
description = "Test data source"
}
data "elasticstack_elasticsearch_security_role" "test" {
name = elasticstack_elasticsearch_security_role.test.name
}
`

const testAccDataSourceSecurityRoleRemoteIndices = `
provider "elasticstack" {
elasticsearch {}
Expand Down

0 comments on commit cc1beb8

Please sign in to comment.