Alec Handal
11/02/2025, 10:36 PMAsk Inkeep
11/02/2025, 10:36 PMpermit support automation2
11/02/2025, 10:36 PMAsk Inkeep
11/02/2025, 10:36 PM/v2/schema/{proj_id}/{env_id}/resources (2) .
However, you can copy environments to avoid recreating resources each time (4) . When you copy an environment into a new environment, it includes all the resources :
curl --location '<https://api.permit.io/v2/projects/{project_id}/envs/{env_id}/copy>' \
The copy operation includes resources along with other policy elements . You can also use scope parameters to include or exclude specific resources during the copy:
curl --location '<https://api.permit.io/v2/projects/{project_id}/envs/{env_id}/copy>' \
-H 'authorization: Bearer API_SECRET_KEY'\
--data '{
"target_env": {
"new": {
"key": "prod",
"name": "production"
}
},
"scope": {
"roles": {
"exclude": ["*"]
},
"resources": {
"include": ["folder", "file"]
},
"resource_sets": {
"exclude": ["test*"]
},
"user_sets": {
"exclude": ["canada_users"]
},
"custom_policies": {
"include": ["*.rego"]
}
}
}'
This approach lets you maintain resources in one environment and copy them to new environments as needed, rather than recreating them manually each time.Ask Inkeep
11/02/2025, 10:37 PMOr Weis
11/02/2025, 10:43 PMAsk Inkeep
11/02/2025, 10:43 PMAsk Inkeep
11/02/2025, 10:43 PMterraform {
required_providers {
permitio = {
source = "<http://registry.terraform.io/permitio/permit-io|registry.terraform.io/permitio/permit-io>"
version = "~> 0.0.14" # Use the latest version
}
}
}
# Configure the <http://Permit.io|Permit.io> provider
provider "permitio" {
api_key = "YOUR_API_KEY" # Replace with your actual API key
# api_url = "<https://api.permit.io>" # Optional: defaults to <https://api.permit.io>
}
# Define a resource (e.g., documents in your application)
resource "permitio_resource" "document" {
key = "document"
name = "Document"
description = "A confidential document that users can read and write"
actions = {
"read" = {
"name" = "Read"
"description" = "Read a document"
}
"write" = {
"name" = "Write"
"description" = "Write to a document"
}
"delete" = {
"name" = "Delete"
"description" = "Delete a document"
}
}
attributes = {
"title" = {
"description" = "The title of the document"
"type" = "string"
}
"owner" = {
"description" = "The owner of the document"
"type" = "string"
}
}
}
You can also use Terraform workspaces to manage different environments :
# Create separate workspaces for different environments
terraform workspace new dev
terraform workspace new staging
terraform workspace new prod
# Switch between workspaces
terraform workspace select dev
This way, you define your resources once and deploy them consistently across all your environments, avoiding the need to recreate them manually each time .Ask Inkeep
11/02/2025, 10:43 PM