diff --git a/.github/workflows/deployment.yaml b/.github/workflows/deployment.yaml index 4d8dbdc7..2b841ae1 100644 --- a/.github/workflows/deployment.yaml +++ b/.github/workflows/deployment.yaml @@ -22,9 +22,25 @@ permissions: contents: read packages: write jobs: + setEnv: + name: Set environment variable + runs-on: ubuntu-latest + steps: + - name: Set env + run: |- + echo "ENVIRONMENT=$( + if ${{ github.event.inputs.environment }}; then + echo ${{ github.event.inputs.environment }} + elif [ ${{ github.ref_name }} == main]; then + echo prod + else + echo dev2 + fi + )" >> $GITHUB_ENV terraform: name: Run Terraform (${{github.event.inputs.environment}}) runs-on: ubuntu-latest + needs: [setEnv] environment: main defaults: run: @@ -82,11 +98,7 @@ jobs: CLIENT_ID: ${{ secrets.CLIENT_ID }} run: |- echo "tf_env=$( - if [[ "${{ github.event.inputs.environment }}" != "" ]]; then - echo ${{ github.event.inputs.environment }} - else - echo dev - fi + echo ${{ env.ENVIRONMENT }} )" >> $GITHUB_OUTPUT echo "short_cid=${CLIENT_ID:0:8}" >> $GITHUB_OUTPUT @@ -97,6 +109,7 @@ jobs: ARM_SUBSCRIPTION_ID: ${{ secrets.SUBSCRIPTION_ID }} TF_ENV: ${{ steps.set-environment.outputs.tf_env }} run: | + asdf terraform init -backend-config=backend.tfvars terraform workspace select -or-create $TF_ENV terraform apply -auto-approve -lock-timeout=30m