terraform-provider-docker
terraform-provider-docker copied to clipboard
Unable to use Dockerfile variable path in module
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Terraform (and docker Provider) Version
~/projects/terraform main* ❯ terraform -v
Terraform v1.9.5
on darwin_arm64
Your version of Terraform is out of date! The latest version
is 1.9.7. You can update by downloading from https://www.terraform.io/downloads.html
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "~> 3.0.1"
}
}
}
Terraform Configuration Files
Website Module
resource "docker_image" "alpine" {
name = "alpine"
keep_locally = false
build {
dockerfile = var.dockerfile
context = var.dockerfile_context
}
}
Main Terraform
module "website" {
source = "../modules/website"
network_id = docker_network.network.id
prefix = var.prefix
external_port = var.external_port
dockerfile = "${path.cwd}/Dockerfile"
dockerfile_context = "${path.cwd}/../.."
mount_source = null
}
Debug Output
Expected Behaviour
I should be able to reference a Dockerfile from any given directory within my module through variables.
Actual Behaviour
For some reason Terraform (or Docker provider) is unable to find the Dockerfile through an absolute path even though I can use cat on the generated output and have it output the contents of the file.
I have attempted to do relative paths but I still run into the same issue.
Steps to Reproduce
- Create a module which has a
docker_imageresource and abuild.dockerfilevalue from a variable. - Use module in parent script, provide variables
- See error
Important Factoids
tree output
~/projects/next/home/terraform main* ❯ tree -L 3
.
├── development
│ ├── Dockerfile
│ ├── main.tf
│ └── variables.tf
├── modules
│ ├── database
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── variables.tf
│ └── website
│ ├── main.tf
│ ├── outputs.tf
│ └── variables.tf
└── production
├── Dockerfile
├── main.tf
├── terraform.tfstate
├── terraform.tfstate.backup
└── variables.tf
6 directories, 14 files