Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use Dockerfile variable path in module #650

Open
dextermb opened this issue Oct 6, 2024 · 0 comments
Open

Unable to use Dockerfile variable path in module #650

dextermb opened this issue Oct 6, 2024 · 0 comments

Comments

@dextermb
Copy link

dextermb commented Oct 6, 2024

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

Gist

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

  1. Create a module which has a docker_image resource and a build.dockerfile value from a variable.
  2. Use module in parent script, provide variables
  3. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant