azure-pipelines-tasks-terraform icon indicating copy to clipboard operation
azure-pipelines-tasks-terraform copied to clipboard

Support Workspace Commands

Open charleszipp opened this issue 6 years ago • 4 comments

As a release engineer, I would like to be able to create and select a terraform workspace, so that I can test features in isolated infrastructure.

Supported Sub-Commands

Workspace commands will be added in the following order

  • [x] select
  • [x] new
  • [ ] new succeeds when workspace exists with toggle to fail if exists (backwards compatibility)
  • [ ] show
  • [ ] delete
  • [ ] list

Select is being used first so those with existing workspaces can use this immediately after that work is completed.

Expected YAML Syntax

The following is the yaml expected to use workspaces. Final syntax will be added to the Overview doc paired with examples in pipelines/test directory.

Workspace Select

- task: TerraformCLI@0
  displayName: 'terraform workspace select'
  inputs:
    command: workspace
    workspaceName: foo
    workspaceSubCommand: select
    workingDirectory: $(terraform_templates_dir)

charleszipp avatar Dec 21 '18 17:12 charleszipp

For those that upvoted this issue, curious to hear feedback on how you would expect this extension to handle running terraform workspace new foo where foo workspace already exists. In this case, terraform returns exit code 1 (failure/error). Would you expect the task to fail as well in this case? If not what would you prefer?

charleszipp avatar May 14 '21 14:05 charleszipp

@charleszipp you appear to have released the "new" functionality, I would have expected it to in reality to not fail as it would be the precursor step for all new environments, what did you end up deciding?

rvowles avatar May 30 '21 09:05 rvowles

@rvowles, the feedback I have collected so far definitely favors what you are suggesting. As I suspected, most prefer to design pipelines to be idempotent. new failing if the workspace exists contradicts this. In a subsequent release, I expect a flag will be added to toggle failure if the workspace exists. This will be false by default (succeeds even if workspace exists). However, for those that have cases where they depend on the failure that terraform emits in this case, they can use that toggle to emit the failure.

Appreciate the feedback!

charleszipp avatar Jun 01 '21 14:06 charleszipp

I'm keen to have the workspace delete command. Any ETA on when this could be done? My use case is where users at my company create any number of temporary environments using a workspace as the environment name (using ADO story as workspace name). After they finished the workspace will be deleted (step I can't do with this currently).

SamuelGarratt avatar Jun 30 '21 04:06 SamuelGarratt