- Access exclusive content
- Connect with peers
- Share your expertise
- Find support resources
11-06-2025 11:40 PM
Hi all,
We've been having trouble getting the Cyberark SCA terraform provider to work.
We have tested the linux terraform-provider-sca_linux_amd64.zip provider versions:
They both had the same issues.
Our debugging led us to believe that the service credentials we've created for the terraform provider ARE successfully generating a valid JWT, however when the token is used the provider is failing, either incorrect permissions or the JWT is not accepted (401 error).
I've confirmed this by using curl to generate myself a JWT from the cyberark oauth endpoint:
curl -X POST https://xxxx.id.cyberark.cloud/oauth2/token/TerraformIntegration \
-H "Content-Type: application/x-www-form-urlencoded" \
-u "${USERNAME}:${PASSWORD}" \
-d "grant_type=client_credentials"
{
"auth_time": 1761795357,
"iss": "https://xxxx.id.cyberark.cloud/TerraformIntegration/",
"iat": 1761795625,
"aud": "cyberark.isp.sca",
"unique_name": "[email protected]",
"user_roles": [
"DpaAdmin",
"CEMAdmin",
"Terraform SCA",
"CS Admin",
"SCAApiFullAccess",
"SCA Admin",
"Connector Management Admin",
"Cloud Onboarding Admin",
"TDR Administrator",
"global auditor",
"TDR Read-only"
],
"user_uuid": "xxxx-xxxx-xxxx-xxxx-xxxx",
"exp": 1762227625,
"sub": "xxxx-xxxx-xxxx-xxxx-xxxx",
"tenant_id": "xxxx-xxxx-xxxx-xxxx-xxxx",
"app_id": "TerraformIntegration"
}
When we use Terraform provider for SCA we get a 401.
Below is the terraform code we've used:
data "sca_discovery" "discovery_example" {
csp = "AWS"
organization_id = "r-xxxx"
account_info = {
id = "xxxx"
new_account = false
}
}
terraform {
required_providers {
sca = {
# Provider version is 1.0.0
source = "cyberark/sca/sca"
}
}
}
provider "sca" {
auth_url = "https://xxxx.id.cyberark.cloud/oauth2/token/TerraformIntegration"
tenant_domain_name = "xxxx"
platform_domain_name = "cyberark.cloud"
username = "[email protected]"
password = "XXX"
debug = true
}
The error we get is:
$ terraform plan
data.sca_discovery.discovery_example: Reading...
Planning failed. Terraform encountered an error while generating this plan.
╷
│ Error: Unable to active discovery
│
│ with data.sca_discovery.discovery_example,
│ on terraform.tf line 1, in data "sca_discovery" "discovery_example":
│ 1: data "sca_discovery" "discovery_example" {
│
│ Error while sending discovery request: Got status code different than 200.Status code is 401 Unauthorized
The DEBUG logs are a bit more detailed but show initial success at authenticating (presumably getting the JWT successfully, like I've done manually above), but then failing to use the JWT
2025-10-30T15:01:37.466+1100 [DEBUG] ReferenceTransformer: "data.sca_discovery.discovery_example" references: []
2025-10-30T15:01:37.467+1100 [DEBUG] skipping FixUpBlockAttrs
2025-10-30T15:01:37.468+1100 [INFO] provider.terraform-provider-sca_linux_amd64: Signed in successfully: SCA_auth_url=https://xxxx.id.cyberark.cloud/oauth2/token/TerraformIntegration SCA_debug=true SCA_password="***" tf_rpc=ConfigureProvider @module=sca SCA_base_url=https://xxxx.sca.cyberark.cloud/api [email protected] tf_provider_addr=cyberark/sca/sca tf_req_id=xxxx-xxxx-xxxx-xxxx-xxxx @caller=/home/jenkins/agent/workspace/cloud-sec-self-services/services/internal-deploy/integrations-v0.1024.3-prod-ap-southeast-2/terraform-provider-sca/sca/provider/provider.go:251 timestamp="2025-10-30T15:01:37.465+1100"
2025-10-30T15:01:37.468+1100 [INFO] provider.terraform-provider-sca_linux_amd64: Configured SCA client: @module=sca SCA_auth_url=https://xxxx.id.cyberark.cloud/oauth2/token/TerraformIntegration SCA_base_url=https://xxxx.sca.cyberark.cloud/api SCA_debug=true SCA_password="***" [email protected] success=true tf_provider_addr=cyberark/sca/sca tf_req_id=xxxx-xxxx-xxxx-xxxx-xxxx tf_rpc=ConfigureProvider @caller=/home/jenkins/agent/workspace/cloud-sec-self-services/services/internal-deploy/integrations-v0.1024.3-prod-ap-southeast-2/terraform-provider-sca/sca/provider/provider.go:257 timestamp="2025-10-30T15:01:37.465+1100"
data.sca_discovery.discovery_example: Reading...
2025-10-30T15:01:37.476+1100 [INFO] provider.terraform-provider-sca_linux_amd64: Starting to create policy: tf_provider_addr=cyberark/sca/sca tf_rpc=ReadDataSource @module=sca tf_data_source_type=sca_discovery tf_req_id=xxxx-xxxx-xxxx-xxxx-xxxx @caller=/home/jenkins/agent/workspace/cloud-sec-self-services/services/internal-deploy/integrations-v0.1024.3-prod-ap-southeast-2/terraform-provider-sca/sca/cloud_discovery/bl/data_source/discovery/discovery_data_resource.go:94 timestamp="2025-10-30T15:01:37.473+1100"
2025-10-30T15:01:37.645+1100 [DEBUG] provider.terraform-provider-sca_linux_amd64: Response body: {"message":"Unauthorized"}: @module=sca tf_data_source_type=sca_discovery tf_provider_addr=cyberark/sca/sca tf_req_id=xxxx-xxxx-xxxx-xxxx-xxxx tf_rpc=ReadDataSource @caller=/home/jenkins/agent/workspace/cloud-sec-self-services/services/internal-deploy/integrations-v0.1024.3-prod-ap-southeast-2/terraform-provider-sca/sca/client/client_utils.go:26 timestamp="2025-10-30T15:01:37.645+1100"
2025-10-30T15:01:37.645+1100 [ERROR] provider.terraform-provider-sca_linux_amd64: Response contains error diagnostic: @caller=/home/jenkins/go/pkg/mod/github.com/hashicorp/[email protected]/tfprotov6/internal/diag/diagnostics.go:58 @module=sdk.proto diagnostic_severity=ERROR diagnostic_summary="Unable to active discovery" tf_data_source_type=sca_discovery tf_req_id=xxxx-xxxx-xxxx-xxxx-xxxx diagnostic_detail="Error while sending discovery request: Got status code different than 200.Status code is 401 Unauthorized" tf_proto_version=6.4 tf_provider_addr=cyberark/sca/sca tf_rpc=ReadDataSource timestamp="2025-10-30T15:01:37.645+1100"To me this seems an authorization problem - did we not give the correct permissions to the service user?
I've tried with another data resource, and tried creating a resource and I still just get the 401 Unauthorized.
We'd love some further guidance on how this issue could be resolved.
Thanks
11-07-2025 12:16 AM
Hello, For the username you are generating the JWT, please ensure that service user is associated to below roles.
Please note: If you don't have below SCAPublicApiWrapper role, then please create one and add roles SCAApiFullAccess, SCAApiFullAccess as members of this role
11-09-2025 04:12 PM
Hi Sunit,
Thank you for your very quick response!
I've worked with my colleague who has granted the permissions you've suggested.
We also assumed that the SCAPublicApiWrapper role should include SCAApiFullAccess and SCAApiReadOnly, rather than what you had posted SCAApiFullAccess and SCAApiFullAccess.
I can confirm these three roles have been given, see:
{
"auth_time": 1762728182,
"iss": "https://xxxx.id.cyberark.cloud/TerraformIntegration/",
"iat": 1762728196,
"aud": "cyberark.isp.sca",
"unique_name": "[email protected]",
"user_roles": [
"DpaAdmin",
"CEMAdmin",
"Terraform SCA",
"CS Admin",
"SCAApiFullAccess",
"SCA Admin",
"SCAUserReadOnly",
"SCAApiReadOnly",
"Connector Management Admin",
"Cloud Onboarding Admin",
"TDR Administrator",
"Access Request Applicant",
"Access Request Approver",
"SCAPublicApiWrapper",
"global auditor",
"TDR Read-only"
],
"user_uuid": "xxxx-xxxx-xxxx-xxxx-xxxx",
"exp": 1763160196,
"sub": "xxxx-xxxx-xxxx-xxxx-xxxx",
"tenant_id": "xxxx-xxxx-xxxx-xxxx-xxxx",
"app_id": "TerraformIntegration"
}Also these screen shots:
I'm afraid that does not work. We still get the 401.
$ terraform apply
data.sca_discovery.discovery_example: Reading...
╷
│ Error: Unable to active discovery
│
│ with data.sca_discovery.discovery_example,
│ on terraform.tf line 1, in data "sca_discovery" "discovery_example":
│ 1: data "sca_discovery" "discovery_example" {
│
│ Error while sending discovery request: Got status code different than 200.Status code is 401 Unauthorized
Do you know any other reason why authorization is not working? What else can we do?
Thanks again
11-10-2025 08:30 AM
Hi, can you please open a support case here, it may need some debugging since its no longer the case of right access: https://community.cyberark.com/s/Submit-a-Case
11-12-2025 03:33 PM
@Sunit Randhawa - We managed to resolve the authn issue after adding full scope on the Oauth2 server. We have updated the support team as well.
11-12-2025 07:54 PM
Thanks Rajnish in updating the thread. Adding below details for anyone else to know where to add the scope.
Click Accept as Solution to acknowledge that the answer to your question has been provided.
The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!
These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!
The LIVEcommunity thanks you for your participation!

