---
updatedAt: 2026-10-13T11:42:26.000Z
agentTools:
  projectIndex: https://docs.scalr.io/llms.txt
---

# scalr_workspace

## Resource: scalr\_workspace

Manages the state of workspaces in Scalr.

## Example Usage

### VCS-driven

```terraform
data "scalr_vcs_provider" "example" {
  name       = "vcs-name"
  account_id = "acc-xxxxxxxxxx"
}

data "scalr_environment" "example" {
  name       = "env-name"
  account_id = "acc-xxxxxxxxxx"
}

resource "scalr_workspace" "example" {
  name            = "my-workspace-name"
  environment_id  = data.scalr_environment.example.id
  vcs_provider_id = data.scalr_vcs_provider.example.id

  working_directory = "example/path"

  vcs_repo {
    identifier       = "org/repo"
    branch           = "dev"
    trigger_prefixes = ["stage", "prod"]
  }

  provider_configuration {
    id    = "pcfg-xxxxxxxxxx"
    alias = "us_east1"
  }
  provider_configuration {
    id    = "pcfg-yyyyyyyyyy"
    alias = "us_east2"
  }
}

resource "scalr_workspace" "trigger_patterns" {
  name            = "trigger_patterns"
  environment_id  = data.scalr_environment.example.id
  vcs_provider_id = data.scalr_vcs_provider.example.id

  working_directory = "example/path"

  vcs_repo {
    identifier       = "org/repo"
    branch           = "dev"
    trigger_patterns = <<-EOT
    !*.MD
    !/**/test/

    /infrastructure/environments/pre/
    /infrastructure/modules/app/
    /infrastructure/modules/db/
    /infrastructure/modules/queue/
    EOT
  }
}
```

### Module-driven

```terraform
data "scalr_environment" "example" {
  name       = "env-name"
  account_id = "acc-xxxxxxxxxx"
}

locals {
  modules = {
    "${data.scalr_environment.example.id}" : "module-name/provider",         # environment-level module will be selected
    "${data.scalr_environment.example.account_id}" : "module-name/provider", # account-level module will be selected
  }
}

data "scalr_module_version" "example" {
  for_each = local.modules
  source   = "${each.key}/${each.value}"
}

resource "scalr_workspace" "example" {
  for_each       = data.scalr_module_version.example
  environment_id = data.scalr_environment.example.id

  name              = replace(each.value.source, "/", "-")
  module_version_id = each.value.id
}
```

### CLI-driven

```terraform
data "scalr_environment" "example" {
  name       = "env-name"
  account_id = "acc-xxxxxxxxxx"
}

resource "scalr_workspace" "example" {
  name              = "my-workspace-name"
  environment_id    = data.scalr_environment.example.id
  working_directory = "example/path"
}
```

### Create tagged workspaces

```terraform
resource "scalr_tag" "team-a" {
  name = "TeamA"
}

resource "scalr_tag" "team-b" {
  name = "TeamB"
}

resource "scalr_workspace" "example-a" {
  environment_id = "env-xxxxxxxxxx"
  name           = "example-a"
  tag_ids        = [scalr_tag.team-a.id]
}

resource "scalr_workspace" "example-b" {
  environment_id = "env-xxxxxxxxxx"
  name           = "example-b"
  tag_ids        = [scalr_tag.team-b.id]
}
```

### Pin the runner image version

Runs executed on Scalr-managed agent pools use the account default runner image unless the workspace is pinned to a specific image version.
The `runner_image_version_id` attribute can only be used with Scalr-managed agent pools: it cannot be combined with an `agent_pool_id` that points to a self-hosted agent pool.
Remove the attribute to fall back to the account default.

```terraform
data "scalr_container_image" "runner" {
  name       = "scalr/runner"
  visibility = "system"
}

data "scalr_container_image_version" "runner" {
  container_image_id = data.scalr_container_image.runner.id
  version            = "0.5.0"
}

resource "scalr_workspace" "example" {
  name                    = "my-workspace-name"
  environment_id          = "env-xxxxxxxxxx"
  runner_image_version_id = data.scalr_container_image_version.runner.id
}
```

## Schema

### Required

* `environment_id` (String) ID of the environment, in the format `env-<RANDOM STRING>`.
* `name` (String) Name of the workspace.

### Optional

* `agent_pool_id` (String) The identifier of an agent pool in the format `apool-<RANDOM STRING>`.
* `auto_apply` (Boolean) Set (true/false) to configure if `terraform apply` should automatically run when `terraform plan` ends without error. Default `false`.
* `auto_queue_runs` (String) Indicates if runs have to be queued automatically when a new configuration version is uploaded. Supported values are `skip_first`, `always`, `never`, `on_create_only`:
  * `skip_first` - after the very first configuration version is uploaded into the workspace the run will not be triggered. But the following configurations will do. This is the default behavior.
  * `always` - runs will be triggered automatically on every upload of the configuration version.
  * `never` - configuration versions are uploaded into the workspace, but runs will not be triggered.
  * `on_create_only` - single run will be triggered only when the workspace is created and the first configuration version is uploaded. Subsequent configurations will not trigger runs.
* `deletion_protection_enabled` (Boolean) Indicates if the workspace has the protection from an accidental state lost. If enabled and the workspace has resource, the deletion will not be allowed. Default `true`.
* `execution_mode` (String) Which execution mode to use. Valid values are `remote` and `local`. When set to `local`, the workspace will be used for state storage only. Defaults to `remote`.
* `force_latest_run` (Boolean) Set (true/false) to configure if latest new run will be automatically raised in priority. Default `false`.
* `hooks` (Block List) Settings for the workspaces custom hooks. (see [below for nested schema](#nestedblock--hooks))
* `iac_platform` (String) The IaC platform to use for this workspace. Valid values are `terraform` and `opentofu`. Defaults to `terraform`.
* `module_version_id` (String) The identifier of a module version in the format `modver-<RANDOM STRING>`. This attribute conflicts with `vcs_provider_id` and `vcs_repo` attributes.
* `operations` (Boolean, Deprecated) Set (true/false) to configure workspace remote execution. When `false` workspace is only used to store state. Defaults to `true`.
* `provider_configuration` (Block Set) Provider configurations used in workspace runs. (see [below for nested schema](#nestedblock--provider_configuration))
* `remote_backend` (Boolean) Manages if Scalr exports the remote backend configuration and state storage for your infrastructure management. Disabling this feature will also prevent the ability to perform state locking, which ensures that concurrent operations do not conflict. Additionally, it will disable the capability to initiate CLI-driven runs through Scalr.
* `remote_state_consumers` (Set of String, Deprecated) The list of workspace identifiers that are allowed to access the state of this workspace. Use `["*"]` to share the state with all the workspaces within the environment (default). Conflicts with `remote_state_sharing`. Do not use it together with the `scalr_workspace_remote_state_consumer` resource.
* `remote_state_sharing` (Boolean) Whether the state of this workspace is shared with all the workspaces within the environment. Set to `false` to manage the list of consumers with the `scalr_workspace_remote_state_consumer` resource. Defaults to the account's workspace state sharing setting. Conflicts with `remote_state_consumers`.
* `run_operation_timeout` (Number) The number of minutes run operation can be executed before termination.
* `runner_image_version_id` (String) The identifier of a container image version to use as the runner image, in the format `cimgv-<RANDOM STRING>`. Use the `scalr_container_image_version` data source to look it up. Can only be used with Scalr-managed agent pools. When not set, the account default runner image is used.
* `ssh_key_id` (String) The identifier of the SSH key to use for the workspace.
* `tag_ids` (Set of String) List of tag IDs associated with the workspace.
* `terraform_version` (String) The version of Terraform to use for this workspace. Defaults to the latest available version.
* `terragrunt` (Block List) Settings for the workspace's Terragrunt configuration. (see [below for nested schema](#nestedblock--terragrunt))
* `type` (String) The type of the Scalr Workspace environment, available options: `production`, `staging`, `testing`, `development`, `unmapped`.
* `var_files` (List of String) A list of paths to the `.tfvars` file(s) to be used as part of the workspace configuration.
* `vcs_provider_id` (String) ID of VCS provider - required if vcs-repo present and vice versa, in the format `vcs-<RANDOM STRING>`.
* `vcs_repo` (Block List) Settings for the workspace's VCS repository. (see [below for nested schema](#nestedblock--vcs_repo))
* `working_directory` (String) A relative path that Terraform will be run in. Defaults to the root of the repository `""`.

### Read-Only

* `created_by` (List of Object) Details of the user that created the workspace. (see [below for nested schema](#nestedatt--created_by))
* `has_resources` (Boolean) The presence of active terraform resources in the current state version.
* `id` (String) The ID of this resource.

<a id="nestedblock--hooks"></a>

### Nested Schema for `hooks`

Optional:

* `post_apply` (String) Action that will be called after apply phase.
* `post_plan` (String) Action that will be called after plan phase.
* `pre_apply` (String) Action that will be called before apply phase.
* `pre_init` (String) Action that will be called before the init phase.
* `pre_plan` (String) Action that will be called before the plan phase.

<a id="nestedblock--provider_configuration"></a>

### Nested Schema for `provider_configuration`

Required:

* `id` (String) The identifier of provider configuration.

Optional:

* `alias` (String) The alias of provider configuration.

<a id="nestedblock--terragrunt"></a>

### Nested Schema for `terragrunt`

Required:

* `version` (String) The version of Terragrunt the workspace performs runs on.

Optional:

* `include_external_dependencies` (Boolean) Indicates whether the workspace includes external dependencies.
* `use_run_all` (Boolean) Indicates whether the workspace uses `terragrunt run-all`.

<a id="nestedblock--vcs_repo"></a>

### Nested Schema for `vcs_repo`

Required:

* `identifier` (String) A reference to your VCS repository in the format `:org/:repo`, it refers to the organization and repository in your VCS provider.

Optional:

* `branch` (String) The repository branch where Terraform will be run from. If omitted, the repository default branch will be used. Conflicts with `version_constraint`.
* `dry_runs_enabled` (Boolean) Set (true/false) to configure the VCS driven dry runs should run when pull request to configuration versions branch created. Default `true`.
* `ingress_submodules` (Boolean) Designates whether to clone git submodules of the VCS repository.
* `path` (String, Deprecated) The repository subdirectory that Terraform will execute from. If omitted or submitted as an empty string, this defaults to the repository's root.
* `trigger_patterns` (String) The gitignore-style patterns for files, whose changes will trigger a run for the workspace using this binding when the CV is created. Conflicts with `trigger_prefixes`. If `trigger_prefixes` and `trigger_patterns` are omitted, any change in `path` will trigger a new run.
* `trigger_prefixes` (List of String) List of paths (relative to `path`), whose changes will trigger a run for the workspace using this binding when the CV is created. Conflicts with `trigger_patterns`. If `trigger_prefixes` and `trigger_patterns` are omitted, any change in `path` will trigger a new run.
* `version_constraint` (String) Terraform-like version constraint used to trigger a run for matching Git tags. Conflicts with `branch`.

<a id="nestedatt--created_by"></a>

### Nested Schema for `created_by`

Read-Only:

* `email` (String)
* `full_name` (String)
* `username` (String)

## Import

Import is supported using the following syntax:

```shell
# By ID:
terraform import scalr_workspace.example ws-xxxxxxxxxx

# By environment name + workspace name:
terraform import scalr_workspace.example <environment-name>/<workspace-name>
```

# Sibling pages

* [scalr\_endpoint](https://docs.scalr.io/scalr/docs/provider_resource_scalr_endpoint.md)
* [scalr\_access\_policy](https://docs.scalr.io/scalr/docs/provider_resource_scalr_access_policy.md)
* [scalr\_account\_allowed\_ips](https://docs.scalr.io/scalr/docs/provider_resource_scalr_account_allowed_ips.md)
* [scalr\_agent\_pool](https://docs.scalr.io/scalr/docs/provider_resource_scalr_agent_pool.md)
* [scalr\_agent\_pool\_token](https://docs.scalr.io/scalr/docs/provider_resource_scalr_agent_pool_token.md)
* [scalr\_assume\_service\_account\_policy](https://docs.scalr.io/scalr/docs/provider_resource_scalr_assume_service_account_policy.md)
* [scalr\_checkov\_integration](https://docs.scalr.io/scalr/docs/provider_resource_scalr_checkov_integration.md)
* [scalr\_datadog\_integration](https://docs.scalr.io/scalr/docs/provider_resource_scalr_datadog_integration.md)
* [scalr\_docker\_integration](https://docs.scalr.io/scalr/docs/provider_resource_scalr_docker_integration.md)
* [scalr\_drift\_detection](https://docs.scalr.io/scalr/docs/provider_resource_scalr_drift_detection.md)
* [scalr\_environment](https://docs.scalr.io/scalr/docs/provider_resource_scalr_environment.md)
* [scalr\_environment\_hook](https://docs.scalr.io/scalr/docs/provider_resource_scalr_environment_hook.md)
* [scalr\_event\_bridge\_integration](https://docs.scalr.io/scalr/docs/provider_resource_scalr_event_bridge_integration.md)
* [scalr\_federated\_environments](https://docs.scalr.io/scalr/docs/provider_resource_scalr_federated_environments.md)
* [scalr\_hook](https://docs.scalr.io/scalr/docs/provider_resource_scalr_hook.md)
* [scalr\_iam\_team](https://docs.scalr.io/scalr/docs/provider_resource_scalr_iam_team.md)
* [scalr\_integration\_infracost](https://docs.scalr.io/scalr/docs/provider_resource_scalr_integration_infracost.md)
* [scalr\_module](https://docs.scalr.io/scalr/docs/provider_resource_scalr_module.md)
* [scalr\_module\_namespace](https://docs.scalr.io/scalr/docs/provider_resource_scalr_module_namespace.md)
* [scalr\_module\_test\_configuration](https://docs.scalr.io/scalr/docs/provider_resource_scalr_module_test_configuration.md)
* [scalr\_module\_test\_provider\_configuration](https://docs.scalr.io/scalr/docs/provider_resource_scalr_module_test_provider_configuration.md)
* [scalr\_policy\_group](https://docs.scalr.io/scalr/docs/provider_resource_scalr_policy_group.md)
* [scalr\_policy\_group\_linkage](https://docs.scalr.io/scalr/docs/provider_resource_scalr_policy_group_linkage.md)
* [scalr\_provider\_configuration](https://docs.scalr.io/scalr/docs/provider_resource_scalr_provider_configuration.md)
* [scalr\_provider\_configuration\_default](https://docs.scalr.io/scalr/docs/provider_resource_scalr_provider_configuration_default.md)
* [scalr\_role](https://docs.scalr.io/scalr/docs/provider_resource_scalr_role.md)
* [scalr\_run\_schedule\_rule](https://docs.scalr.io/scalr/docs/provider_resource_scalr_run_schedule_rule.md)
* [scalr\_run\_trigger](https://docs.scalr.io/scalr/docs/provider_resource_scalr_run_trigger.md)
* [scalr\_service\_account](https://docs.scalr.io/scalr/docs/provider_resource_scalr_service_account.md)
* [scalr\_service\_account\_token](https://docs.scalr.io/scalr/docs/provider_resource_scalr_service_account_token.md)
* [scalr\_slack\_integration](https://docs.scalr.io/scalr/docs/provider_resource_scalr_slack_integration.md)
* [scalr\_ssh\_key](https://docs.scalr.io/scalr/docs/provider_resource_scalr_ssh_key.md)
* [scalr\_storage\_profile](https://docs.scalr.io/scalr/docs/provider_resource_scalr_storage_profile.md)
* [scalr\_tag](https://docs.scalr.io/scalr/docs/provider_resource_scalr_tag.md)
* [scalr\_var\_set](https://docs.scalr.io/scalr/docs/provider_resource_scalr_var_set.md)
* [scalr\_variable](https://docs.scalr.io/scalr/docs/provider_resource_scalr_variable.md)
* [scalr\_vcs\_provider](https://docs.scalr.io/scalr/docs/provider_resource_scalr_vcs_provider.md)
* [scalr\_webhook](https://docs.scalr.io/scalr/docs/provider_resource_scalr_webhook.md)
* [scalr\_wiz\_integration](https://docs.scalr.io/scalr/docs/provider_resource_scalr_wiz_integration.md)
* [scalr\_workload\_identity\_provider](https://docs.scalr.io/scalr/docs/provider_resource_scalr_workload_identity_provider.md)
* [scalr\_workspace\_remote\_state\_consumer](https://docs.scalr.io/scalr/docs/provider_resource_scalr_workspace_remote_state_consumer.md)
* [scalr\_workspace\_run\_schedule](https://docs.scalr.io/scalr/docs/provider_resource_scalr_workspace_run_schedule.md)
* [scalr\_workspace\_var\_set](https://docs.scalr.io/scalr/docs/provider_resource_scalr_workspace_var_set.md)