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

Using a file for storing environment variables #629

Open
nmcc1212 opened this issue Jun 20, 2024 · 0 comments
Open

Using a file for storing environment variables #629

nmcc1212 opened this issue Jun 20, 2024 · 0 comments

Comments

@nmcc1212
Copy link

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
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