Skip to content

Add role_assignment resource and admin_role_id to space resource #105

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Aug 7, 2025

This PR implements the role_assignment resource requested in issue #85, along with the preferred solution of adding admin_role_id output to the space resource.

Changes Made

Admin Role ID Support (Preferred Solution)

Added admin_role_id as a computed output field to both the contentful_space resource and contentful_space data source. When a space is created or read, the provider automatically fetches all roles for the space and identifies the admin role using intelligent heuristics:

resource "contentful_space" "example" {
  name = "My Space"
}

output "admin_role_id" {
  value = contentful_space.example.admin_role_id  # Now available!
}

The admin role detection algorithm identifies roles with:

  • "all" permissions for key operations
  • Comprehensive permission sets (>3 permissions)
  • Handles both string and array permission formats

Role Assignment Resource

Created a complete contentful_role_assignment resource structure that supports:

Inputs:

  • space_id - The space where the assignment is made
  • team_id - Team to assign the role to (from future contentful_team resource)
  • role_id - Specific role to assign (mutually exclusive with is_admin)
  • is_admin - Boolean flag to assign the admin role (mutually exclusive with role_id)

Validation:

  • Ensures role_id and is_admin are mutually exclusive
  • Requires either a specific role or admin assignment

Import format: space_id:team_id:role_id or space_id:team_id:admin

# Assign specific role
resource "contentful_role_assignment" "editor" {
  space_id = contentful_space.example.id
  team_id  = contentful_team.editors.id
  role_id  = contentful_role.editor.role_id
}

# Assign admin role
resource "contentful_role_assignment" "admin" {
  space_id = contentful_space.example.id
  team_id  = contentful_team.admins.id
  is_admin = true
}

Current Status

The role assignment resource is implemented as a placeholder since the underlying Contentful Management API endpoints for role assignments are not yet available. The resource currently returns a helpful "Feature Not Available" error message and is ready to be activated when Contentful adds the necessary APIs.

The admin role ID functionality is fully operational and uses the existing GetAllRoles API endpoint.

Dependencies

  • Role assignments depend on team resources (issue New Resource: contentful_team #84)
  • Role assignments require Contentful to add role assignment APIs to their Management API

Fixes #85.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI changed the title [WIP] New Resource: role_assignment Add role_assignment resource and admin_role_id to space resource Aug 7, 2025
@Copilot Copilot AI requested a review from mvantellingen August 7, 2025 07:47
Copilot finished work on behalf of mvantellingen August 7, 2025 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New Resource: role_assignment
2 participants