Merge pull request #34 from deploymenttheory/feat-test #23
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Demo | Workflow 2 - Apply Targetted at Staging from Main | |
on: | |
# Manual trigger options - debug only | |
workflow_dispatch: | |
inputs: | |
environment: | |
description: "Target RTL Environment" | |
required: true | |
type: choice | |
options: | |
- sandbox | |
- staging | |
- production | |
push: | |
# if the target is main | |
branches: | |
- main | |
# if .tf files in this directory are part of the diff. | |
paths: | |
- 'workload/terraform/jamfpro/*.tf' | |
jobs: | |
terraform-upload-plan-apply: | |
environment: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || 'staging' }} | |
runs-on: ubuntu-latest | |
env: | |
TF_API_KEY: ${{ secrets.TF_API_KEY }} | |
TF_CLOUD_ORGANIZATION: ${{ vars.TF_CLOUD_ORG }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Upload configuration to tf cloud | |
uses: hashicorp/tfc-workflows-github/actions/[email protected] | |
id: upload-config | |
with: | |
token: ${{ secrets.TF_API_KEY }} | |
workspace: ${{ vars.TF_WORKSPACE }} | |
directory: "workload/terraform/jamfpro" | |
- name: Terraform plan | |
id: terraform-plan | |
uses: hashicorp/tfc-workflows-github/actions/[email protected] | |
with: | |
token: ${{ secrets.TF_API_KEY }} | |
workspace: ${{ vars.TF_WORKSPACE }} | |
configuration_version: ${{ steps.upload-config.outputs.configuration_version_id }} | |
- name: Terraform Apply | |
id: terraform-apply | |
uses: hashicorp/tfc-workflows-github/actions/[email protected] | |
with: | |
token: ${{ secrets.TF_API_KEY }} | |
run: ${{ steps.terraform-plan.outputs.run_id }} | |
- name: Save outputs to file | |
run: | | |
cat << EOF > ${{ vars.OUTPUTS_FILE_FN }} | |
{ | |
"pr_number": ${{ github.event.pull_request.number }} | |
"status": ${{ steps.terraform-apply.outputs.status }} | |
} | |
EOF | |
- name: Upload outputs json file as artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ vars.APPLY_OUTPUT_ARTIFACT_NAME }} | |
path: ${{ vars.OUTPUTS_FILE_FN }} | |
retention-days: 0 | |
update-pr: | |
name: Deposit plan output on trigger pr | |
needs: terraform-upload-plan-apply | |
uses: ./.github/workflows/update_pr.yml | |
with: | |
outputs-payload: ${{ vars.APPLY_OUTPUT_ARTIFACT_NAME }} | |