Skip to content

Commit 9b4ca21

Browse files
toshkePwnionclaude
authored
new resources for assigning permissions, creating resource instances (#55)
* feat: add role assignments, data sources, and import support New resources: - permitio_role_assignment: tenant-level role assignments - permitio_resource_instance_role_assignment: instance-level role assignments - permitio_group_resource_instance_role_assignment: group-based instance role assignments New data sources: - permitio_user: fetch user information by key Import support added to existing resources: - permitio_role: top-level and resource-level roles - permitio_condition_set_rule: comma-separated user_set,permission,resource_set Bug fixes & improvements: - Drift detection for role assignments and resource instances - Nil guards on API responses to prevent runtime panics - Empty set handling in roles model for permissions and extends - Global config module for resources needing direct HTTP access * feat: add resource_instance resource Manage Permit.io resource instances - specific objects of a resource type (e.g., a specific document, project, or folder). Supports ABAC attributes via JSON. Includes: - Full CRUD operations for resource instances - Drift detection (removes from state when deleted externally) - Nil guards on API responses to prevent runtime panics - Import support using resource_key:instance_key format - Documentation with usage examples * docs: update docs with go generate * fix: split resource_instance into separate fields and fix __user: prefix bug Splits the combined resource_instance field (e.g. "document:doc-123") into separate resource and resource_instance fields, matching the schema used by permitio_group_resource_instance_role_assignment. Also fixes a bug where tfModelFromRelationshipTupleRead stored the raw API subject including the __user: prefix, causing permanent state drift on every plan. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: use Users API instead of RelationshipTuples API for resource instance role assignments * chore: update tenant docs * docs: add examples for resource imports * chore: fix cilinting errors, upgrade to go1.24 --------- Co-authored-by: Aden McCusker <aden.m@null.net> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0f84592 commit 9b4ca21

39 files changed

Lines changed: 2104 additions & 33 deletions

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,9 @@ website/vendor
3535

3636
# Keep windows files with windows line endings
3737
*.winfile eol=crlf
38+
39+
# Local claude configuration
40+
.claude/settings.local.json
41+
42+
# Built binary for local testing
43+
terraform-provider-permit-io

docs/data-sources/permitio_user.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "permitio_user Data Source - terraform-provider-permit-io"
4+
subcategory: ""
5+
description: |-
6+
Fetches a user from the Permit.io directory.
7+
---
8+
9+
# permitio_user (Data Source)
10+
11+
Fetches a user from the Permit.io directory.
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Required
19+
20+
- `key` (String) User key identifier
21+
22+
### Read-Only
23+
24+
- `attributes` (String) Custom user attributes as JSON string
25+
- `email` (String) User's email address
26+
- `environment_id` (String) Environment ID
27+
- `first_name` (String) User's first name
28+
- `id` (String) Unique user ID
29+
- `last_name` (String) User's last name
30+
- `organization_id` (String) Organization ID
31+
- `project_id` (String) Project ID

docs/resources/permitio_condition_set_rule.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,12 @@ See [our documentation](https://api.permit.io/v2/redoc#tag/Condition-Set-Rules)
2727
- `id` (String) Unique id of the condition set rule
2828
- `organization_id` (String) Unique id of the organization that owns the condition set rule
2929
- `project_id` (String) Unique id of the project that owns the condition set rule
30+
31+
## Import
32+
33+
Import is supported using the following syntax:
34+
35+
```shell
36+
# Import a condition set rule using the format: user_set,permission,resource_set
37+
terraform import permitio_condition_set_rule.example admins,document:read,sensitive-docs
38+
```
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "permitio_group_resource_instance_role_assignment Resource - terraform-provider-permit-io"
4+
subcategory: ""
5+
description: |-
6+
Assigns a role to a group on a specific resource instance within a tenant. This uses the Permit.io Groups API to manage group-level permissions on resource instances. For user-specific assignments, use permitio_resource_instance_role_assignment instead.
7+
---
8+
9+
# permitio_group_resource_instance_role_assignment (Resource)
10+
11+
Assigns a role to a group on a specific resource instance within a tenant. This uses the Permit.io Groups API to manage group-level permissions on resource instances. For user-specific assignments, use `permitio_resource_instance_role_assignment` instead.
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Required
19+
20+
- `group` (String) Group key to assign the role to
21+
- `resource` (String) Resource type (e.g., 'workspace', 'document')
22+
- `resource_instance` (String) Resource instance key (e.g., 'ws-123', 'doc-456')
23+
- `role` (String) Role key to assign
24+
- `tenant` (String) Tenant key for scoped assignment
25+
26+
### Read-Only
27+
28+
- `id` (String) Unique identifier of the role assignment
29+
30+
## Import
31+
32+
Import is supported using the following syntax:
33+
34+
```shell
35+
# Import a group resource instance role assignment using the format: group:role:resource:resource_instance:tenant
36+
terraform import permitio_group_resource_instance_role_assignment.example engineering:viewer:document:doc-1:default
37+
```
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "permitio_resource_instance Resource - terraform-provider-permit-io"
4+
subcategory: ""
5+
description: |-
6+
Manages a Permit.io resource instance. Resource instances represent specific objects of a resource type (e.g., a specific document, project, or folder). See the documentation https://api.permit.io/v2/redoc#tag/Resource-Instances for more information.
7+
---
8+
9+
# permitio_resource_instance (Resource)
10+
11+
Manages a Permit.io resource instance. Resource instances represent specific objects of a resource type (e.g., a specific document, project, or folder). See [the documentation](https://api.permit.io/v2/redoc#tag/Resource-Instances) for more information.
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Required
19+
20+
- `key` (String) The key. This is a unique identifier.
21+
- `resource` (String) The resource type key that this instance belongs to.
22+
23+
### Optional
24+
25+
- `attributes` (String) Arbitrary resource instance attributes in JSON format that will be used to enforce attribute-based access control policies.
26+
- `tenant` (String) The tenant key for multi-tenant enforcement.
27+
- `updated_at` (String) The update timestamp. This is a timestamp for when the object was last updated.
28+
29+
### Read-Only
30+
31+
- `created_at` (String) The creation timestamp. This is a timestamp for when the object was created.
32+
- `environment_id` (String) The environment ID. This is a unique identifier for the environment.
33+
- `id` (String) The resource ID. This is a unique identifier for the resource.
34+
- `organization_id` (String) The organization ID. This is a unique identifier for the organization.
35+
- `project_id` (String) The project ID. This is a unique identifier for the project.
36+
- `resource_id` (String) The unique resource type ID.
37+
38+
## Import
39+
40+
Import is supported using the following syntax:
41+
42+
```shell
43+
# Import a resource instance using the format: resource_key:instance_key
44+
terraform import permitio_resource_instance.example document:doc-1
45+
```
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "permitio_resource_instance_role_assignment Resource - terraform-provider-permit-io"
4+
subcategory: ""
5+
description: |-
6+
Assigns a role to a user on a specific resource instance within a tenant. This is for instance-level permissions (e.g., giving a user editor access to a specific document). For tenant-level role assignments, use permitio_role_assignment instead.
7+
---
8+
9+
# permitio_resource_instance_role_assignment (Resource)
10+
11+
Assigns a role to a user on a specific resource instance within a tenant. This is for instance-level permissions (e.g., giving a user editor access to a specific document). For tenant-level role assignments, use `permitio_role_assignment` instead.
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Required
19+
20+
- `resource` (String) Resource type (e.g., 'workspace', 'document')
21+
- `resource_instance` (String) Resource instance key (e.g., 'ws-123', 'doc-456')
22+
- `role` (String) Role key to assign
23+
- `tenant` (String) Tenant key for scoped assignment
24+
- `user` (String) User key to assign the role to
25+
26+
### Read-Only
27+
28+
- `created_at` (String)
29+
- `environment_id` (String)
30+
- `id` (String) Unique identifier of the role assignment
31+
- `organization_id` (String)
32+
- `project_id` (String)
33+
34+
## Import
35+
36+
Import is supported using the following syntax:
37+
38+
```shell
39+
# Import a resource instance role assignment using the format: user:role:resource:resource_instance:tenant
40+
terraform import permitio_resource_instance_role_assignment.example john@example.com:viewer:document:doc-1:default
41+
```

docs/resources/permitio_role.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,15 @@ See [the documentation](https://api.permit.io/v2/redoc#tag/Resources/operation/c
3838
- `organization_id` (String) The organization ID. This is a unique identifier for the organization.
3939
- `project_id` (String) The project ID. This is a unique identifier for the project.
4040
- `resource_id` (String) The unique resource ID that the role belongs to.
41+
42+
## Import
43+
44+
Import is supported using the following syntax:
45+
46+
```shell
47+
# Import a top-level role using the format: role_key
48+
terraform import permitio_role.example admin
49+
50+
# Import a resource-level role using the format: resource_key:role_key
51+
terraform import permitio_role.example document:editor
52+
```
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "permitio_role_assignment Resource - terraform-provider-permit-io"
4+
subcategory: ""
5+
description: |-
6+
Assigns a role to a user within a specific tenant.
7+
---
8+
9+
# permitio_role_assignment (Resource)
10+
11+
Assigns a role to a user within a specific tenant.
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Required
19+
20+
- `role` (String) Role key to assign
21+
- `tenant` (String) Tenant key for scoped assignment
22+
- `user` (String) User key to assign the role to
23+
24+
### Read-Only
25+
26+
- `created_at` (String)
27+
- `environment_id` (String)
28+
- `id` (String) Unique identifier of the role assignment
29+
- `organization_id` (String)
30+
- `project_id` (String)
31+
32+
## Import
33+
34+
Import is supported using the following syntax:
35+
36+
```shell
37+
# Import a role assignment using the format: user:role:tenant
38+
terraform import permitio_role_assignment.example john@example.com:admin:default
39+
```

docs/resources/permitio_tenant.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "permitio_tenant Resource - terraform-provider-permit-io"
4+
subcategory: ""
5+
description: |-
6+
Manages a Permit.io tenant. Tenants represent isolated groups or organizations within your application. See the documentation https://api.permit.io/v2/redoc#tag/Tenants for more information about tenants.
7+
---
8+
9+
# permitio_tenant (Resource)
10+
11+
Manages a Permit.io tenant. Tenants represent isolated groups or organizations within your application. See [the documentation](https://api.permit.io/v2/redoc#tag/Tenants) for more information about tenants.
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Required
19+
20+
- `key` (String) The key. This is a unique identifier.
21+
- `name` (String) The name. This is a human-readable name for the object.
22+
23+
### Optional
24+
25+
- `attributes` (String) Arbitrary tenant attributes in JSON format that will be used to enforce attribute-based access control policies.
26+
- `description` (String) The description. This is a human-readable description for the object.
27+
- `updated_at` (String) The update timestamp. This is a timestamp for when the object was last updated.
28+
29+
### Read-Only
30+
31+
- `created_at` (String) The creation timestamp. This is a timestamp for when the object was created.
32+
- `environment_id` (String) The environment ID. This is a unique identifier for the environment.
33+
- `id` (String) The resource ID. This is a unique identifier for the resource.
34+
- `last_action_at` (String) Date and time when the tenant was last active (ISO_8601 format). In other words, this is the last time a permission check was done on a resource belonging to this tenant.
35+
- `organization_id` (String) The organization ID. This is a unique identifier for the organization.
36+
- `project_id` (String) The project ID. This is a unique identifier for the project.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Import a condition set rule using the format: user_set,permission,resource_set
2+
terraform import permitio_condition_set_rule.example admins,document:read,sensitive-docs

0 commit comments

Comments
 (0)