Skip to content

Commit 8341481

Browse files
authored
fixes the conflicts and description spell mistake (#216)
1 parent aff66b6 commit 8341481

File tree

1 file changed

+54
-60
lines changed

1 file changed

+54
-60
lines changed

.github/workflows/terraform_workflow_target.yml

Lines changed: 54 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -32,59 +32,58 @@ on:
3232
approvers:
3333
required: false
3434
type: string
35-
description: 'Approvals list to approve apply or destroy.'
35+
description: 'Approvals list to approve apply or destroy'
3636
terraform_version:
3737
type: string
3838
default: 1.3.6
39-
description: 'Terraform version to use.'
39+
description: 'Required terraform version '
4040
timeout:
4141
required: false
4242
type: number
4343
default: 10
44-
description: 'Timeout for approval step.'
44+
description: 'Timeout for approval step'
4545
minimum-approvals:
4646
required: false
4747
type: string
4848
default: 1
49-
description: 'Minimum approvals required to accept the plan.'
49+
description: 'Minimum approvals required to accept the plan'
5050
token_format:
5151
required: false
5252
type: string
5353
default: access_token
54-
description: 'Token format for GCP authentication.'
54+
description: 'Output format for the generated authentication token. For OAuth 2.0 access tokens, specify "access_token". For OIDC tokens, specify "id_token". To skip token generation, leave this value empty'
5555
access_token_lifetime:
5656
required: false
5757
type: string
5858
default: 300s
59-
description: 'Lifetime of access token for GCP.'
59+
description: 'Desired lifetime duration of the access token, in seconds'
6060
project_id:
6161
required: false
6262
type: string
63-
description: 'GCP project ID.'
63+
description: 'ID of the default project to use for future API calls and invocations.'
6464
create_credentials_file:
6565
required: false
6666
type: string
6767
default: true
68-
description: 'Whether to create credentials file for GCP.'
68+
description: 'If true, the action will securely generate a credentials file which can be used for authentication via gcloud and Google Cloud SDKs.'
6969
git_ssh_key_setup:
7070
required: false
7171
type: string
7272
default: false
73-
description: 'Whether to setup SSH keys for Git access.'
73+
description: 'If true, sets up SSH keys for Git access to clone private repositories.'
7474
target_environment:
75+
description: "Name of the deployment environment (e.g., dev, staging, prod). Leave empty if no environment-specific context is needed."
7576
required: false
7677
type: string
7778
default: ""
78-
description: "Deployment environment (e.g., dev, prod)."
7979
target:
8080
required: false
8181
type: string
82-
description: 'Target specific Terraform resource (e.g., module.vpc_ec2). If not set, value will be read from target.txt.'
82+
description: 'Target specific Terraform resource (e.g., module.vpc_ec2). If not set, fallback to target_file or target.txt.'
8383
target_file:
8484
required: false
8585
type: string
8686
description: 'Path to file with target resource (e.g., vars/target.txt)'
87-
8887
secrets:
8988
AZURE_CREDENTIALS:
9089
required: false
@@ -133,7 +132,7 @@ jobs:
133132
uses: actions/checkout@v4
134133

135134
- uses: webfactory/[email protected]
136-
if: ${{ inputs.git_ssh_key_setup == 'true' }}
135+
if: ${{ inputs.git_ssh_key_setup == true }}
137136
with:
138137
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
139138

@@ -163,9 +162,9 @@ jobs:
163162
with:
164163
creds: ${{ secrets.AZURE_CREDENTIALS }}
165164

166-
- name: Authenticate to Google Cloud
165+
- name: 'Authenticate to Google Cloud'
167166
if: ${{ inputs.provider == 'gcp' }}
168-
uses: google-github-actions/auth@v2
167+
uses: 'google-github-actions/auth@v2'
169168
with:
170169
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
171170
create_credentials_file: ${{ inputs.create_credentials_file }}
@@ -186,20 +185,20 @@ jobs:
186185
with:
187186
terraform_version: ${{ inputs.terraform_version }}
188187

189-
- name: Terraform Format
188+
- name: 'Terraform Format'
190189
if: ${{ inputs.destroy != true }}
191190
id: fmt
192-
uses: dflook/terraform-fmt-check@v2
191+
uses: 'dflook/terraform-fmt-check@v2'
193192
with:
194-
actions_subcommand: fmt
193+
actions_subcommand: 'fmt'
195194
path: ${{ inputs.working_directory }}
196195

197-
- name: Terraform Init
196+
- name: terraform init
198197
run: |
199198
cd ${{ inputs.working_directory }}
200199
terraform init
201200
202-
- name: Terraform Validate
201+
- name: 'Terraform validate'
203202
if: ${{ inputs.destroy != true }}
204203
id: validate
205204
uses: dflook/terraform-validate@v2
@@ -209,22 +208,24 @@ jobs:
209208
- name: Terraform Plan
210209
id: tf-plan
211210
run: |
211+
export exitcode=0
212212
cd ${{ inputs.working_directory }}
213213
214214
TARGET=""
215+
TARGET_FILE_PATH="${{ github.workspace }}/${{ inputs.target_file }}"
216+
215217
if [ -n "${{ inputs.target }}" ]; then
216-
echo "Using direct input target"
217218
TARGET="${{ inputs.target }}"
218-
elif [ -n "${{ inputs.target_file }}" ] && [ -f "${{ inputs.target_file }}" ]; then
219-
echo "Using absolute/relative path as-is: ${{ inputs.target_file }}"
220-
TARGET=$(cat "${{ inputs.target_file }}" | tr -d '\n')
219+
elif [ -n "${{ inputs.target_file }}" ] && [ -f "$TARGET_FILE_PATH" ]; then
220+
TARGET=$(cat "$TARGET_FILE_PATH" | tr -d '\n' | xargs)
221221
elif [ -f "target.txt" ]; then
222-
echo "Using fallback target.txt"
223-
TARGET=$(cat target.txt | tr -d '\n')
222+
TARGET=$(cat target.txt | tr -d '\n' | xargs)
224223
fi
225224
225+
echo "Final Target Value: '$TARGET'"
226+
226227
PLAN_CMD="terraform plan -out=tfplan"
227-
if [ "${{ inputs.destroy }}" = "true" ]; then
228+
if [ "${{ inputs.destroy }}" = true ]; then
228229
PLAN_CMD="terraform plan -destroy -out=tfplan"
229230
fi
230231
@@ -233,16 +234,13 @@ jobs:
233234
fi
234235
235236
if [ -n "$TARGET" ]; then
236-
echo "Target detected: $TARGET"
237237
PLAN_CMD="$PLAN_CMD --target=$TARGET"
238-
else
239-
echo "No target specified. Running full plan."
240238
fi
241239
242240
echo "Running: $PLAN_CMD"
243241
eval "$PLAN_CMD"
244242
245-
- name: Upload Terraform Plan
243+
- name: Publish Terraform Plan
246244
uses: actions/upload-artifact@v4
247245
with:
248246
name: tfplan
@@ -264,7 +262,7 @@ jobs:
264262
echo "</details>" >> $GITHUB_OUTPUT
265263
echo "${delimiter}" >> $GITHUB_OUTPUT
266264
267-
- name: Manual Approval
265+
- name: "Accept plan or deny"
268266
uses: trstringer/manual-approval@v1
269267
timeout-minutes: ${{ inputs.timeout }}
270268
with:
@@ -273,41 +271,21 @@ jobs:
273271
minimum-approvals: ${{ inputs.minimum-approvals }}
274272
issue-title: "Terraform Plan for Infrastructure Update"
275273

276-
- name: Terraform Apply
274+
- name: terraform apply
277275
if: ${{ inputs.destroy != true }}
278276
run: |
279277
cd ${{ inputs.working_directory }}
280-
281-
TARGET=""
282-
if [ -n "${{ inputs.target }}" ]; then
283-
echo "Using direct input target"
284-
TARGET="${{ inputs.target }}"
285-
elif [ -n "${{ inputs.target_file }}" ] && [ -f "${{ inputs.target_file }}" ]; then
286-
echo "Using absolute/relative path as-is: ${{ inputs.target_file }}"
287-
TARGET=$(cat "${{ inputs.target_file }}" | tr -d '\n')
288-
elif [ -f "target.txt" ]; then
289-
echo "Using fallback target.txt"
290-
TARGET=$(cat target.txt | tr -d '\n')
291-
fi
292-
293-
if [ -n "$TARGET" ]; then
294-
echo "Target specified: $TARGET"
295-
else
296-
echo "No target specified. Applying full plan."
297-
fi
298-
299-
if [ -n "${{ inputs.var_file }}" ]; then
300-
terraform apply -var-file="${{ inputs.var_file }}" -auto-approve tfplan
301-
else
302-
terraform apply -auto-approve tfplan
303-
fi
278+
terraform apply -auto-approve tfplan
304279
305280
- name: Find Errored Terraform State
306281
if: ${{ always() }}
307282
run: |
308283
cd ${{ inputs.working_directory }}
309284
if [ -f "errored.tfstate" ]; then
310-
echo "Errored state found."
285+
ls -la errored.tfstate
286+
echo "Uploading errored.tfstate as artifact..."
287+
else
288+
echo "Errored Terraform state file not found."
311289
fi
312290
313291
- name: Upload Errored Terraform State Artifact
@@ -317,12 +295,28 @@ jobs:
317295
name: errored_tfstate
318296
path: ${{ inputs.working_directory }}/errored.tfstate
319297

320-
- name: Terraform Destroy
298+
- name: Terraform destroy
321299
if: ${{ inputs.destroy == true }}
322300
id: destroy
323301
run: |
324302
cd ${{ inputs.working_directory }}
325-
if [ -n "${{ inputs.var_file }}" ]; then
303+
304+
TARGET=""
305+
TARGET_FILE_PATH="${{ github.workspace }}/${{ inputs.target_file }}"
306+
307+
if [ -n "${{ inputs.target }}" ]; then
308+
TARGET="${{ inputs.target }}"
309+
elif [ -n "${{ inputs.target_file }}" ] && [ -f "$TARGET_FILE_PATH" ]; then
310+
TARGET=$(cat "$TARGET_FILE_PATH" | tr -d '\n' | xargs)
311+
elif [ -f "target.txt" ]; then
312+
TARGET=$(cat target.txt | tr -d '\n' | xargs)
313+
fi
314+
315+
echo "Final Target Value: '$TARGET'"
316+
317+
if [ -n "$TARGET" ]; then
318+
terraform destroy --target="$TARGET" -auto-approve
319+
elif [ -n "${{ inputs.var_file }}" ]; then
326320
terraform destroy -var-file="${{ inputs.var_file }}" -auto-approve
327321
else
328322
terraform destroy -auto-approve

0 commit comments

Comments
 (0)