-
Notifications
You must be signed in to change notification settings - Fork 9
144 lines (120 loc) · 4.61 KB
/
terraform_plan_cli_sonar.yml
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: 'Terraform Sonar CLI - Plan'
on:
workflow_call:
inputs:
use_modules_from_terraform_registry:
required: true
type: boolean
explicit_ref:
required: true
type: string
secrets:
AWS_ACCESS_KEY_ID:
required: true
AWS_SECRET_ACCESS_KEY:
required: true
AWS_ACCESS_KEY_ID_STAGE:
required: true
AWS_SECRET_ACCESS_KEY_STAGE:
required: true
workflow_dispatch:
inputs:
use_modules_from_terraform_registry:
type: boolean
required: false
push:
branches:
- '*'
- '!master'
- '!dev'
permissions:
contents: read
jobs:
terraform:
# name: 'Terraform'
runs-on: ubuntu-latest
environment: test
# Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
include:
- name: Sonar Basic
example: ./examples/poc/sonar_basic_deployment
- name: Sonar HADR
example: ./examples/poc/sonar_hadr_deployment
- name: Sonar Single Account
example: ./examples/installation/sonar_single_account_deployment
- name: Sonar Multi Account
example: ./examples/installation/sonar_multi_account_deployment
name: '${{ matrix.name }}'
env:
TF_CLI_ARGS: "-no-color"
TF_INPUT: 0
AWS_REGION: us-west-2
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
steps:
- name: Pick ref
run: |
if [ -z "${{ inputs.explicit_ref }}" ]; then
echo REF=${{ github.ref }} >> $GITHUB_ENV;
else
echo REF=${{ inputs.explicit_ref }} >> $GITHUB_ENV;
fi
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ env.REF }}
- name: Change the modules source to local
if: ${{ inputs.use_modules_from_terraform_registry == false }}
run: |
find ./examples/ -type f -exec sed -i -f sed.expr {} \;
# Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: ~1.5.0
- name: Configure AWS credentials - innodev
if: contains(matrix.name, 'single account') || contains(matrix.name, 'multi account')
run: |
aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }} --profile innodev
aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }} --profile innodev
- name: Configure AWS credentials - innostage
if: contains(matrix.name, 'single account') || contains(matrix.name, 'multi account')
run: |
aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID_STAGE }} --profile innostage
aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY_STAGE }} --profile innostage
- name: Get AWS credentials
run: |
aws sts get-caller-identity
- name: Create tfvars File
if: contains(matrix.name, 'Single Account') || contains(matrix.name, 'Multi Account')
run: |
if [ "${{ matrix.name }}" == "Sonar Single Account" ]; then
cat << EOF > "${{ matrix.example }}/terraform.tfvars"
${{ vars.TFVAR_PARAMETERS_SINGLE_ACCOUNT_AUTOMATION }}
EOF
elif [ "${{ matrix.name }}" == "Sonar Multi Account" ]; then
cat << EOF > "${{ matrix.example }}/terraform.tfvars"
${{ vars.TFVAR_PARAMETERS_MULTI_ACCOUNT_AUTOMATION }}
EOF
fi
- name: View The Vars
if: contains(matrix.name, 'single account') || contains(matrix.name, 'multi account')
run: cat ${{ matrix.example }}/terraform.tfvars
# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
- name: Terraform Init
run: terraform -chdir=${{ matrix.example }} init
- name: Terraform Validate
run: terraform -chdir=${{ matrix.example }} validate
# Checks that all Terraform configuration files adhere to a canonical format
- name: Terraform Format
run: terraform fmt -check
continue-on-error: true
# Generates an execution plan for Terraform
- name: Terraform Plan
run: terraform -chdir=${{ matrix.example }} plan