terraform-provider-docker
terraform-provider-docker copied to clipboard
Support for Waiting on Container Health Status Before Continuing
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Description
I use docker-compose heavily for performing functional tests of my code. Due to the complexity of the functional tests, I believe terraform with this provider would be a better alternative. docker compose can express dependencies between two containers such that if container A depends on container B and container A is not healthy, then docker compose up fails and container B is not started. There's currently no easy way to do that with this provider. The workaround was to use a local exec provisioner but that has the downside of having to maintain and distribute a separate program
I propose that we add an optional to capability to docker_container, where container creation and start does not complete successfully unless the container is healthy.
I have already added this functionality into my fork and tested it locally. I am happy to provide a pull request if there's interest in adopting this feature.
New or Affected Resource(s)
- docker_container
Potential Terraform Configuration
resource "docker_container" "zookeeper" {
name = "zookeeper"
image = docker_image.zookeeper.latest
# by default, this is false. if true and the container has no healthcheck, then an error will be returned.
wait_until_healthy = true
# timeout is optional and defaults to 5 minutes. String must be parseable into time.Duration.
wait_until_healthy_timeout = "10s"
}
References
- I did find #247 but the issue was closed and I did not see comments from the maintainers indicating whether they were open to this functionality being added in or not. This issue is different only in as much as I have already written the code for this feature and am willing to submit a PR for it. However, if the maintainers do not believe this feature is appropriate, then I think this issue should be closed as a duplicate.
I would be happy about a PR @jaloren
I am still unsure about is the exackt naming/structure of the additional attributes. Should it be two attributes? Should they be placed inside the existing healthcheck block https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources/container#nestedblock--healthcheck?
Should the two attributes placed inside a new block (something like ready_conditions)
Please check my PR #467.
Implemented with https://github.com/kreuzwerker/terraform-provider-docker/releases/tag/v2.23.0