1

i'm beginner in Terraform.

I tried to install docker image nginx on my local server but i have an issue when i launch the command terraform plan

Error: Unsupported attribute │ │ on dockernginx.tf line 20, in resource "docker_container" "nginx": │ 20: image = docker_image.nginx.latest │ │ This object has no argument, nested block, or exported attribute named "latest".

there is my code:


terraform {
  required_providers {
    docker = {
      source  = "kreuzwerker/docker"
      version = "3.0.2"
    }
  }
}

provider "docker" {
    host = "tcp://${var.ssh_host}:2375"
}

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

resource "docker_container" "nginx" {
  image = docker_image.nginx.latest
  name  = "enginecks"
  ports {
    internal = 80
    external = 80
  }
}

if someone can help me please ?!

Best regards

I tried to install docker image nginx on my local server but i have an issue when i launch the command terraform plan

  • 3
    Use `docker_image.nginx.image_id` (see https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources/container) – Paolo Mar 22 '23 at 13:21

1 Answers1

2

In the resource "docker_container" "nginx", change the image from

image = docker_image.nginx.latest

to

image = docker_image.nginx.image_id

Because the "docker_image" don`t output the attribute "latest", just "image_id".

See in the documentation

Dourado
  • 110
  • 8