Skip to content

Commit 96515fd

Browse files
committed
solution 3
1 parent 632bbd6 commit 96515fd

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

.github/workflows/terraform.yml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,23 +150,30 @@ jobs:
150150
run: |
151151
chmod +x ./ansible/deploy-api-to-jumpbox.sh
152152
153-
# Install jq if not present
154-
sudo apt-get update && sudo apt-get install -y jq
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'"
155156
156-
# Get outputs as JSON and parse with jq
157-
terraform -chdir=infra output -json > tf_output.json
158-
DB_HOST=$(jq -r '.mysql_fqdn.value' tf_output.json | tr -d '\r\n')
159-
JUMP_HOST=$(jq -r '.control_node_public_ip.value' tf_output.json | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}')
160-
JUMP_USER=$(jq -r '.ssh_user.value' tf_output.json | head -n1 | tr -d '\r\n')
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"
161+
exit 1
162+
fi
161163
162-
echo "DB_HOST='$DB_HOST'"
163-
echo "JUMP_HOST='$JUMP_HOST'"
164-
echo "JUMP_USER='$JUMP_USER'"
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')
165167
166168
DB_USER="${{ secrets.MYSQL_USER }}"
167169
DB_PASS="${{ secrets.MYSQL_ADMIN_PASSWORD }}"
168170
DB_NAME="moviesdb"
169171
172+
echo "=== Final Variables ==="
173+
echo "DB_HOST: $DB_HOST"
174+
echo "JUMP_HOST: $JUMP_HOST"
175+
echo "JUMP_USER: $JUMP_USER"
176+
170177
./ansible/deploy-api-to-jumpbox.sh "$DB_HOST" "$DB_USER" "$DB_PASS" "$DB_NAME" "$JUMP_HOST" "$JUMP_USER"
171178
172179
- name: 🛢️ Run Script Deploy Database

0 commit comments

Comments
 (0)