DEV Community

Frank Promise Edah
Frank Promise Edah

Posted on • Updated on

terraform httpd_container

terraform {
  required_providers {
    docker = {
      source  = "kreuzwerker/docker"
      version = "~>2.12.0"
    }
  }
}

provider "docker" {}

resource "docker_image" "httpd_image" {
  name = "httpd:latest"
}

resource "random_string" "random" {
  count = 2
  length  = 4
  special = false
  upper   = false
}



resource "docker_container" "httpd_container" {
  count = 2
  name  = join("-", ["httpd", random_string.random[count.index].result])
  image = docker_image.httpd_image.latest
  ports {
    internal = 8080
    #external = 8080
  }
}



output "IPAddress" {
  value       = [for i in docker_container.httpd_container[*]: join(":", [i.ip_address], i.ports[*]["external"])]
  description = "The IP Address and port  of the container"
}


output "container_name" {
  value       = docker_container.httpd_container[*].name
  description = "The name of the container"
}


Enter fullscreen mode Exit fullscreen mode


`

Oldest comments (0)