Skip to content

Conversation

orkhanM
Copy link

@orkhanM orkhanM commented Aug 31, 2025

This PR extends the datadog_role data source to include a permissions attribute that returns all permissions associated with a role. The permissions are returned as a map (name → ID), consistent with the datadog_permissions data source format. This enhancement enables users to programmatically inherit permissions from existing roles when creating custom roles, rather than manually maintaining permission lists.

If preferable this can be made into a different datasource all_together (i.e. datadog_role_permissions)

Example:

# Get all available permissions to look up IDs by name
data "datadog_permissions" "all" {}

# Get the existing "Datadog Read Only" role and its permissions
data "datadog_role" "readonly" {
  filter = "Datadog Read Only"
}

# Create a custom role that inherits all read permissions plus adds write access for notebooks and dashboards
resource "datadog_role" "custom_analyst" {
  name        = "Custom Analyst"
  description = "Read-only access plus dashboard and notebook write permissions"
  
  default_permissions_opt_out = true

  dynamic "permission" {
    for_each = data.datadog_role.readonly.permissions
    content {
      id = permission.value
    }
  }

  permission {
    id = data.datadog_permissions.all.permissions["dashboards_write"]
  }
  
  permission {
    id = data.datadog_permissions.all.permissions["notebooks_write"]
  }
}

Without this feature, users have to manually enumerate every single permission ID from the base role, which is error-prone and difficult to maintain as permissions change over time.

@orkhanM orkhanM requested review from a team as code owners August 31, 2025 01:31
@orkhanM orkhanM changed the title Add permissions attribute to datadog_role data source [datadog_role] Add permissions attribute to datadog_role data source Sep 1, 2025
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.

2 participants