terraform и docker
здравствуй читатель
пытаюсь освоить связку terraform и docker пишу следующую конструкцию, которая по моей задаче должна бы запустить три хеловорлда в докере
provider "docker" {
host = "ssh://user@docker:22"
}
# Create a container
resource "docker_container" "foo" {
count = 3
depends_on = [docker_image.hello-world]
image = docker_image.hello-world.latest
name = "foo${count.index}"
}
resource "docker_image" "hello-world" {
name = "hello-world"
}
terraform plan проходит без предупреждений
$ terraform apply
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# docker_container.foo[0] will be created
+ resource "docker_container" "foo" {
+ attach = false
+ bridge = (known after apply)
+ command = (known after apply)
+ container_logs = (known after apply)
+ entrypoint = (known after apply)
+ env = (known after apply)
+ exit_code = (known after apply)
+ gateway = (known after apply)
+ hostname = (known after apply)
+ id = (known after apply)
+ image = (known after apply)
+ ip_address = (known after apply)
+ ip_prefix_length = (known after apply)
+ ipc_mode = (known after apply)
+ log_driver = (known after apply)
+ log_opts = (known after apply)
+ logs = false
+ must_run = true
+ name = "foo0"
+ network_data = (known after apply)
+ read_only = false
+ restart = "no"
+ rm = false
+ shm_size = (known after apply)
+ start = true
+ user = (known after apply)
+ labels {
+ label = (known after apply)
+ value = (known after apply)
}
}
# docker_container.foo[1] will be created
+ resource "docker_container" "foo" {
+ attach = false
+ bridge = (known after apply)
+ command = (known after apply)
+ container_logs = (known after apply)
+ entrypoint = (known after apply)
+ env = (known after apply)
+ exit_code = (known after apply)
+ gateway = (known after apply)
+ hostname = (known after apply)
+ id = (known after apply)
+ image = (known after apply)
+ ip_address = (known after apply)
+ ip_prefix_length = (known after apply)
+ ipc_mode = (known after apply)
+ log_driver = (known after apply)
+ log_opts = (known after apply)
+ logs = false
+ must_run = true
+ name = "foo1"
+ network_data = (known after apply)
+ read_only = false
+ restart = "no"
+ rm = false
+ shm_size = (known after apply)
+ start = true
+ user = (known after apply)
+ labels {
+ label = (known after apply)
+ value = (known after apply)
}
}
# docker_container.foo[2] will be created
+ resource "docker_container" "foo" {
+ attach = false
+ bridge = (known after apply)
+ command = (known after apply)
+ container_logs = (known after apply)
+ entrypoint = (known after apply)
+ env = (known after apply)
+ exit_code = (known after apply)
+ gateway = (known after apply)
+ hostname = (known after apply)
+ id = (known after apply)
+ image = (known after apply)
+ ip_address = (known after apply)
+ ip_prefix_length = (known after apply)
+ ipc_mode = (known after apply)
+ log_driver = (known after apply)
+ log_opts = (known after apply)
+ logs = false
+ must_run = true
+ name = "foo2"
+ network_data = (known after apply)
+ read_only = false
+ restart = "no"
+ rm = false
+ shm_size = (known after apply)
+ start = true
+ user = (known after apply)
+ labels {
+ label = (known after apply)
+ value = (known after apply)
}
}
# docker_image.hello-world will be created
+ resource "docker_image" "hello-world" {
+ id = (known after apply)
+ latest = (known after apply)
+ name = "hello-world"
}
Plan: 4 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
docker_image.hello-world: Creating...
docker_image.hello-world: Creation complete after 0s [id=sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6bhello-world]
docker_container.foo[0]: Creating...
docker_container.foo[1]: Creating...
docker_container.foo[2]: Creating...
docker_container.foo[1]: Still creating... [10s elapsed]
docker_container.foo[2]: Still creating... [10s elapsed]
Error: Container afd354e763dfb796c74fa7d4e253ecb961b7301d15d5343e7cbf9f0b094f309d exited after creation, error was:
on main.tf line 6, in resource "docker_container" "foo":
6: resource "docker_container" "foo" {
Error: Container 8d7638874ea4c8705cbc760f8e1f36118018fa90a50bda0df0c883cc6c0c6f55 exited after creation, error was:
on main.tf line 6, in resource "docker_container" "foo":
6: resource "docker_container" "foo" {
Error: Container 260404f0618ebbd4e481f0a5fe41414e2a0e8ec03aa1e2aeba7e8de4ab91e0bc exited after creation, error was:
on main.tf line 6, in resource "docker_container" "foo":
6: resource "docker_container" "foo" {
$ docker -v Docker version 19.03.11, build 42e35e61f3
$ terraform -v Terraform v0.12.26
- provider.docker v2.7.1
запускаю пальчиками или через ansible все без проблем
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fa5fb066ee85 hello-world "/hello" 26 minutes ago Exited (0) 26 minutes ago quizzical_merkle
12b62aefd47b hello-world "/hello" 26 minutes ago Exited (0) 26 minutes ago quizzical_robinson
f92c9a5ed928 hello-world "/hello" 26 minutes ago Exited (0) 26 minutes ago relaxed_euler
убираю count и запускаю один экземпляр hello-world прекрасно работает из terraform. Где и что я упустил из виду?
спасибо