Skip to content

Commit 50c0d2c

Browse files
committed
solution 4
1 parent 96515fd commit 50c0d2c

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

.github/workflows/terraform.yml

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,20 +150,30 @@ jobs:
150150
run: |
151151
chmod +x ./ansible/deploy-api-to-jumpbox.sh
152152
153-
# Get clean DB_HOST - Most reliable method
154-
DB_HOST=$(terraform -chdir=infra output mysql_fqdn | sed -n 's/^.* = "\([^"]*\)"/\1/p' | tr -d '\r\n')
155-
echo "DB_HOST='$DB_HOST'"
153+
# Get clean DB_HOST - Ultimate reliable method
154+
DB_HOST=$(terraform -chdir=infra output -raw mysql_fqdn 2>&1 | grep -oE '[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}' | head -n1)
155+
echo "Extracted DB_HOST='$DB_HOST'"
156156
157-
# Strict validation
158-
if [[ ! "$DB_HOST" =~ ^[a-zA-Z0-9.-]+$ ]]; then
159-
echo "ERROR: Invalid DB_HOST format: '$DB_HOST'"
160-
echo "Expected format: hostname.domain.tld"
157+
# Fallback if raw output fails
158+
if [ -z "$DB_HOST" ]; then
159+
DB_HOST=$(terraform -chdir=infra output mysql_fqdn | grep -oE '[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}' | head -n1)
160+
echo "Fallback extracted DB_HOST='$DB_HOST'"
161+
fi
162+
163+
# Final validation
164+
if [[ ! "$DB_HOST" =~ ^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ ]]; then
165+
echo "ERROR: Could not extract valid DB_HOST"
166+
echo "Raw terraform output:"
167+
terraform -chdir=infra output mysql_fqdn
161168
exit 1
162169
fi
163170
164-
# Get jump host IP (alternative method)
165-
JUMP_HOST=$(terraform -chdir=infra output control_node_public_ip | sed -n 's/^.* = "\([^"]*\)"/\1/p' | tr -d '\r\n')
166-
JUMP_USER=$(terraform -chdir=infra output ssh_user | sed -n 's/^.* = "\([^"]*\)"/\1/p' | tr -d '\r\n')
171+
# Get jump host details
172+
JUMP_HOST=$(terraform -chdir=infra output -raw control_node_public_ip 2>/dev/null || \
173+
terraform -chdir=infra output control_node_public_ip | grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}' | head -n1)
174+
175+
JUMP_USER=$(terraform -chdir=infra output -raw ssh_user 2>/dev/null || \
176+
terraform -chdir=infra output ssh_user | awk '{print $3}' | tr -d '"')
167177
168178
DB_USER="${{ secrets.MYSQL_USER }}"
169179
DB_PASS="${{ secrets.MYSQL_ADMIN_PASSWORD }}"
@@ -175,7 +185,7 @@ jobs:
175185
echo "JUMP_USER: $JUMP_USER"
176186
177187
./ansible/deploy-api-to-jumpbox.sh "$DB_HOST" "$DB_USER" "$DB_PASS" "$DB_NAME" "$JUMP_HOST" "$JUMP_USER"
178-
188+
179189
- name: 🛢️ Run Script Deploy Database
180190
run: |
181191
chmod +x ./ansible/deploy-db-from-local.sh

0 commit comments

Comments
 (0)