kreuzwerker / terraform-provider-docker

Terraform Docker provider
Mozilla Public License 2.0
570 stars 187 forks source link

Support `extra_hosts`, `secrets` attribute for `docker_container` resource #633

Open neostage opened 5 days ago

neostage commented 5 days ago

Community Note

Description

I'm trying to use docker_container resource and it has no extra_hosts, secrets attribute.

New or Affected Resource(s)

Potential Terraform Configuration

terraform {
# ...
}

resource "docker_container" "nginx" {
  image = "nginx:latest"
  name  = "nginx"

# ...

  extra_hosts {
    host = "host.docker.internal"
    ip   = "host-gateway"
  }

  extra_hosts {
    host = "foo"
    ip   = "bar"
  }

# ...
}
terraform {
# ...
}

resource "docker_secret" "postgres_password" {
  name = "postgres_password"
  data = file(local.password_file)
}

resource "docker_image" "postgres" {
  name = "postgres:latest"
}

resource "docker_container" "postgres" {
  name  = "postgres"
  image = docker_image.postgres

# ...

  env = [
    "POSTGRES_PASSWORD=/run/secrets/postgres_password"
  ]

  secrets {
    id = docker_secret.postgres_password.id
  }

# ...
}