2017-05-31 02:46:12 +02:00
|
|
|
---
|
2020-10-27 01:58:30 +01:00
|
|
|
layout: "docs"
|
2017-05-31 02:46:12 +02:00
|
|
|
page_title: "Command: workspace new"
|
2018-12-21 03:18:13 +01:00
|
|
|
sidebar_current: "docs-commands-workspace-sub-new"
|
2017-05-31 02:46:12 +02:00
|
|
|
description: |-
|
|
|
|
The terraform workspace new command is used to create a new workspace.
|
|
|
|
---
|
|
|
|
|
|
|
|
# Command: workspace new
|
|
|
|
|
|
|
|
The `terraform workspace new` command is used to create a new workspace.
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
2020-11-11 23:21:21 +01:00
|
|
|
Usage: `terraform workspace new [OPTIONS] NAME [DIR]`
|
2017-05-31 02:46:12 +02:00
|
|
|
|
|
|
|
This command will create a new workspace with the given name. A workspace with
|
|
|
|
this name must not already exist.
|
|
|
|
|
|
|
|
If the `-state` flag is given, the state specified by the given path
|
|
|
|
will be copied to initialize the state for this new workspace.
|
|
|
|
|
2021-01-26 17:34:48 +01:00
|
|
|
The command-line flags are all optional. The supported flags are:
|
2017-05-31 02:46:12 +02:00
|
|
|
|
2021-05-12 18:05:03 +02:00
|
|
|
* `-lock=false` - Don't hold a state lock during the operation. This is
|
|
|
|
dangerous if others might concurrently run commands against the same
|
|
|
|
workspace.
|
|
|
|
* `-lock-timeout=DURATION` - Duration to retry a state lock. Default 0s.
|
2020-11-11 23:21:21 +01:00
|
|
|
* `-state=path` - Path to an existing state file to initialize the state of this environment.
|
2017-05-31 02:46:12 +02:00
|
|
|
|
|
|
|
## Example: Create
|
|
|
|
|
|
|
|
```
|
|
|
|
$ terraform workspace new example
|
|
|
|
Created and switched to workspace "example"!
|
|
|
|
|
|
|
|
You're now on a new, empty workspace. Workspaces isolate their state,
|
|
|
|
so if you run "terraform plan" Terraform will not see any existing state
|
|
|
|
for this configuration.
|
|
|
|
```
|
|
|
|
|
|
|
|
## Example: Create from State
|
|
|
|
|
|
|
|
To create a new workspace from a pre-existing local state file:
|
|
|
|
|
|
|
|
```
|
|
|
|
$ terraform workspace new -state=old.terraform.tfstate example
|
|
|
|
Created and switched to workspace "example".
|
|
|
|
|
|
|
|
You're now on a new, empty workspace. Workspaces isolate their state,
|
|
|
|
so if you run "terraform plan" Terraform will not see any existing state
|
|
|
|
for this configuration.
|
|
|
|
```
|