Skip to content

Variable containing hyphens can not be set using environment variable #37885

@colllijo

Description

@colllijo

Terraform Version

Terraform v1.13.5
on linux_amd64
+ provider registry.terraform.io/hashicorp/null v3.2.4

Terraform Configuration Files

terraform {
  required_version = ">= 1.13.5"
}

variable "works" {
  type = string
}

variable "does-not-work" {
  type = string
}

resource "null_resource" "dummy" {
  provisioner "local-exec" {
    command = "echo 'This works: ${var.works}, but this doesn't: ${var.does-not-work}"
  }
}

Debug Output

debug.log

Expected Behavior

Terraform should have seen that the environment variable (TF_VAR_does__not__work) was set and used the value from this environment variable as value for var.does-not-work.

This would be the same behavior as with TF_TOKEN where hyphens in the hostname are also replaced by two underscores.

Actual Behavior

Terraform does not find the environment variable and terraform prompts for it / errors, because it hasn't been set.

Steps to Reproduce

  1. terraform init
  2. export TF_VAR_works="works"
  3. export TF_VAR_does__not__work="doesn't work"
  4. terraform apply

Additional Context

No response

References

Generative AI / LLM assisted development?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions