Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [Unreleased]

- Use the auto-generated OAS schema from elastic/kibana for the Fleet API. ([#834](https://github.com/elastic/terraform-provider-elasticstack/issues/834))
- Support description in `elasticstack_elasticsearch_security_role` data sources. ([#884](https://github.com/elastic/terraform-provider-elasticstack/pull/884))

## [0.11.11] - 2024-10-25

Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/elasticsearch_security_role.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ output "role" {

- `applications` (Set of Object) A list of application privilege entries. (see [below for nested schema](#nestedatt--applications))
- `cluster` (Set of String) A list of cluster privileges. These privileges define the cluster level actions that users with this role are able to execute.
- `description` (String) The description of the role.
- `global` (String) An object defining global privileges.
- `id` (String) Internal identifier of the resource
- `indices` (Set of Object) A list of indices permissions entries. (see [below for nested schema](#nestedatt--indices))
Expand Down
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
Loading