File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ url=" $1 "
3+ echo ${url}
4+ status_code=0
5+
6+ while [ $status_code -ne 200 ]; do
7+ status_code=$( curl -o /dev/null -s -w " %{http_code}\n" " $url " )
8+ echo " Waiting for server to respond with 200 OK. Current status: $status_code "
9+ sleep 5 # wait for 5 seconds before trying again
10+ done
11+
12+ echo " Received 200 OK from server."
Original file line number Diff line number Diff line change @@ -4,6 +4,10 @@ terraform {
44 source = " hashicorp/aws"
55 version = " ~> 4.0"
66 }
7+ null = {
8+ source = " hashicorp/null"
9+ version = " 3.2.2"
10+ }
711 }
812}
913
@@ -201,23 +205,27 @@ resource "aws_instance" "terraform_instance_master" {
201205
202206 sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin git -y
203207 sudo service docker start
204- wget https://raw.githubusercontent.com/maxiplux/api-python-project-devops-fast-api/dev-auth/docker-compose.yml
205- sudo docker compose up -d
206-
207-
208-
209-
210-
208+ cd /tmp && wget https://raw.githubusercontent.com/maxiplux/api-python-project-devops-fast-api/dev-auth/docker-compose.yml
209+ cd /tmp && sudo docker compose up -d
210+ echo "echo found" > /tmp/STATUS
211+ EOF
212+ }
211213
212214
215+ resource "null_resource" "user_data_status_check" {
213216
217+ provisioner "local-exec" {
218+ command = " bash check_status.sh \" http://${ aws_instance . terraform_instance_master . public_dns } :8080/docs\" "
219+ }
220+ triggers = {
221+ # remove this once you test it out as it should run only once
222+ always_run = " ${ timestamp ()} "
214223
224+ }
225+ depends_on = [aws_instance . terraform_instance_master ]
215226
216- EOF
217227}
218228
219-
220-
221229output "server_private_ip" {
222230 value = [aws_instance . terraform_instance_master . private_ip ]
223231}
You can’t perform that action at this time.
0 commit comments