9
9
required : true
10
10
type : string
11
11
terraform_version :
12
- required : true
12
+ required : false
13
13
type : string
14
+ default : latest
14
15
roleArn :
15
16
required : true
16
17
type : string
20
21
github_event_number :
21
22
required : true
22
23
type : string
23
- github_event_issue_url :
24
- required : true
25
- type : string
26
24
github_event_issue_comments_url :
27
25
required : true
28
26
type : string
29
27
github_event_repository_url :
30
28
required : true
31
29
type : string
30
+ stack :
31
+ required : false
32
+ type : string
33
+ default : " ."
32
34
33
35
34
36
jobs :
81
83
uses : actions/checkout@v4
82
84
with :
83
85
ref : refs/pull/${{ inputs.github_event_number }}/merge
86
+ - run : echo "REPOSITORY_NAME=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV
87
+ shell : bash
84
88
85
89
# Install the latest version of Terraform CLI
86
90
- name : Setup Terraform
@@ -90,38 +94,63 @@ jobs:
90
94
91
95
# Initialize Terraform
92
96
- name : Terraform Init
93
- run : terraform init -upgrade
97
+ run : |
98
+ cd ${{ inputs.stack }}
99
+ terraform init -upgrade
94
100
95
- # Checks that all Terraform configuration files adhere to a canonical format
96
- - name : Terraform Format LandingZone
97
- run : terraform fmt -check
101
+ # Terraform Validation Steps
102
+ - name : terraform validate ${{ inputs.stack }}
103
+ uses : dflook/terraform-validate@v1
104
+ with :
105
+ path : ${{ inputs.stack }}
106
+ env :
107
+ TERRAFORM_HTTP_CREDENTIALS : |
108
+ github.com/arvatoaws=oauth:${{ steps.generate-token.outputs.token }}
109
+ GITHUB_TOKEN : ${{ steps.generate-token.outputs.token }}
110
+ TERRAFORM_ACTIONS_GITHUB_TOKEN : ${{ steps.generate-token.outputs.token }}
111
+ GITHUB_APP_ID : ${{ secrets.TERRAFORM_GITHUB_ACTION_APP_ID }}
112
+ GITHUB_APP_PEM_FILE : ${{ secrets.TERRAFORM_GITHUB_ACTION_PRIVATE_KEY }}
113
+ - name : terraform fmt ${{ inputs.stack }}
114
+ uses : dflook/terraform-fmt-check@v1
115
+ with :
116
+ path : ${{ inputs.stack }}
117
+ env :
118
+ TERRAFORM_HTTP_CREDENTIALS : |
119
+ github.com/arvatoaws=oauth:${{ steps.generate-token.outputs.token }}
120
+ GITHUB_TOKEN : ${{ steps.generate-token.outputs.token }}
121
+ TERRAFORM_ACTIONS_GITHUB_TOKEN : ${{ steps.generate-token.outputs.token }}
122
+ GITHUB_APP_ID : ${{ secrets.TERRAFORM_GITHUB_ACTION_APP_ID }}
123
+ GITHUB_APP_PEM_FILE : ${{ secrets.TERRAFORM_GITHUB_ACTION_PRIVATE_KEY }}
98
124
99
125
# Download the plan from S3
100
126
- name : Download Plan from S3
101
127
run : |
102
- aws s3 cp s3://${{ inputs.s3bucketName }}/plans/tfplan ./tfplan
128
+ cd ${{ inputs.stack }}
129
+ aws s3 cp s3://${{ inputs.s3bucketName }}/plans/${{ github.repository }}/${{ inputs.stack }}/${{ inputs.github_event_number }}/tfplan ./tfplan
103
130
104
131
# Build or change infrastructure according to Terraform configuration files
105
132
- name : Terraform Apply
106
133
id : apply
107
134
continue-on-error : true
108
135
run : |
136
+ cd ${{ inputs.stack }}
109
137
terraform apply -input=false -no-color tfplan
110
138
# Upload the plan to S3
111
139
- name : Upload Plan to S3
112
140
run : |
113
- aws s3 cp ./tfplan s3://${{ inputs.s3bucketName }}/plans/
141
+ cd ${{ inputs.stack }}
142
+ aws s3 cp ./tfplan s3://${{ inputs.s3bucketName }}/plans/${{ github.repository }}/${{ inputs.stack }}/${{ inputs.github_event_number }}/
114
143
115
144
# CONCLUDE
116
145
# If the apply was successful, post a comment with the applied output
117
146
- name : Post Plan and Apply to GitHub PR
118
147
if : steps.apply.outcome == 'success'
119
148
env :
120
149
URL : ${{ inputs.github_event_issue_comments_url }}
121
- LABEL : ${{ inputs.github_event_issue_url }}
122
150
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
123
151
run : |
124
- (printf "Mode1 Apply\n\n\`\`\`" && echo -n '${{ steps.apply.outputs.stdout }}' && printf "\`\`\`\n\n") > comment.txt
152
+ cd ${{ inputs.stack }}
153
+ (printf "Terraform Apply\n\n\`\`\`" && echo -n '${{ steps.apply.outputs.stdout }}' && printf "\`\`\`\n\n") > comment.txt
125
154
jq -R -s '.' < comment.txt > comment2.txt
126
155
truncate -s -1 comment2.txt
127
156
(echo -n '{ "body": ' && cat comment2.txt && echo -n ' }') > comment3.txt
@@ -133,7 +162,7 @@ jobs:
133
162
-d @comment3.txt
134
163
curl \
135
164
-X POST \
136
- $LABEL /labels \
165
+ https://api.github.com/repos/${{ github.repository }}/issues/${{ inputs.github_event_number }} /labels \
137
166
-H "Content-Type: application/json" \
138
167
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
139
168
-d '["applied"]'
@@ -145,6 +174,7 @@ jobs:
145
174
URL : ${{ inputs.github_event_repository_url }}/pulls/${{ inputs.github_event_number }}/merge
146
175
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
147
176
run : |
177
+ cd ${{ inputs.stack }}
148
178
curl \
149
179
-X PUT \
150
180
$URL \
@@ -155,7 +185,8 @@ jobs:
155
185
# remove the organization plan from S3 whether successful or not
156
186
- name : Delete Plan from S3
157
187
run : |
158
- aws s3 rm s3://${{ inputs.s3bucketName }}/plans/tfplan
188
+ cd ${{ inputs.stack }}
189
+ aws s3 rm --recursive s3://${{ inputs.s3bucketName }}/plans/${{ github.repository }}/${{ inputs.stack }}/${{ inputs.github_event_number }}
159
190
160
191
# If the apply failed, post the errors
161
192
- name : Post Organization Apply Failure
@@ -164,7 +195,8 @@ jobs:
164
195
URL : ${{ inputs.github_event_issue_comments_url }}
165
196
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
166
197
run : |
167
- (printf "Apply failed for Mode1:\n\nMode1\n\n\`\`\`" && echo -n '${{ steps.apply.outputs.stderr }}' && printf "\`\`\`\n\n") > comment.txt
198
+ cd ${{ inputs.stack }}
199
+ (printf "Apply failed for:\n\n\`\`\`" && echo -n '${{ steps.apply.outputs.stderr }}' && printf "\`\`\`\n\n") > comment.txt
168
200
jq -R -s '.' < comment.txt > comment2.txt
169
201
truncate -s -1 comment2.txt
170
202
(echo -n '{ "body": ' && cat comment2.txt && echo -n ' }') > comment3.txt
0 commit comments