-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package datadog | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func dataSourceDatadogPermissions() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceDatadogPermissionsRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
// Computed values | ||
"permissions": { | ||
Type: schema.TypeMap, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceDatadogPermissionsRead(d *schema.ResourceData, meta interface{}) error { | ||
providerConf := meta.(*ProviderConfiguration) | ||
datadogClientV2 := providerConf.DatadogClientV2 | ||
authV2 := providerConf.AuthV2 | ||
|
||
res, _, err := datadogClientV2.RolesApi.ListPermissions(authV2).Execute() | ||
if err != nil { | ||
return translateClientError(err, "error querying roles") | ||
} | ||
perms := res.GetData() | ||
permsNameToID := make(map[string]string, len(perms)) | ||
for _, perm := range perms { | ||
permsNameToID[perm.Attributes.GetName()] = perm.GetId() | ||
} | ||
d.Set("permissions", permsNameToID) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
page_title: "datadog_role" | ||
--- | ||
|
||
# datadog_permissions Data Source | ||
|
||
Use this data source to retrieve the list of Datadog permissions by name and their corresponding ID, for use in the role resource. | ||
|
||
## Example Usage | ||
|
||
``` | ||
data "datadog_permissions" "permissions" {} | ||
``` | ||
|
||
## Attributes Reference | ||
|
||
- `permissions`: Map of permissions names to their corresponding ID. |