support to import some docker_container's attributes #234
Conversation
Verification preceduremain.tf provider "docker" {
}
resource "docker_image" "alpine" {
name = "alpine:3.10.3"
}
resource "docker_container" "foo" {
image = docker_image.alpine.latest
name = "foo"
rm = true
entrypoint = ["tail"]
start = true
command = ["-f", "/dev/null"]
read_only = true
shm_size = 64 # 64MB
privileged = true
user = "root"
working_dir = "/workspace"
domainname = "foo.com"
hostname = "foo"
dns = ["8.8.8.8"]
dns_search = ["example.com"]
env = [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"RACK_ENV=development"
]
userns_mode = "host"
tmpfs = {
"/run" : ""
"/tmp" : ""
}
log_driver = "json-file"
log_opts = {
max-size : "200k"
max-file : "10"
}
# these labels are set by docker-compose automatically
labels {
label = "com.docker.compose.config-hash"
value = "40541480c3ba148eefff245755e35d6186d2bca9c9033340866be9a27a603fe9" # you have to fix the value
}
labels {
label = "com.docker.compose.container-number"
value = "1"
}
labels {
label = "com.docker.compose.oneoff"
value = "False"
}
labels {
label = "com.docker.compose.project"
value = "terraform-provider-docker"
}
labels {
label = "com.docker.compose.service"
value = "foo"
}
labels {
label = "com.docker.compose.version"
value = "1.24.1"
}
network_mode = "bridge"
pid_mode = "host"
healthcheck {
test = ["CMD", "true"]
interval = "1m30s"
timeout = "10s"
retries = 3
}
sysctls = {
"net.core.somaxconn" : 1024
"net.ipv4.tcp_syncookies" : 0
}
ipc_mode = "shareable"
memory = 50
memory_swap = 100
capabilities {
add = ["ALL"]
drop = ["SYS_ADMIN"]
}
devices {
container_path = "/dev/null"
host_path = "/dev/null"
permissions = "rwm"
}
}
resource "docker_container" "zoo" {
image = docker_image.alpine.latest
name = "zoo"
command = ["tail", "-f", "/dev/null"]
cpu_shares = 2
cpu_set = "1"
start = true
env = [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
]
# links = ["/foo:/zoo/foo"]
} commands
results
|
Hey, @suzuki-shunsuke thank you for your effort on helping to finish the import of all resources :) Could you take a look at the failing tests? Furthermore, we'd consider adding the verify-step for the test as well as already done in the test for
|
@mavogel |
I found that https://github.com/suzuki-shunsuke/terraform-provider-docker/blob/dbf977499272d5bde494c823e8bff777e2fa0f3b/docker/resource_docker_container_funcs.go#L436 When I comment out |
We can avoid the above trouble by removing
https://www.terraform.io/docs/providers/docker/r/container.html#start I think the attribute |
Note that Docker image can have labels and environment variables so when we define labels or environment variables of |
CI fails but this failure occurs at the master branch too so it has nothing to do with this pull request. This is a test of
I don't know why this test fails. |
@mavogel Please review 🙏 |
``` panic: interface conversion: interface {} is int, not int64 ```
@suzuki-shunsuke thank you for the awesome work. It looks like we have a flaky test here and yes it has nothing to do with your PR. I'll investigate in a separate issue and we can deactivate this test temporarily (as we did also for another flaky test only on travis) I'll review in the next couple of days |
Would you review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM :) big thanks for this PR.
#219
Computed: true
to some attributesDiffSuppressFunc
to some attributesVerification codes
I share verification codes.
main.tf
Using Docker Compose and
docker run
commanddocker-compose.yml
terraform apply and terraform state rm
Instead of Docker Compose and
docker run
command, we can runterraform apply
andterraform state rm
too.terraform import