Not able to execute influx setup command using terraform

I am using terraform to create an ec2 instance and install docker containers using a docker compose file. I am able to install influxdb docker container, for setting it up i am using the command - docker exec influxdb influx setup --org <organization_name> --bucket <bucket_name> --username <user_name> --password <password> --force

This command is running perfectly if i am running it manually on created ec2. But when i am trying to run command using remote-exec provisioner it’s giving following error - Error: failed to determine if instance has been configured: Get "http://localhost:8086/api/v2/setup": dial tcp connect: connection refused .

I have verified 8086 port is open. Any solution for this?

@Pratik_Das_Baghel the setup command is being sent to the server before it’s fully booted up and started listening for connections. You can prevent this by running influx ping in a loop until it prints OK / exits with code 0, then sending influx setup.

Alternatively, if you’re using the influxdb image hosted on DockerHub, you can use its built-in auto-setup logic. See this section of the docs.