Skip to content

Instantly share code, notes, and snippets.

@godhand4826
Created September 2, 2022 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save godhand4826/cc139eaeb141e7c0ea0727bf218b90d2 to your computer and use it in GitHub Desktop.
Save godhand4826/cc139eaeb141e7c0ea0727bf218b90d2 to your computer and use it in GitHub Desktop.
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "2.20.3"
}
}
}
variable "nginx_image_tag" {
description = "tag of the nginx image"
type = string
default = "1.23.1"
}
variable "nginx_container_name" {
description = "name of the nginx docker container"
type = string
default = "nginx"
}
provider "docker" {}
resource "docker_image" "nginx" {
name = "nginx:${var.nginx_image_tag}"
keep_locally = false
}
resource "docker_container" "nginx" {
image = docker_image.nginx.name
name = var.nginx_container_name
ports {
internal = 80
external = 8000
}
}
output "image_id" {
description = "ID of the Docker image"
value = docker_image.nginx.id
}
output "container_id" {
description = "ID of the Docker container"
value = docker_container.nginx.id
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment