-
Notifications
You must be signed in to change notification settings - Fork 2
103 lines (89 loc) · 3.27 KB
/
Copy pathdeploy-to-control-plane.yml
File metadata and controls
103 lines (89 loc) · 3.27 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Control Plane Github Action
name: Deploy-To-Control-Plane
# Controls when the workflow will run
on:
# Triggers the workflow on push events but only for the dev branch
# push:
# branches: [main, dev]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
apply:
description: "Apply Terraform"
required: true
default: "false"
ref:
description: "Specific Commit SHA (leave empty for latest)"
required: false
default: ""
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
plan:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v2
- name: Run input action for dev branch
if: ${{ github.ref == 'refs/heads/dev' }}
uses: ./.github/actions/inputs
with:
org: ${{ secrets.CPLN_ORG }}
token: ${{ secrets.CPLN_TOKEN }}
control_plane_terraform_version: ${{ secrets.TF_PROVIDER_VERSION }}
gvc: ${{ secrets.CPLN_GVC_DEV }}
workload: ${{ secrets.CPLN_WORKLOAD_DEV }}
image: ${{ secrets.CPLN_IMAGE_NAME_DEV }}
tag: $(git rev-parse --short HEAD)
terraform_workspace: ${{ secrets.TF_WORKSPACE_DEV }}
- name: Run input action for main branch
if: ${{ github.ref == 'refs/heads/main' }}
uses: ./.github/actions/inputs
with:
org: ${{ secrets.CPLN_ORG }}
token: ${{ secrets.CPLN_TOKEN }}
control_plane_terraform_version: ${{ secrets.TF_PROVIDER_VERSION }}
gvc: ${{ secrets.CPLN_GVC_MAIN }}
workload: ${{ secrets.CPLN_WORKLOAD_MAIN }}
image: ${{ secrets.CPLN_IMAGE_NAME_MAIN }}
tag: $(git rev-parse --short HEAD)
terraform_workspace: ${{ secrets.TF_WORKSPACE_MAIN }}
- name: Containerize application and push image to Control Plane
if: ${{ github.event.inputs.apply == 'true' }}
shell: bash
run: |
cpln profile update default --token ${{ secrets.CPLN_TOKEN }}
cpln image docker-login
cpln image build --name ${TF_VAR_image} --dockerfile ./Dockerfile --push
- name: Set Terraform Cloud Token
id: terraform_token
shell: bash
working-directory: ./terraform
run: |
sed -i 's/1/${{ secrets.TF_CLOUD_TOKEN }}/' .terraformrc
# Install the latest version of Terraform CLI
- name: Set up Terraform
uses: hashicorp/setup-terraform@v1
# Initialize Terraform
- name: Terraform Init
id: init
shell: bash
working-directory: ./terraform
run: terraform init -upgrade
# Validate Terraform configuration
- name: Terraform Validate
id: validate
shell: bash
working-directory: ./terraform
run: terraform validate
- name: Terraform Plan
if: ${{ github.event.inputs.apply != 'true' }}
id: plan
shell: bash
working-directory: ./terraform
run: terraform plan -input=false
- name: Terraform Apply
if: ${{ github.event.inputs.apply == 'true' }}
id: apply
shell: bash
working-directory: ./terraform
run: terraform apply -input=false -auto-approve