(MODE-11365) fixing local-exec command.

This commit is contained in:
siozosdr 2019-06-24 20:54:07 +02:00
parent eeb781583a
commit b1e6e01a68

View file

@ -47,36 +47,7 @@ resource "aws_autoscaling_group" "autoscalinggroup" {
provisioner "local-exec" { provisioner "local-exec" {
# Wait until the number of "ok" instance status checks is equal to 1 # Wait until the number of "ok" instance status checks is equal to 1
command = "sleep 15; \ command = "sleep 15;expected=2; current=0; retries=0; instances=$(aws autoscaling describe-auto-scaling-groups --auto-scaling-group-name "${aws_autoscaling_group.autoscalinggroup.name}" --query 'AutoScalingGroups[*].Instances[*].InstanceId' --output text); while [ "$current" -lt "$expected" ]; do for i in $(echo $instances); do check=$(aws elbv2 describe-target-health --target-group-arn "${aws_alb_target_group.target_group_this.arn}" --query "TargetHealthDescriptions[?Target.Id == '$i'].TargetHealth.State" --output text); echo "$check"; if [ "$check" = "$(echo 'healthy')" ]; then current="$(echo $((++current)))"; else current="$(echo $((--current)))"; fi; done; if [ "$current" -eq "$expected" ]; then break; else current="0"; retries="$((++retries))" fi; if [ "$retries" = "3" ]; then break;fi done"
expected=2; \
current=0; \
retries=0; \
instances=$(aws autoscaling describe-auto-scaling-groups \
--auto-scaling-group-name "${aws_autoscaling_group.autoscalinggroup.name}" \
--query 'AutoScalingGroups[*].Instances[*].InstanceId' --output text); \
while [ "$current" -lt "$expected" ]; do \
for i in $(echo $instances); do \
check=$(aws elbv2 describe-target-health \
--target-group-arn "${aws_alb_target_group.target_group_this.arn}" \
--query "TargetHealthDescriptions[?Target.Id == '$i'].TargetHealth.State" --output text); \
echo "$check"; \
if [[ "$check" -eq "healthy" ]]; then \
current="$(echo $((++current)))"; \
else \
current="$(echo $((--current)))"; \
fi \
done; \
if [[ "$($current)" -eq "$expected" ]]; then \
break; \
else \
current="0";
retries="$((++retries))"
fi; \
if [[ "$retries" -eq "3" ]]; then \
break;\
fi
done
"
} }
} }