---
updatedAt: 2026-10-28T12:42:40.000Z
agentTools:
  projectIndex: https://docs.scalr.io/llms.txt
---

# GCP Provider Configuration

Scalr offers two types of authentication for the Google Compute Cloud (GCP) provider. The OIDC generates temporary credentials for each run and is considered a best practice. The service account key method uses static credentials, which should be rotated regularly.

# OIDC

The OIDC authentication method will create a temporary access token for each run, avoiding the need to store static credentials in Scalr. A single OIDC provider can be linked to many workspaces, but each workspace can only have one OIDC provider linked to it.

## GCP Steps

To enable this, the following must be done in GCP first (see GCP OIDC docs [here](https://cloud.google.com/iam/docs/workload-identity-federation-with-other-providers#create-pool-provider)):

### Create a Workload Identity Pool

* Create a workload identity pool; the name is required, while the ID and description are optional.

### Create a Workload Identity Provider

* Register Scalr as the identity provider in the identity pool; the provider type must be `OIDC`.
* Add the provider name, e.g., `scalr`.
* The identity provider issuer URL is <https://scalr.io> (this must be an exact match).
* Leave the audience as the `Default audience`
* Now add the provider attribute mappings with the following settings. One of these two attribute mappings is required (the rest are optional):
  * `attribute.scalr_account_id`
  * `attribute.scalr_environment_id`

```
attribute_mapping = {
    "google.subject"                              = "assertion.sub",
    "attribute.aud"                               = "assertion.aud",
    "attribute.scalr_provider_configuration_id"   = assertition.scalr_provider_configuration_id,
    "attribute.scalr_provider_configuration_name" = assertition.scalr_provider_configuration_name,
    "attribute.scalr_run_phase"                   = "assertion.scalr_run_phase",
    "attribute.scalr_workspace_id"                = "assertion.scalr_workspace_id",
    "attribute.scalr_workspace_name"              = "assertion.scalr_workspace_name",
    "attribute.scalr_environment_id"              = "assertion.scalr_environment_id",
    "attribute.scalr_environment_name"            = "assertion.scalr_environment_name",
    "attribute.scalr_account_id"                  = "assertion.scalr_account_id",
    "attribute.scalr_account_name"                = "assertion.scalr_account_name",
    "attribute.scalr_run_id"                      = "assertion.scalr_run_id",
    "attribute.scalr_tags"                        = "assertion.scalr_tags" # comma-separated list of workspace tags
  }
```

* Optionally, you can add attribute conditions to restrict the access for tokens to specific workspaces in Scalr. For example, you can limit the provider to be available only in certain environments or workspaces, e.g., by name or tag. From a security perspective, attribute conditions are considered a best practice.

### Grant access

To grant access, you can use a pre-configured service account or create a new one with the required IAM permissions for the workspace(s). Scalr doesn't require any extra permission.

This [Google doc](https://cloud.google.com/iam/docs/workload-identity-federation-with-other-providers#impersonation) describes how to allow your workload to access Google Cloud resources:

1. To create a service account for the external workload, do the following:
   1. Enable APIs
   2. Create a service account (or use a pre-configured one)
   3. Grant the service account access to resources that you want external identities to access.
   4. Grant the Workload Identity User role `roles/iam.workloadIdentityUser` to the service account.
2. Grant access to a federated identity using service account impersonation using the Google Cloud console or the gcloud CLI:
   1. Go to the [Workload Identity Pools page](https://console.cloud.google.com/iam-admin/workload-identity-pools).
   2. Select **Grant access**.
   3. In the **Grant access to service account** dialog, select **Grant access using Service Account impersonation.**
   4. In the **Service accounts** list, select the service account for the external identities to impersonate
      1. Select `scalr_account_id` or `scalr_environment_id`attribute and paste your Scalr **account id** or **environment id** in the value field.
   5. Click Save
   6. Lastly, in the **Configure your application** dialog, do the following:
      1. Select provider
      2. Enter `/` in the **OIDC ID token path** field
      3. Choose JSON format and download the configuration

## Scalr Steps

In Scalr, you must create a provider configuration by going to the **Administration** and then to **Provider configurations**. Select GCP and OIDC, then upload the JSON into Scalr.

<Image src="https://files.readme.io/faf6e55-Screenshot_2023-07-14_at_10.18.29_AM.png" align="center" />

Once the provider configuration is added, it should then be shared with the environment(s) and linked to the workspace(s).

### Provider Example

The following is an example of how to configure this in Scalr with the Scalr Terraform provider:

```Text main.tf
resource "scalr_provider_configuration" "oidc" {
  name       = "oidc-main"
  account_id = "acc-xxxxxxxxx"
  google {
    auth_type              = "oidc"
    service_account_email  = "service-account@project-id.iam.gserviceaccount.com"
    workload_provider_name = "projects/123/locations/global/workloadIdentityPools/pool-name/providers/provider-name"
  }
}
```

The above is an example; please see the full provider documentation [here](https://docs.scalr.io/docs/provider_resource_scalr_provider_configuration).

# Service Account Key Method

## Create the Credential in GCP

In GCP, create the service account and assign enough permissions to manage the intended GCP objects. See more in the GCP docs [here](https://cloud.google.com/iam/docs/keys-create-delete).

Once the key is created, download it and store it in a secure place.

## Create the Provider Configuration in Scalr

Once you have the JSON file, it can be uploaded into Scalr:

<Image src="https://files.readme.io/d74298d-Screenshot_2023-07-14_at_10.16.56_AM.png" align="center" />

Share the configuration with environments and/or workspaces once it has been created. See more on this [here](https://docs.scalr.io/docs/provider-configurations).

### Provider example

The following is an example of how to configure this in Scalr with the Scalr Terraform provider:

```javascript main.tf
resource "scalr_provider_configuration" "service-account" {
 name       = "google_main"
  account_id = "acc-xxxxxxxxx"
  google {
    project     = "my-project"
    credentials = "my-credentials"
  }
}
```

<Callout icon="ℹ️" theme="info">
  ### Google Project ID

  The project value here is your <Anchor target="_blank" href="https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects">GCP Project ID.</Anchor>
</Callout>

The above is an example, please see the full provider documentation [here](https://docs.scalr.io/docs/provider_resource_scalr_provider_configuration).

Review the full provider configuration documents on how to link the provider configuration to an environment and workspace [here](https://docs.scalr.io/scalr/docs/provider_resource_scalr_provider_configuration)

# Google Default Labels

Google default labels automatically apply labels to all GCP resources managed by the provider configuration. These labels are merged with any `default_labels` defined in the workspace's Terraform code during each run, ensuring consistent labeling for cost allocation, governance, and ownership tracking across all workspaces linked to the provider configuration.

The feature supports two merge strategies:

* **Skip**: User-defined labels in source code take precedence over provider default labels when the same key appears in both.

* **Update**: Provider default labels override user-defined labels when the same key appears in both. Labels must comply with [Google Cloud label format requirements](https://cloud.google.com/resource-manager/docs/creating-managing-labels#requirements):

* Keys and values may only contain lowercase letters, digits, and hyphens.

* Keys must start with a lowercase letter and be 1–63 characters. Values must be 0–63 characters.

* A maximum of 64 labels can be defined per provider configuration.

## Provider example

```javascript main.tf
resource "scalr_provider_configuration" "gcp" {
  name                   = "gcp_with_default_labels"
  account_id             = "acc-xxxxxxxxx"
  export_shell_variables = false
  environments           = ["*"]
  google {
    auth_type              = "oidc"
    service_account_email  = "service-account@project-id.iam.gserviceaccount.com"
    workload_provider_name = "projects/123/locations/global/workloadIdentityPools/pool-name/providers/provider-name"
 
    # Google Default Labels configuration
    default_labels {
      strategy = "update"
      labels = {
        "environment" = "production"
        "cost-center" = "engineering"
        "owner"       = "platform-team"
        "managed-by"  = "scalr"
      }
    }
  }
}
```

Default labels are injected as the `default_labels` block in the Google provider configuration during the Terraform planning phase. They work with multiple provider configurations via aliases, allowing different label sets for different projects or regions.

# Enabling the Google Beta Provider

To use the configuration provider with the Google beta provider, you must enable the "export credentials as shell variables" option.

# Sibling pages

* [AWS Provider Configuration](https://docs.scalr.io/scalr/docs/aws.md)
* [Azure Provider Configuration](https://docs.scalr.io/scalr/docs/azure.md)
* [Scalr Provider Configuration](https://docs.scalr.io/scalr/docs/scalr.md)
* [Other Providers](https://docs.scalr.io/scalr/docs/custom-providers.md)

# What’s Next

* [Provider Configurations](https://docs.scalr.io/scalr/docs/provider-configurations.md)