Created
September 2, 2022 09:55
-
-
Save godhand4826/cc139eaeb141e7c0ea0727bf218b90d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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