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

(GH-919) Update role permission and permissions documentation #963

Merged
merged 2 commits into from
May 27, 2024
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
54 changes: 54 additions & 0 deletions docs/resources/role_permission.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,50 @@ With this resource, you can manage role permissions (1-1).
permissions assigned to a role. To avoid potential issues, it is recommended not to use this resource in conjunction
with the `auth0_role_permissions` resource when managing permissions for the same role id.

## Example Usage

```terraform
# Example:
resource "auth0_resource_server" "resource_server" {
name = "test"
identifier = "test.example.com"
}

resource "auth0_resource_server_scopes" "resource_server_scopes" {
resource_server_identifier = auth0_resource_server.resource_server.identifier

scopes {
name = "store:create"
}
scopes {
name = "store:read"
}
scopes {
name = "store:update"
}
scopes {
name = "store:delete"
}
}

resource "auth0_role" "my_role" {
name = "My Role"
}

locals {
scopesList = [
for scope in auth0_resource_server_scopes.resource_server_scopes.scopes : scope.name
]
}

resource "auth0_role_permission" "my_role_perm" {
for_each = toset(local.scopesList)

role_id = auth0_role.my_role.id
resource_server_identifier = auth0_resource_server.resource_server.identifier
permission = each.value
}
```

<!-- schema generated by tfplugindocs -->
## Schema
Expand All @@ -29,4 +72,15 @@ with the `auth0_role_permissions` resource when managing permissions for the sam
- `id` (String) The ID of this resource.
- `resource_server_name` (String) Name of the resource server that the permission is associated with.

## Import

Import is supported using the following syntax:

```shell
# This resource can be imported by specifying the
# role ID, resource identifier, and permission name separated by "::" (note the double colon)
# <roleID>::<resourceServerIdentifier>::<permission>
#
# Example:
terraform import auth0_role_permission.permission "rol_XXXXXXXXXXXXX::https://example.com::read:foo"
```
51 changes: 50 additions & 1 deletion docs/resources/role_permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,47 @@ With this resource, you can manage role permissions (1-many).
appends a permission to a role. To avoid potential issues, it is recommended not to use this resource in conjunction
with the `auth0_role_permission` resource when managing permissions for the same role id.


## Example Usage

```terraform
# Example:
resource "auth0_resource_server" "resource_server" {
name = "test"
identifier = "test.example.com"
}
resource "auth0_resource_server_scopes" "resource_server_scopes" {
resource_server_identifier = auth0_resource_server.resource_server.identifier

scopes {
name = "store:create"
}
scopes {
name = "store:read"
}
scopes {
name = "store:update"
}
scopes {
name = "store:delete"
}
}

resource "auth0_role" "my_role" {
name = "My Role"
}

resource "auth0_role_permissions" "my_role_perms" {
role_id = auth0_role.my_role.id

dynamic "permissions" {
for_each = auth0_resource_server_scopes.resource_server_scopes.scopes
content {
name = permissions.value.name
resource_server_identifier = auth0_resource_server.resource_server.identifier
}
}
}
```

<!-- schema generated by tfplugindocs -->
## Schema
Expand All @@ -39,4 +79,13 @@ Read-Only:
- `description` (String) Description of the permission.
- `resource_server_name` (String) Name of resource server that the permission is associated with.

## Import

Import is supported using the following syntax:

```shell
# This resource can be imported by specifying the role ID
#
# Example:
terraform import auth0_role_permissions.all_role_permissions "rol_XXXXXXXXXXXX"
```
6 changes: 6 additions & 0 deletions examples/resources/auth0_role_permission/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This resource can be imported by specifying the
# role ID, resource identifier, and permission name separated by "::" (note the double colon)
# <roleID>::<resourceServerIdentifier>::<permission>
#
# Example:
terraform import auth0_role_permission.permission "rol_XXXXXXXXXXXXX::https://example.com::read:foo"
40 changes: 40 additions & 0 deletions examples/resources/auth0_role_permission/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Example:
resource "auth0_resource_server" "resource_server" {
developerkunal marked this conversation as resolved.
Show resolved Hide resolved
name = "test"
identifier = "test.example.com"
}

resource "auth0_resource_server_scopes" "resource_server_scopes" {
resource_server_identifier = auth0_resource_server.resource_server.identifier

scopes {
name = "store:create"
}
scopes {
name = "store:read"
}
scopes {
name = "store:update"
}
scopes {
name = "store:delete"
}
}

resource "auth0_role" "my_role" {
name = "My Role"
}

locals {
scopesList = [
for scope in auth0_resource_server_scopes.resource_server_scopes.scopes : scope.name
]
}

resource "auth0_role_permission" "my_role_perm" {
for_each = toset(local.scopesList)

role_id = auth0_role.my_role.id
resource_server_identifier = auth0_resource_server.resource_server.identifier
permission = each.value
}
4 changes: 4 additions & 0 deletions examples/resources/auth0_role_permissions/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This resource can be imported by specifying the role ID
#
# Example:
terraform import auth0_role_permissions.all_role_permissions "rol_XXXXXXXXXXXX"
37 changes: 37 additions & 0 deletions examples/resources/auth0_role_permissions/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Example:
resource "auth0_resource_server" "resource_server" {
developerkunal marked this conversation as resolved.
Show resolved Hide resolved
name = "test"
identifier = "test.example.com"
}
resource "auth0_resource_server_scopes" "resource_server_scopes" {
resource_server_identifier = auth0_resource_server.resource_server.identifier

scopes {
name = "store:create"
}
scopes {
name = "store:read"
}
scopes {
name = "store:update"
}
scopes {
name = "store:delete"
}
}

resource "auth0_role" "my_role" {
name = "My Role"
}

resource "auth0_role_permissions" "my_role_perms" {
role_id = auth0_role.my_role.id

dynamic "permissions" {
for_each = auth0_resource_server_scopes.resource_server_scopes.scopes
content {
name = permissions.value.name
resource_server_identifier = auth0_resource_server.resource_server.identifier
}
}
}
Loading