diff --git a/.github/workflows/base-deployment.yml b/.github/workflows/base-deployment.yml new file mode 100644 index 00000000..cd4a40be --- /dev/null +++ b/.github/workflows/base-deployment.yml @@ -0,0 +1,92 @@ +on: + workflow_call: + inputs: + environment: + description: "Which Environment settings to use" + required: true + type: string + default: "dev" + is_deployment: + description: "Do you want to run Terraform Apply" + type: boolean + default: false + + workflow_dispatch: + inputs: + environment: + description: "Which Environment settings to use" + required: true + type: choice + options: + - dev + - pre-prod + - prod + is_deployment: + description: "Do you want to run Terraform Apply" + type: boolean + default: false + +name: Base Plan and Apply +permissions: + contents: read + id-token: write + pull-requests: write + +jobs: + plan: + name: ${{ inputs.environment }} - Plan and Apply + runs-on: ubuntu-latest + environment: ${{ inputs.environment }} + defaults: + run: + working-directory: ./terraform + steps: + - name: Set up git repo + uses: actions/checkout@v4 + + - name: Set up Terraform + uses: hashicorp/setup-terraform@v3 + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ secrets.IAM_ROLE }} + aws-region: eu-west-2 + mask-aws-account-id: true + + - name: terraform init + id: init + run: terraform init -no-color -upgrade -backend-config="bucket=${{ secrets.TF_BACKEND_BUCKET }}" -backend-config="key=${{ secrets.TF_BACKEND_KEY }}" -backend-config="dynamodb_table=${{ secrets.TF_BACKEND_DYNAMODB_TABLE }}" + + - name: terraform validate + id: validate + run: terraform validate -no-color + + ## REPOSITORY SPECIFIC ## + - name: Setup Terraform variables + id: vars + run: | + COMMON_ACCOUNT_ID=$(aws ssm get-parameter --name /repo/ci/user-input/external/aws-account-id --with-decryption | jq -r .Parameter.Value) + cat > pipeline.auto.tfvars <