diff --git a/.github/workflows/bootstrap.yml b/.github/workflows/bootstrap.yml index 49a5090..7644764 100644 --- a/.github/workflows/bootstrap.yml +++ b/.github/workflows/bootstrap.yml @@ -55,7 +55,7 @@ jobs: if: steps.check_backend.outputs.backend_exists == 'false' run: | terraform init - terraform workspace new ${{ github.event.inputs.environment }} + terraform workspace select ${{ github.event.inputs.environment }} || terraform workspace new ${{ github.event.inputs.environment }} terraform apply -auto-approve working-directory: ./bootstrap/setup-backend @@ -72,6 +72,6 @@ jobs: -backend-config="dynamodb_table=${{ vars.ORGANIZATION }}-terraform-lock-table-${{ github.event.inputs.environment }}" \ -backend-config="key=bootstrap/terraform.tfstate" - terraform workspace new ${{ github.event.inputs.environment }} + terraform workspace select ${{ github.event.inputs.environment }} || terraform workspace new ${{ github.event.inputs.environment }} terraform apply -auto-approve working-directory: ./bootstrap/setup-oidc \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index aec4342..6be1017 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -135,12 +135,12 @@ jobs: organization=${{ env.TF_VAR_organization }} \ cleanup_policies=${{ github.event_name == 'schedule' || github.event.inputs.cleanup_policies == 'true' }} - terraform workspace new ${{ needs.setup.outputs.env }} + terraform workspace select ${{ needs.setup.outputs.env }} || terraform workspace new ${{ needs.setup.outputs.env }} chmod +x ./scripts/ci_retry_command.sh - name: ${{ (github.event_name == 'pull_request' && format('Terraform Plan{0}', matrix.step == 'iam' && ' & Apply' || '')) || 'Terraform Apply' }} run: | - terraform workspace select ${{ needs.setup.outputs.env }} + terraform workspace select ${{ needs.setup.outputs.env }} || terraform workspace new ${{ needs.setup.outputs.env }} if [ ${{ github.event_name }} == 'pull_request' ]; then if [ ${{ matrix.step }} == 'iam' ]; then terraform plan -lock=false diff --git a/.github/workflows/destroy.yml b/.github/workflows/destroy.yml index 9b20427..fde53d7 100644 --- a/.github/workflows/destroy.yml +++ b/.github/workflows/destroy.yml @@ -79,7 +79,7 @@ jobs: organization=${{ env.TF_VAR_organization }} \ cleanup_policies=true - terraform workspace new ${{ github.event.inputs.environment }} + terraform workspace select ${{ github.event.inputs.environment }} || terraform workspace new ${{ github.event.inputs.environment }} chmod +x ./scripts/ci_retry_command.sh - name: Terraform Destroy diff --git a/.github/workflows/remove_tf_state.yml b/.github/workflows/remove_tf_state.yml index 3c07159..2ee2ff3 100644 --- a/.github/workflows/remove_tf_state.yml +++ b/.github/workflows/remove_tf_state.yml @@ -78,12 +78,12 @@ jobs: organization=${{ env.TF_VAR_organization }} \ cleanup_policies=true - terraform workspace new ${{ github.event.inputs.environment }} + terraform workspace select ${{ github.event.inputs.environment }} || terraform workspace new ${{ github.event.inputs.environment }} chmod +x ./scripts/ci_retry_command.sh - name: Check and Remove Resource from Terraform State run: | - terraform workspace select ${{ github.event.inputs.environment }} + terraform workspace select ${{ github.event.inputs.environment }} || terraform workspace new ${{ github.event.inputs.environment }} echo "Removing resource: ${{ inputs.tf-rm }}" terraform state rm '${{ inputs.tf-rm }}' working-directory: ${{ env.TF_ROOT_DIRECTORY }} \ No newline at end of file