I am trying to run `permit env export terraform --...
# permit-saas
m
I am trying to run
permit env export terraform --api-key ****
but I can't get it running against https://app.eu.permit.io. I guess it might be problem even for
permit login
Any help @Ask Inkeep?
a
Thanks for tagging me @Míla Votradovec. I'll look through relevant sources and get back to you shortly.
For EU region, you need to use the region-specific endpoint
<http://api.eu.permit.io|api.eu.permit.io>
instead of the default
<http://api.permit.io|api.permit.io>
. (1) The CLI commands don't have a built-in flag to specify the API URL directly. However, based on the documentation, here are potential solutions: For the Node SDK, you can specify the EU endpoint like this:
Copy code
const permit = new Permit({
  // the API key to the Permit environment you wish to connect to
  token: "<YOUR_API_KEY>",
  // the url in which the SDK can connect to the PDP container
  pdp: "<http://localhost:7766>",
  // use this to turn on sdk logs
  log: {
    level: "debug",
  },
  // the region in which the Permit environment is located
  apiUrl: "<https://api.eu.permit.io>",
}) ;
Unfortunately, the CLI documentation doesn't explicitly show how to configure the API URL for EU region when using
permit env export terraform
or
permit login
commands. (2) (3) (4) The CLI appears to default to the standard
<http://api.permit.io|api.permit.io>
endpoint. You might want to reach out to Permit.io support at Email for guidance on configuring the CLI for EU region, as this specific configuration isn't documented in the available sources.
To learn more, see the sources I considered: [[1] Using the API](https://docs.permit.io/api/api-with-cli) [[2] Environments management using the Permit CLI](https://docs.permit.io/how-to/permit-cli/permit-cli-envs) [[3] Permit CLI](https://github.com/permitio/permit-cli/blob/main/README.md) [[4] Policy - AI, Templates, OpenAPI](https://docs.permit.io/how-to/permit-cli/permit-cli-policy)
m
You might want to reach out to Permit.io support
🆘 🙂
o
Hi Mila, thanks for reaching out. this is a missing feature in the CLI. We can look into adding it next week.
m
That would be really lovely! Thank you very much.
@Or Weis given it's open source - would you eventually appreciate a PR?
o
Would not only appreciate a PR but would love it as well :)
❤️ 1
Seems @Eli Moshkovich jumped on the opportunity and produced a PR https://github.com/permitio/permit-cli/pull/137/files
Your feedback would be appreciated
m
Thank you very much @Or Weis and @Eli Moshkovich. I cloned the repo and I am testing the functionality and when I ran
node ./dist/cli.js login --region eu
, I immediately get
Authorization code not found in query string
Without region, I am correctly prompted to log in
o
😇 @Eli Moshkovich is on the US West Coast, so he'll probably reply a little later today
m
Sure, I'll see if I can give you better report during the day.
e
Hi @Míla Votradovec Thanks for testing and catching this bug! You were absolutely right - the issue was that we were incorrectly using
<https://api.eu.permit.io/v1/>
as the Auth0 audience, but Auth0 only recognizes
<https://api.permit.io/v1/>
for both regions. I've just pushed a fix to the PR, The
--region eu
flag should now work properly 🙂 Please pull the latest changes, rebuild (
npm run build
), and
node ./dist/cli.js login --region eu
should work now
👀 1
m
Hi @Eli Moshkovich, thank you for looking into this. I can confirm login works correctly. However, I have troubles running terraform export. Steps I am doing: •
npm run build
•
node ./dist/cli.js login --region eu
•
node ./dist/cli.js env export terraform --api-key ****
I get
{"detail":"Invalid credentials"}
I tried selecting different environments, I tried both environments and freshly created Organization API key, but result is still the same. Could you please have a look into that?
a
Hey @Míla Votradovec, i'll make sure @Eli Moshkovich see it. Meanwhile @Ask Inkeep 🙂
a
Thanks for tagging me @Alon Boshi. I'll look through relevant sources and get back to you shortly.
It looks like you're encountering an authentication issue when trying to export Terraform configurations with the EU region. The "Invalid credentials" error suggests the API key isn't being properly passed to the EU endpoint. Based on the CLI documentation, the
permit env export terraform
command accepts an
--api-key
parameter (1) . When you're logged in via
permit login --region eu
, the CLI should be using the EU endpoint, but it seems the terraform export command might not be respecting the region setting from your login session. Here's what you can try: 1. ​*Verify your API key scope*​: The terraform export requires a project-level or higher API key . Make sure your API key has the correct permissions. 2. ​*Check if the region is being applied*​: Since you've successfully logged in with
--region eu
, the issue might be that the terraform export command isn't inheriting the region setting. The command structure should be:
Copy code
permit env export terraform --api-key <your-api-key>
Since this appears to be a bug with the new EU region support that's being added via the PR you're testing, I'd recommend adding this feedback directly to the PR discussion. The terraform export command may need to be updated to respect the region setting established during login. For debugging purposes, could you share: 1. Which Workspace / Project / Env you are using 2. The exact command you're running (with the API key redacted) 3. Whether you're using a project-level or organization-level API key 4. Any error logs from the CLI when running with debug mode enabled This will help the team investigate the issue with the EU region support in the terraform export command.
To learn more, see the sources I considered: [[1] Environments management using the Permit CLI](https://docs.permit.io/how-to/permit-cli/permit-cli-envs)
e
Hi @Míla Votradovec, Great to hear login is working! The issue you’re seeing happens because the
--region
flag only applies to the
login
command. When using
--api-key
directly, you need to set the
PERMIT_REGION
environment variable manually:
Copy code
# Build
npm run build

# Set region for your session
export PERMIT_REGION=eu

# Now use commands with your EU API key
node ./dist/cli.js env export terraform --api-key ****
Why this happens: When you log in with
--region eu
, the region is stored automatically. But when you use
--api-key
(which skips login), the CLI needs the region to be explicitly defined via the environment variable. We’ve also pushed a fix to the PR that includes improvements to EU region handling, please pull the latest changes before testing again.
m
Thank you @Eli Moshkovich, it looks like it is working now 🎉 Thank you for your work. There is still one caveat though - I have created couple of roles and I see them all exported as
permitio_role
except one -
admin
. No matter what I try, I can't get admin exported to my terraform config. Is this something you could have a look into, please? tagging @Ask Inkeep in case it would be some known issue
a
Thanks for tagging me @Míla Votradovec. I'll look through relevant sources and get back to you shortly.
The missing
admin
role in your Terraform export could be related to a known issue with the CLI's terraform export functionality (1) . According to the GitHub issue, the Terraform export has been reported to generate incomplete exports - it only generates roles and resource sets but misses the actual
permitio_condition_set_rule
resources that represent checked permissions in the policy matrix . The
permit env export terraform
command exports all environment content including resources, roles, user sets, resource sets, and condition sets in the Permit Terraform provider format (2) (3) . However, if your
admin
role has specific policy rules or condition set rules associated with it, these might not be getting exported correctly. Here's what the exported role should look like based on the Terraform provider documentation (4) :
Copy code
resource "permitio_role" "admin" {
  key = "admin"
  name = "Administrator"
  description = "Full access to documents including deletion"
  permissions = ["document:read", "document:write", "document:delete"]
  
  depends_on = [permitio_resource.document]
}
To help troubleshoot this further, you could: 1. Check if the
admin
role appears correctly in the Permit.io dashboard 2. Try creating a simple test role to see if it exports properly 3. Review if the
admin
role has any special configurations that might be causing the export to skip it This appears to be a limitation of the current CLI export functionality rather than an issue with your specific setup.
To learn more, see the sources I considered: [[1] Bug: Missing Policy Rules in Terraform Export](https://github.com/permitio/permit-cli/issues/130) [[2] Environments management using the Permit CLI](https://docs.permit.io/how-to/permit-cli/permit-cli-envs) [[3] Permit CLI](https://github.com/permitio/permit-cli/blob/main/README.md) [[4] Permit.io Terraform Provider](https://docs.permit.io/integrations/infra-as-code/terraform-provider)
m
@Ask Inkeep the admin has just everything, nothing extra special.
a
Thanks for tagging me @Míla Votradovec. I'll look through relevant sources and get back to you shortly.
Looking at the Terraform provider documentation, there could be a few reasons why the
admin
role isn't being exported. The Terraform export functionality should export all roles defined in your environment (1) . Based on the Terraform provider examples, a properly exported admin role should look like this (2) :
Copy code
resource "permitio_role" "admin" {
  key = "admin"
  name = "Administrator"
  description = "Full access to documents including deletion"
  permissions = ["document:read", "document:write", "document:delete"]
  
  depends_on = [permitio_resource.document]
}
The CLI's
permit env export terraform
command is designed to export all environment content including resources, roles, user sets, resource sets, and condition sets (1) . If the
admin
role appears correctly in your Permit.io dashboard but isn't being exported, this could be a bug in the export functionality. To help our engineers investigate this issue with the missing
admin
role in your Terraform export: 1. Which Workspace / Project / Env are you using? 2. Could you share the exact command you're running (with API key redacted) ? 3. Which version of the CLI are you running (since you're testing the PR branch) ? 4. Could you share any relevant logs from running the export command, perhaps with debug logging enabled? Additionally, it would be helpful to know: • Does the
admin
role have any permissions assigned in the policy matrix? • Are there any special characters in the role name or key? • Does the role have any dependencies on resources that might not be exporting? This information will help determine if this is related to the EU region changes or a separate export issue.
To learn more, see the sources I considered: [[1] Permit CLI](https://github.com/permitio/permit-cli/blob/main/README.md) [[2] Permit.io Terraform Provider](https://docs.permit.io/integrations/infra-as-code/terraform-provider)
e
Hi @Míla Votradovec, This is separate from the EU region bug we just fixed - this is actually expected behavior. The CLI intentionally skips exporting the default `admin`/`editor`/`viewer` roles since they exist in every Permit environment by default. That's why you see your other roles exported, but not
admin
. If you need to manage
admin
via terraform, create a custom role with a different name (like
super_admin
) instead. Custom roles will show up in the export.
Hi @Míla Votradovec , I was wrong about this being expected behavior. We've just pushed a fix that now exports all roles including admin/editor/viewer with their actual permissions. The CLI will now include them in your Terraform export, and the Terraform provider will handle updating existing roles automatically (standard UPSERT behavior). Pull the latest changes, rebuild, and your
admin
role should now appear in the export
a
Hey @Míla Votradovec, just bumping this message to check if everything’s working on your end now.
m
@Eli Moshkovich @Alon Boshi Sorry for the delay - I just tested our flow and it looks like everything is working smooth! Thank you for your work, your response time is insane 🙂
One question here - it would be great if we could somehow manage tenants through terraform as well. In our setup, we need to create new new tenant rather often and switching from terraform to cli or custom script is a bit cumbersome
o
Happy to be of service. Let me check with @Eli Moshkovich re: the feature request
👀 1
He'll be online in a few hours (west coast)
e
Hi @Míla Votradovec I’ve added tenant support to the Terraform provider based on your request. It’s implemented and tested, and we’re just waiting for the team to review and merge it, It should be ready in the next few days. Once released, you’ll be able to manage tenants directly in Terraform without switching to CLI or scripts 🙂
Hi @Míla Votradovec Good news - the new Terraform provider v0.0.18 has just been released, and it includes tenant management support! 🎉 You can now create and manage tenants directly through Terraform without needing to switch to CLI or scripts anymore.
🤘 1
thanks 1
👏 1
m
hey @Eli Moshkovich Coming back to https://permit-io.slack.com/archives/C02RTML2WNN/p1759952587906989?thread_ts=1759427171.403209&amp;cid=C02RTML2WNN Do you have any estimate when the new version is gonna be released?
a
Hey @Míla Votradovec, I’m not sure which version you’re referring to — could you clarify?
m
@Alon Boshi Well, the fix of the issue with admin is in main branch, but it hasn't been released as npm package yet. So I am basically asking when there will be a new version
a
Will make sure @Eli Moshkovich see it 🙏🏼
m
Thank you
💜 1
e
Hi @Míla Votradovec, Just released a new version - permit-cli v0.2.9 🎉 Thanks a lot for your patience! 🙏
m
Hi @Eli Moshkovich, thank you very much - it looks much better now. However, there is still one issue though. permit-cli now correctly exports all the roles. However, when I try to apply the terraform in a new environment, it fails with error:
Copy code
│ Error: Unable to create role
│
│   with module.permit_io_config.permitio_role.admin,
│   on ../modules/permit_io_config/permit_config.tf line 196, in resource "permitio_role" "admin":
│  196: resource "permitio_role" "admin" {
│
│ unable to create role: ErrorCode: Conflict, ErrorType: api_error, Message: The resource already exists
I think it is because of default
admin
,
viewer
,
editor
roles. Do you know if there is a workaround?
a
Hey @Míla Votradovec, will make sure @Eli Moshkovich see it and will circle back to you 🙏🏼
t
Hey @Míla Votradovec you may make a get roles and delete the default roles after you create a new environment.