Search code examples
dockercontainersterraform

Terraform destroy not work on docker container


I have a terrafom file with name main.tf that resource is only docker_container

main.tf file is:

provider "docker" {
}

#data "docker_registry_image" "baresip" {
#   name          =     "registry.gitlab.com/greenmns/test"
#}


#resource "docker_image" "baresip" {
# name           =     "registry.gitlab.com/greenmns/test"
# pull_triggers  =     ["${data.docker_registry_image.baresip.sha256_digest}"]
#}

resource "docker_container" "baresipcallee" {
  name           =     "baresipcallee"
  image          =     "registry.gitlab.com/greenmns/test"
  command        =     ["1"]
  rm             =     true
}

image registry.gitlab.com/greenmns/test is locally in my computer.

when i run terraform apply to generate a container i saw with docker ps my container is up but when i run terraform destroy container test is run and it didn't destory I think this is a buge of terraform


Solution

  • Based on:

    https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources/container
    

    When use switch rm = true in file terraform for example main.tf mean When create container docker Terraform won't check this container after creation.