Skip to content

Simplify your Docker image deployment process with this Terraform module! This module automates the building and pushing of Docker images to your desired container registry. Easily define your image source, repository details, and registry settings using Terraform's declarative syntax.

License

Notifications You must be signed in to change notification settings

Redevaerk/terraform-docker-image

Repository files navigation

Terraform Docker Build & Push Module

Simplify your Docker image deployment process with our Terraform module! This module automates the building and pushing of Docker images to your desired container registry. Easily define your image source, repository details, and registry settings using Terraform's declarative syntax.

Usage

module "docker_image" {
  source  = "Redevaerk/image/docker"
  version = "x.x.x"
  name    = var.name
}

Examples

  • Simple - This example will build and push Docker image with default settings.
  • Build Image With Context - This example will build and push Docker image with a context in different folder.
  • Azure Container Registry - This example will build and push Docker image to Azure Container Registry.
  • Multiple Tags - This example will build and push Docker image with multiple tags.

Requirements

Name Version
terraform >= 1.0
docker >=3.0.0

Providers

Name Version
docker >=3.0.0

Modules

No modules.

Resources

Name Type
docker_image.this resource
docker_registry_image.this resource

Inputs

Name Description Type Default Required
add_latest_tag Add latest tag to the Image. If false, it's necessary to add at least one tag on 'variable.tags'. bool true no
context Value to specify the build context. Currently, only a PATH context is supported. string null no
dockerfile A directory containing your Dockerfile string "Dockerfile" no
dynamic_build If true, will force the docker_image resource to be replaced. This can be used to rebuild an image when contents of source code folders change. bool true no
dynamic_build_attach_dockerfile If true, will force the docker_image resource to be replaced when dockerfile changes. bool true no
dynamic_build_attach_dockerignore If true, will force the docker_image resource to be replaced when docker ignore file changes. bool true no
dynamic_build_attach_source If true, will force the docker_image resource to be replaced when contents of source code folders change. bool true no
dynamic_build_extra A map of arbitrary strings that, when changed, will force the docker_image resource to be replaced map(string) null no
dynamic_build_source_dir A directory containing your source code. This variable will be used in dynamic build when var.dynamic_build_attach_source is true. string "src" no
force_remove If true, then the image is removed forcibly when the resource is destroyed. bool false no
keep_locally If true, then the Docker image won't be deleted on destroy operation. If this is false, it will delete the image from the docker local storage on destroy operation. bool false no
keep_remotely If true, then the Docker image won't be deleted on destroy operation. If this is false, it will delete the image from the docker registry on destroy operation. bool false no
labels A map of labels to add to the Image map(string) {} no
name A unique name for your Image string n/a yes
push If true, then the Image will be pushed to the registry bool true no
registry Registry Name to push the Image string "registry-1.docker.io" no
tags Optionally a tags to add to the Image list(string) [] no

Outputs

Name Description
images List of all created docker images
map_images Map per tag corresponding docker images

License

Apache 2 Licensed. See LICENSE for full details.

About

Simplify your Docker image deployment process with this Terraform module! This module automates the building and pushing of Docker images to your desired container registry. Easily define your image source, repository details, and registry settings using Terraform's declarative syntax.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published