diff --git a/internal/elasticsearch/security/role_data_source.go b/internal/elasticsearch/security/role_data_source.go index fe8933a8..3b2ffc29 100644 --- a/internal/elasticsearch/security/role_data_source.go +++ b/internal/elasticsearch/security/role_data_source.go @@ -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, diff --git a/internal/elasticsearch/security/role_data_source_test.go b/internal/elasticsearch/security/role_data_source_test.go index 33778129..1fbebe70 100644 --- a/internal/elasticsearch/security/role_data_source_test.go +++ b/internal/elasticsearch/security/role_data_source_test.go @@ -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`), + ), + }, }, }) } @@ -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 {}