Skip to content

Commit 632bbd6

Browse files
committed
solution 2
1 parent 8e6f5d0 commit 632bbd6

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

.github/workflows/terraform.yml

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,26 +150,24 @@ jobs:
150150
run: |
151151
chmod +x ./ansible/deploy-api-to-jumpbox.sh
152152
153-
# Get clean DB_HOST - NEW IMPROVED VERSION
154-
DB_HOST=$(terraform -chdir=infra output -raw mysql_fqdn | grep -E '^[a-zA-Z0-9.-]+$' | head -n1)
155-
echo "DB_HOST='$DB_HOST'"
153+
# Install jq if not present
154+
sudo apt-get update && sudo apt-get install -y jq
156155
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
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')
161+
162+
echo "DB_HOST='$DB_HOST'"
163+
echo "JUMP_HOST='$JUMP_HOST'"
164+
echo "JUMP_USER='$JUMP_USER'"
163165
164166
DB_USER="${{ secrets.MYSQL_USER }}"
165167
DB_PASS="${{ secrets.MYSQL_ADMIN_PASSWORD }}"
166168
DB_NAME="moviesdb"
167169
168-
JUMP_HOST=$(terraform -chdir=infra output -raw control_node_public_ip | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}')
169-
JUMP_USER=$(terraform -chdir=infra output -raw ssh_user | head -n1 | tr -d '\r\n')
170-
171170
./ansible/deploy-api-to-jumpbox.sh "$DB_HOST" "$DB_USER" "$DB_PASS" "$DB_NAME" "$JUMP_HOST" "$JUMP_USER"
172-
173171
174172
- name: 🛢️ Run Script Deploy Database
175173
run: |

0 commit comments

Comments
 (0)