terraform-provider-docker icon indicating copy to clipboard operation
terraform-provider-docker copied to clipboard

Support for Waiting on Container Health Status Before Continuing

Open jaloren opened this issue 3 years ago • 2 comments
trafficstars

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.

jaloren avatar Jun 20 '22 13:06 jaloren

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)

Junkern avatar Aug 10 '22 13:08 Junkern

Please check my PR #467.

bhuisgen avatar Oct 02 '22 12:10 bhuisgen

Implemented with https://github.com/kreuzwerker/terraform-provider-docker/releases/tag/v2.23.0

Junkern avatar Nov 02 '22 11:11 Junkern