From 87faaa8a0a77d602205f604c661a10cefc4c829f Mon Sep 17 00:00:00 2001 From: Alex Wilcox Date: Wed, 15 Feb 2023 16:31:58 +0000 Subject: [PATCH] Add template_ids to roles data source --- docs/data-sources/directory_roles.md | 1 + .../directoryroles/directory_roles_data_source.go | 12 ++++++++++++ .../directory_roles_data_source_test.go | 2 ++ 3 files changed, 15 insertions(+) diff --git a/docs/data-sources/directory_roles.md b/docs/data-sources/directory_roles.md index 96539631f5..7e47e9a1ad 100644 --- a/docs/data-sources/directory_roles.md +++ b/docs/data-sources/directory_roles.md @@ -33,6 +33,7 @@ This data source does not have any arguments. The following attributes are exported: * `object_ids` - The object IDs of the roles. +* `template_ids` - The template IDs of the roles. * `roles` - A list of users. Each `role` object provides the attributes documented below. --- diff --git a/internal/services/directoryroles/directory_roles_data_source.go b/internal/services/directoryroles/directory_roles_data_source.go index 1ba5cbb7ce..9989e1c65c 100644 --- a/internal/services/directoryroles/directory_roles_data_source.go +++ b/internal/services/directoryroles/directory_roles_data_source.go @@ -33,6 +33,15 @@ func directoryRolesDataSource() *schema.Resource { }, }, + "template_ids": { + Description: "The template IDs of the roles", + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "roles": { Description: "A list of roles", Type: schema.TypeList, @@ -81,10 +90,12 @@ func directoryRolesDataSourceRead(ctx context.Context, d *schema.ResourceData, m } objectIds := make([]string, 0) + templateIds := make([]string, 0) roleList := make([]map[string]interface{}, 0) for _, r := range *directoryRoles { objectIds = append(objectIds, *r.ID()) + templateIds = append(templateIds, *r.RoleTemplateId) role := make(map[string]interface{}) role["description"] = r.Description @@ -104,6 +115,7 @@ func directoryRolesDataSourceRead(ctx context.Context, d *schema.ResourceData, m tf.Set(d, "roles", roleList) tf.Set(d, "object_ids", objectIds) + tf.Set(d, "template_ids", templateIds) return nil } diff --git a/internal/services/directoryroles/directory_roles_data_source_test.go b/internal/services/directoryroles/directory_roles_data_source_test.go index 696184b990..fc0c157656 100644 --- a/internal/services/directoryroles/directory_roles_data_source_test.go +++ b/internal/services/directoryroles/directory_roles_data_source_test.go @@ -29,6 +29,8 @@ func (DirectoryRolesDataSource) testCheckFunc(data acceptance.TestData, addition check.That(data.ResourceName).Key("roles.0.display_name").Exists(), check.That(data.ResourceName).Key("roles.0.object_id").Exists(), check.That(data.ResourceName).Key("roles.0.template_id").Exists(), + check.That(data.ResourceName).Key("object_ids.#").Exists(), + check.That(data.ResourceName).Key("template_ids.#").Exists(), } checks = append(checks, additionalChecks...) return resource.ComposeTestCheckFunc(checks...)