-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds support for creating new workspaces (#27)
* added workspace new * renamed select test file * moved to feature folder * doc'd workspace new
- Loading branch information
1 parent
d6c4a78
commit 5e19414
Showing
9 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { CommandResponse, ICommand } from "."; | ||
import { ITaskContext } from "../context"; | ||
import { IRunner } from "../runners"; | ||
import { RunWithTerraform } from "../runners/builders"; | ||
|
||
export class TerraformWorkspaceNew implements ICommand { | ||
constructor( | ||
private readonly runner: IRunner | ||
) { | ||
} | ||
|
||
async exec(ctx: ITaskContext): Promise<CommandResponse> { | ||
const options = await new RunWithTerraform(ctx, false, ctx.workspaceSubCommand, [ctx.name]) | ||
.withCommandOptions(ctx.commandOptions) | ||
.withWorkspace(ctx.workspaceName) | ||
.build(); | ||
|
||
const result = await this.runner.exec(options); | ||
|
||
return result.toCommandResponse(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
tasks/terraform-cli/src/tests/features/workspace/stdout-new-workspace-bar.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
\u001b[0m\u001b[32m\u001b[1mCreated and switched to workspace \"bar\"!\u001b[0m\u001b[32m\n\nYou're now on a new, empty workspace. Workspaces isolate their state,\nso if you run \"terraform plan\" Terraform will not see any existing state\nfor this configuration.\u001b[0m\n |
30 changes: 30 additions & 0 deletions
30
tasks/terraform-cli/src/tests/features/workspace/terraform-workspace-new.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Feature: terraform workspace new | ||
|
||
terraform workspace new [OPTIONS] [name] [DIR] | ||
|
||
Scenario: new workspace | ||
Given terraform exists | ||
And terraform command is "workspace" | ||
And workspace command is "new" with name "bar" | ||
And running command "terraform workspace new bar" returns successful result with stdout from file "./src/tests/features/workspace/stdout-new-workspace-bar.txt" | ||
When the terraform cli task is run | ||
Then the terraform cli task executed command "terraform workspace new bar" | ||
And the terraform cli task is successful | ||
|
||
Scenario: new workspace with command options | ||
Given terraform exists | ||
And terraform command is "workspace" with options "-state=terraform.tfstate" | ||
And workspace command is "new" with name "bar" | ||
And running command "terraform workspace new -state=terraform.tfstate bar" returns successful result with stdout from file "./src/tests/features/workspace/stdout-new-workspace-bar.txt" | ||
When the terraform cli task is run | ||
Then the terraform cli task executed command "terraform workspace new -state=terraform.tfstate bar" | ||
And the terraform cli task is successful | ||
|
||
Scenario: new workspace already exists | ||
Given terraform exists | ||
And terraform command is "workspace" | ||
And workspace command is "new" with name "bar" | ||
And running command "terraform workspace new bar" fails with error "\u001b[31mWorkspace \"bar\" already exists\u001b[0m\u001b[0m\n" | ||
When the terraform cli task is run | ||
Then the terraform cli task executed command "terraform workspace new bar" | ||
And the terraform cli task fails with message "\u001b[31mWorkspace \"bar\" already exists\u001b[0m\u001b[0m\n" |
File renamed without changes.