-
Notifications
You must be signed in to change notification settings - Fork 0
76 lines (73 loc) · 2.55 KB
/
terraform-cloud.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
name: "Terraform Cloud"
on:
push:
branches:
- 'main'
paths:
- 'essentials/terraform-cloud/**'
- '.github/workflows/terraform-cloud.yaml'
pull_request:
types: [opened, synchronize, reopened]
branches:
- 'main'
paths:
- 'essentials/terraform-cloud/**'
- '.github/workflows/terraform-cloud.yaml'
env:
TF_API_TOKEN: ${{ secrets.TFC_API_TOKEN }}
TF_CLOUD_ORGANIZATION: ${{ vars.TFC_ORGANIZATION }}
TF_CLOUD_EMAIL: ${{ vars.TFC_ORGANIZATION_EMAIL }}
TF_PROJECT: remote-operations
TF_WORKSPACE: remote-operations
SYNC_TF_CONFIG_DIRECTORY: ./essentials/terraform-cloud
# SYNC_TF_VARS: |
# {
# tfc_api_token = "${{ secrets.TFC_API_TOKEN }}"
# organization_name = "${{ vars.TFC_ORGANIZATION }}"
# organization_email = "${{ vars.TFC_ORGANIZATION_EMAIL }}"
# }
jobs:
remote-operations:
name: Prepare Remote Operations
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
name: Checkout source code
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: "1.6.3"
- name: Ensure remote-operations exists
run: ./hacks/bootstrap-terraform-cloud.sh
terraform-apply:
name: Terraform Plan & Apply
runs-on: ubuntu-22.04
needs:
- remote-operations
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
name: Checkout source code
- name: Upload Configuration
uses: hashicorp/tfc-workflows-github/actions/[email protected]
id: upload-configuration
with:
workspace: ${{ env.TF_WORKSPACE }}
directory: ${{ env.SYNC_TF_CONFIG_DIRECTORY }}
- name: Create Plan Run
uses: hashicorp/tfc-workflows-github/actions/[email protected]
id: create-run
with:
workspace: ${{ env.TF_WORKSPACE }}
configuration_version: ${{ steps.upload-configuration.outputs.configuration_version_id }}
- name: Get Plan Output
uses: hashicorp/tfc-workflows-github/actions/[email protected]
id: plan-output
with:
plan: ${{ fromJSON(steps.create-run.outputs.payload).data.relationships.plan.data.id }}
- uses: hashicorp/tfc-workflows-github/actions/[email protected]
id: apply
with:
run: ${{ steps.create-run.outputs.run_id }}
comment: "Apply Run from GitHub Actions CI ${{ github.sha }}"