Skip to content

Commit d894a2f

Browse files
committed
Fixed Error: Terraform outputs contain command strings
1 parent bb4635f commit d894a2f

File tree

2 files changed

+26
-30
lines changed

2 files changed

+26
-30
lines changed

.github/workflows/terraform.yml

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -208,30 +208,26 @@ jobs:
208208
run: |
209209
cd infra
210210
211-
# Get outputs using separate commands with proper sanitization
212-
APP_NAME=$(terraform output app_service_name | sed 's/"//g' | tr -d '\n')
213-
RG_NAME=$(terraform output resource_group_name | sed 's/"//g' | tr -d '\n')
214-
API_URL=$(terraform output lb_api_url | sed 's/"//g' | tr -d '\n')
215-
216-
# Verify outputs don't contain command strings
217-
if [[ "$APP_NAME" == *"command"* || "$RG_NAME" == *"command"* || "$API_URL" == *"command"* ]]; then
218-
echo "::error::Terraform outputs contain command strings!"
219-
echo "APP_NAME: $APP_NAME"
220-
echo "RG_NAME: $RG_NAME"
221-
echo "API_URL: $API_URL"
222-
exit 1
223-
fi
211+
# Create a script to capture clean outputs
212+
cat << 'EOF' > get_outputs.sh
213+
#!/bin/bash
214+
{
215+
echo "app_service_name=$(terraform output -raw app_service_name | tr -d '\n')"
216+
echo "resource_group_name=$(terraform output -raw resource_group_name | tr -d '\n')"
217+
echo "lb_api_url=$(terraform output -raw lb_api_url | tr -d '\n')"
218+
} >> $GITHUB_OUTPUT
219+
EOF
224220
225-
# Set outputs
226-
echo "app_service_name=${APP_NAME}" >> $GITHUB_OUTPUT
227-
echo "resource_group_name=${RG_NAME}" >> $GITHUB_OUTPUT
228-
echo "lb_api_url=${API_URL}" >> $GITHUB_OUTPUT
221+
# Make script executable and run it
222+
chmod +x get_outputs.sh
223+
./get_outputs.sh
229224
230-
echo "✅ Verified clean outputs:"
231-
echo "APP: ${APP_NAME}"
232-
echo "RG: ${RG_NAME}"
233-
echo "API: ${API_URL}"
234-
shell: bash
225+
# Verify outputs
226+
echo "✅ Clean outputs captured:"
227+
echo "APP: ${{ steps.tf.outputs.app_service_name }}"
228+
echo "RG: ${{ steps.tf.outputs.resource_group_name }}"
229+
echo "API: ${{ steps.tf.outputs.lb_api_url }}"
230+
235231
236232
- name: Deploy Frontend
237233
run: |

ansible/deploy-frontend.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
node_version: "16-lts"
77

88
tasks:
9-
- name: Validate variables don't contain command strings
10-
fail:
11-
msg: |
9+
- name: Validate variables
10+
assert:
11+
that:
12+
- "'[' not in app_service_name"
13+
- "'[' not in resource_group_name"
14+
- "'[' not in lb_api_url"
15+
fail_msg: |
1216
Invalid variables detected!
1317
- App Service: {{ app_service_name }}
1418
- Resource Group: {{ resource_group_name }}
1519
- API URL: {{ lb_api_url }}
16-
Check GitHub Actions workflow for proper output handling.
17-
when: >
18-
'[command]' in app_service_name or
19-
'[command]' in resource_group_name or
20-
'[command]' in lb_api_url
20+
Check GitHub Actions workflow.
2121
2222
- name: Show deployment configuration
2323
debug:

0 commit comments

Comments
 (0)