terraform httpd_container
Frank Promise Edah
Posted on April 25, 2022
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"
}
`
💖 💪 🙅 🚩
Frank Promise Edah
Posted on April 25, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
webdev Understanding HTTP, Cookies, Email Protocols, and DNS: A Guide to Key Internet Technologies
November 30, 2024