kreuzwerker/terraform-provider-docker

Using a file for storing environment variables

Opened this issue ยท 0 comments

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

TF v1.8.5, Provider version "~> 3.0.1"

Affected Resource(s)

  • docker_container

Terraform Configuration Files

terraform {
  required_providers {
    docker = {
      source  = "kreuzwerker/docker"
      version = "~> 3.0.1"
    }
  }
}

provider "docker" {}

# Define the MongoDB image resource
resource "docker_image" "mongo" {
  name         = "mongo"
  keep_locally = false
}

# Define the icds-frontend image resource
resource "docker_image" "icds_frontend" {
  name         = "ghcr.io/nmcc1212/icds-frontend:v3"
  keep_locally = false
}

# Define the volume for MongoDB data
resource "docker_volume" "mongo_data" {
  name = "mongo-data"
}

# Define the db container resource
resource "docker_container" "db" {
  image = docker_image.mongo.image_id
  name  = "db"
  hostname = "db"

  ports {
    internal = 27017
    external = 27017
  }

  volumes {
    volume_name    = docker_volume.mongo_data.name
    container_path = "/data/db"
  }

  volumes {
    host_path      = "${path.module}/mongo/init.sh"
    container_path = "/docker-entrypoint-initdb.d/init.sh"
    read_only      = true
  }

  volumes {
    host_path      = "${path.module}/mongo/socialAPI.posts.json"
    container_path = "/docker-entrypoint-initdb.d/socialAPI.posts.json"
    read_only      = true
  }
}

# Define the icds-frontend container resource
resource "docker_container" "icds_frontend" {
  image = docker_image.icds_frontend.image_id
  name  = "icds-frontend"

  ports {
    internal = 3000
    external = 3000
  }

  env = file(".tf.env")
}

and the .tf.env file (obvious redactions)

[
  "AUTH0_SECRET=x",
  "AUTH0_BASE_URL=http://localhost:3000",
  "AUTH0_ISSUER_BASE_URL=x",
  "AUTH0_CLIENT_ID=x",
  "AUTH0_CLIENT_SECRET=x",
  "API_URL = x",
  "MONGO_URI = mongodb://db:27017/socialAPI"
]

Debug Output

Panic Output

Expected Behaviour

Using the environment variables from the file

Actual Behaviour

โ”‚ 68: env = file(".tf.env")
โ”‚
โ”‚ Inappropriate value for attribute "env": set of string required.

Steps to Reproduce

Use provided tf code and create a .tf.env file with environment variables

  1. terraform apply

Important Factoids

References

  • #0000