Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add template_ids to azuread_directory_roles #1011

Merged
merged 1 commit into from
Feb 21, 2023
Merged
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
Add template_ids to roles data source
alexwilcox9 committed Feb 15, 2023
commit 87faaa8a0a77d602205f604c661a10cefc4c829f
1 change: 1 addition & 0 deletions docs/data-sources/directory_roles.md
Original file line number Diff line number Diff line change
@@ -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.

---
12 changes: 12 additions & 0 deletions internal/services/directoryroles/directory_roles_data_source.go
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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...)