Skip to content

Commit eedaa52

Browse files
kanare-devclaude
andcommitted
fix: Improve Terraform output parsing in deployment workflow
Fix "Invalid format" error caused by Terraform error messages containing box drawing characters being written to GITHUB_OUTPUT. Changes: - Filter out box drawing characters (╷, │, ╵) from Terraform output - Add validation for AWS User Pool ID format (regex check) - Add validation for Client ID format - Improve error handling with explicit Terraform init check - Clearer fallback logic to GitHub Secrets - Better logging for debugging This prevents malformed output from breaking GitHub Actions file commands while maintaining robust fallback to Secrets when Terraform outputs are unavailable or invalid. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 6b44863 commit eedaa52

1 file changed

Lines changed: 24 additions & 10 deletions

File tree

.github/workflows/deploy-static-site.yml

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,25 +85,39 @@ jobs:
8585
cd terraform/environments/${{ steps.set-env.outputs.environment }}
8686
8787
# Terraform init (backend設定を読み込むため)
88-
terraform init > /dev/null 2>&1 || true
89-
90-
# Terraform outputsから値を取得
91-
USER_POOL_ID=$(terraform output -raw cognito_user_pool_id 2>/dev/null || echo "")
92-
USER_POOL_CLIENT_ID=$(terraform output -raw cognito_user_pool_client_id 2>/dev/null || echo "")
88+
echo "Initializing Terraform..."
89+
if terraform init > /dev/null 2>&1; then
90+
echo "✅ Terraform initialized successfully"
91+
92+
# Terraform outputsから値を取得(エラー出力を完全に無視)
93+
USER_POOL_ID=$(terraform output -raw cognito_user_pool_id 2>&1 | grep -v "╷" | grep -v "│" | grep -v "╵" | head -n1 || echo "")
94+
USER_POOL_CLIENT_ID=$(terraform output -raw cognito_user_pool_client_id 2>&1 | grep -v "╷" | grep -v "│" | grep -v "╵" | head -n1 || echo "")
95+
96+
# 出力値の検証(AWS User Pool IDの形式チェック)
97+
if [[ "$USER_POOL_ID" =~ ^[a-z]+-[a-z]+-[0-9]+_[a-zA-Z0-9]+$ ]] && [[ "$USER_POOL_CLIENT_ID" =~ ^[a-zA-Z0-9]+$ ]]; then
98+
echo "✅ Terraform outputsからCognito設定を取得しました"
99+
echo "user_pool_id=$USER_POOL_ID" >> $GITHUB_OUTPUT
100+
echo "user_pool_client_id=$USER_POOL_CLIENT_ID" >> $GITHUB_OUTPUT
101+
else
102+
echo "⚠️ Terraform outputs validation failed. Using Secrets..."
103+
USER_POOL_ID=""
104+
USER_POOL_CLIENT_ID=""
105+
fi
106+
else
107+
echo "⚠️ Terraform init failed. Using Secrets..."
108+
USER_POOL_ID=""
109+
USER_POOL_CLIENT_ID=""
110+
fi
93111
112+
# Secretsから取得(フォールバック)
94113
if [ -z "$USER_POOL_ID" ] || [ -z "$USER_POOL_CLIENT_ID" ]; then
95-
echo "⚠️ Terraform outputsからCognito設定を取得できませんでした。Secretsから取得します..."
96114
if [ "${{ steps.set-env.outputs.environment }}" == "prod" ]; then
97115
echo "user_pool_id=${{ secrets.VITE_USER_POOL_ID }}" >> $GITHUB_OUTPUT
98116
echo "user_pool_client_id=${{ secrets.VITE_USER_POOL_CLIENT_ID }}" >> $GITHUB_OUTPUT
99117
else
100118
echo "user_pool_id=${{ secrets.VITE_USER_POOL_ID_DEV }}" >> $GITHUB_OUTPUT
101119
echo "user_pool_client_id=${{ secrets.VITE_USER_POOL_CLIENT_ID_DEV }}" >> $GITHUB_OUTPUT
102120
fi
103-
else
104-
echo "✅ Terraform outputsからCognito設定を取得しました"
105-
echo "user_pool_id=$USER_POOL_ID" >> $GITHUB_OUTPUT
106-
echo "user_pool_client_id=$USER_POOL_CLIENT_ID" >> $GITHUB_OUTPUT
107121
fi
108122
109123
- name: Install dependencies

0 commit comments

Comments
 (0)