|
| 1 | +--- |
| 2 | +layout: "tfe" |
| 3 | +page_title: "Terraform Enterprise: tfe_workspace_setting" |
| 4 | +description: |- |
| 5 | + Manages workspace settings. |
| 6 | +--- |
| 7 | + |
| 8 | +# tfe_workspace_settings |
| 9 | + |
| 10 | +Manages or reads execution mode and agent pool settings for a workspace. If [tfe_organization_default_settings](organization_default_settings.html) are used, those settings may be read using a combination of the read-only `overwrites` argument and the setting itself. |
| 11 | + |
| 12 | +## Example Usage |
| 13 | + |
| 14 | +Basic usage: |
| 15 | + |
| 16 | +```hcl |
| 17 | +resource "tfe_organization" "test-organization" { |
| 18 | + name = "my-org-name" |
| 19 | + |
| 20 | +} |
| 21 | +
|
| 22 | +resource "tfe_workspace" "test" { |
| 23 | + name = "my-workspace-name" |
| 24 | + organization = tfe_organization.test-organization.name |
| 25 | +} |
| 26 | +
|
| 27 | +resource "tfe_workspace_settings" "test-settings" { |
| 28 | + workspace_id = tfe_workspace.test.id |
| 29 | + execution_mode = "local" |
| 30 | +} |
| 31 | +``` |
| 32 | + |
| 33 | +With `execution_mode` of `agent`: |
| 34 | + |
| 35 | +```hcl |
| 36 | +resource "tfe_organization" "test-organization" { |
| 37 | + name = "my-org-name" |
| 38 | + |
| 39 | +} |
| 40 | +
|
| 41 | +resource "tfe_agent_pool" "test-agent-pool" { |
| 42 | + name = "my-agent-pool-name" |
| 43 | + organization = tfe_organization.test-organization.name |
| 44 | +} |
| 45 | +
|
| 46 | +resource "tfe_agent_pool_allowed_workspaces" "test" { |
| 47 | + agent_pool_id = tfe_agent_pool.test-agent-pool.id |
| 48 | + allowed_workspace_ids = [tfe_workspace.test.id] |
| 49 | +} |
| 50 | +
|
| 51 | +resource "tfe_workspace" "test" { |
| 52 | + name = "my-workspace-name" |
| 53 | + organization = tfe_organization.test-organization.name |
| 54 | +} |
| 55 | +
|
| 56 | +resource "tfe_workspace_settings" "test-settings" { |
| 57 | + workspace_id = tfe_workspace.test.id |
| 58 | + agent_pool_id = tfe_agent_pool.test-agent-pool.id |
| 59 | + execution_mode = "agent" |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +This resource may be used as a data source when no optional arguments are defined: |
| 64 | + |
| 65 | +```hcl |
| 66 | +data "tfe_workspace" "test" { |
| 67 | + name = "my-workspace-name" |
| 68 | + organization = "my-org-name" |
| 69 | +} |
| 70 | +
|
| 71 | +resource "tfe_workspace_settings" "test" { |
| 72 | + workspace_id = data.tfe_workspace.test.id |
| 73 | +} |
| 74 | +
|
| 75 | +output "workspace-explicit-local-execution" { |
| 76 | + value = alltrue([ |
| 77 | + tfe_workspace_settings.test.execution_mode == "local", |
| 78 | + tfe_workspace_settings.test.overwrites[0]["execution_mode"] |
| 79 | + ]) |
| 80 | +} |
| 81 | +``` |
| 82 | + |
| 83 | +## Argument Reference |
| 84 | + |
| 85 | +The following arguments are supported: |
| 86 | + |
| 87 | +* `workspace_id` - (Required) ID of the workspace. |
| 88 | +* `agent_pool_id` - (Optional) The ID of an agent pool to assign to the workspace. Requires `execution_mode` |
| 89 | + to be set to `agent`. This value _must not_ be provided if `execution_mode` is set to any other value. |
| 90 | +* `execution_mode` - (Optional) Which [execution mode](https://developer.hashicorp.com/terraform/cloud-docs/workspaces/settings#execution-mode) |
| 91 | + to use. Using Terraform Cloud, valid values are `remote`, `local` or `agent`. Defaults your organization's default execution mode, or `remote` if no organization default is set. Using Terraform Enterprise, only `remote` and `local` execution modes are valid. When set to `local`, the workspace will be used for state storage only. |
| 92 | + |
| 93 | +## Attributes Reference |
| 94 | + |
| 95 | +In addition to all arguments above, the following attributes are exported: |
| 96 | + |
| 97 | +* `id` - The workspace ID. |
| 98 | +* `overwrites` - Can be used to check whether a setting is currently inheriting its value from another resource. |
| 99 | + - `execution_mode` - Set to `true` if the execution mode of the workspace is being determined by the setting on the workspace itself. It will be `false` if the execution mode is inherited from another resource (e.g. the organization's default execution mode) |
| 100 | + - `agent_pool` - Set to `true` if the agent pool of the workspace is being determined by the setting on the workspace itself. It will be `false` if the agent pool is inherited from another resource (e.g. the organization's default agent pool) |
| 101 | + |
| 102 | +## Import |
| 103 | + |
| 104 | +Workspaces can be imported; use `<WORKSPACE ID>` or `<ORGANIZATION NAME>/<WORKSPACE NAME>` as the |
| 105 | +import ID. For example: |
| 106 | + |
| 107 | +```shell |
| 108 | +terraform import tfe_workspace_settings.test ws-CH5in3chf8RJjrVd |
| 109 | +``` |
| 110 | + |
| 111 | +```shell |
| 112 | +terraform import tfe_workspace_settings.test my-org-name/my-wkspace-name |
| 113 | +``` |
0 commit comments