scalr_workspace

Resource: scalr_workspace

Manages the state of workspaces in Scalr.

Example Usage

VCS-driven

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

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

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

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]
}

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:
    • 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.
  • 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)
  • 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)
  • remote_state_consumers (Set of String) 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).
  • run_operation_timeout (Number) The number of minutes run operation can be executed before termination.
  • 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)
  • 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)
  • 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)
  • has_resources (Boolean) The presence of active terraform resources in the current state version.
  • id (String) The ID of this resource.

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.

Nested Schema for provider_configuration

Required:

  • id (String) The identifier of provider configuration.

Optional:

  • alias (String) The alias of provider configuration.

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.

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.
  • 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.

Nested Schema for created_by

Read-Only:

  • email (String)
  • full_name (String)
  • username (String)

Import

Import is supported using the following syntax:

terraform import scalr_workspace.example ws-xxxxxxxxxx