Skip to content

Commit

Permalink
Silence terraform workspace select
Browse files Browse the repository at this point in the history
  • Loading branch information
carlssonk committed Sep 28, 2024
1 parent a5785fe commit 9c40637
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/bootstrap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
if: steps.check_backend.outputs.backend_exists == 'false'
run: |
terraform init
terraform workspace select ${{ github.event.inputs.environment }} || terraform workspace new ${{ github.event.inputs.environment }}
terraform workspace select ${{ github.event.inputs.environment }} 2>/dev/null || terraform workspace new ${{ github.event.inputs.environment }}
terraform apply -auto-approve
working-directory: ./bootstrap/setup-backend

Expand All @@ -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 select ${{ github.event.inputs.environment }} || terraform workspace new ${{ github.event.inputs.environment }}
terraform workspace select ${{ github.event.inputs.environment }} 2>/dev/null || terraform workspace new ${{ github.event.inputs.environment }}
terraform apply -auto-approve
working-directory: ./bootstrap/setup-oidc
3 changes: 1 addition & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,11 @@ jobs:
organization=${{ env.TF_VAR_organization }} \
cleanup_policies=${{ github.event_name == 'schedule' || github.event.inputs.cleanup_policies == 'true' }}
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 new ${{ needs.setup.outputs.env }}
terraform workspace select ${{ needs.setup.outputs.env }} 2>/dev/null || terraform workspace new ${{ needs.setup.outputs.env }}
if [ ${{ github.event_name }} == 'pull_request' ]; then
if [ ${{ matrix.step }} == 'iam' ]; then
terraform plan -lock=false
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,11 @@ jobs:
organization=${{ env.TF_VAR_organization }} \
cleanup_policies=true
terraform workspace select ${{ github.event.inputs.environment }} || terraform workspace new ${{ github.event.inputs.environment }}
chmod +x ./scripts/ci_retry_command.sh
- name: Terraform Destroy
run: |
terraform workspace select ${{ github.event.inputs.environment }} || terraform workspace new ${{ github.event.inputs.environment }}
terraform workspace select ${{ github.event.inputs.environment }} 2>/dev/null || terraform workspace new ${{ github.event.inputs.environment }}
if ! ../../scripts/ci_retry_command.sh "terraform destroy -lock=false -auto-approve -var-file='${{ env.TFVARS_FILE_NAME }}.tfvars'"; then
echo "Terraform failed after all retry attempts"
exit 1
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/remove_tf_state.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,11 @@ jobs:
organization=${{ env.TF_VAR_organization }} \
cleanup_policies=true
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 new ${{ github.event.inputs.environment }}
terraform workspace select ${{ github.event.inputs.environment }} 2>/dev/null || 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 }}

0 comments on commit 9c40637

Please sign in to comment.