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

feat: add new data source for docker_containers

Open KetchupBomb opened this issue 1 year ago • 0 comments

Addresses https://github.com/kreuzwerker/terraform-provider-docker/issues/642 by adding a new data source -- docker_containers -- for listing containers.

Right now, the data source has no schema beyond what is computed. The primary attribute, containers, is currently a list of strings. This is a naive implementation that can be improved, but is still quite compatible with Terraform through jsondecode():

> jsondecode(data.docker_containers.this.containers[0]).Id
"037d3b70a777ad7f66ae60534545fed5d69c784cdf685810370ed4f2cfed9020"

The Docker Engine API endpoint exposes more parameters that can be incorporated into this data source, but I wanted to put this up for initial consideration and guidance for me as a Golang noob, and first time working with Terraform Provider development.

  • The Docker Engine API returns values without ordering, so as of right now, repeated terraform plan or terraform apply commands will likely report changes to the underlying data source.
  • I am unsure of how to write adequate testing for such a simple case. Even then, I noticed that purposefully writing incorrect test cases would not cause make test or go test to fail. Advice on making sure I am writing tests correctly would be appreciated.

KetchupBomb avatar Aug 24 '24 23:08 KetchupBomb