# Not able to Parse environment variable through CLI on terraform

**URL:** <https://discuss.hashicorp.com/t/not-able-to-parse-environment-variable-through-cli-on-terraform/67992>\
**Category:** Terraform\
**Tags:** hcp-terraform, azure\
**Created:** [June 21, 2024, 3:07am UTC](https://discuss.hashicorp.com/t/not-able-to-parse-environment-variable-through-cli-on-terraform/67992 "2024-06-21T03:07:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SAURAVPADHY](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/sauravpadhy/32/42074_2.png) [@SAURAVPADHY](https://discuss.hashicorp.com/u/SAURAVPADHY)\
**Post date:** [June 21, 2024, 3:07am UTC](https://discuss.hashicorp.com/t/not-able-to-parse-environment-variable-through-cli-on-terraform/67992/1 "2024-06-21T03:07:13Z")

</div>

## terraform.tfvar

```auto
certconfig = {

"cert1" = {

name = "validcert3"

certificatename = {

"app1" = {

contents = "C:/Users/adminuser/Desktop/Appgateway_stg_https/modules/az_keyvault_appgw_policy/certificate/certificate.pfx"

# password = "Plants@12345"

}

}

},

"cert2" = {

name = "validcert4"

certificatename = {

"app2" = {

contents = "C:/Users/adminuser/Desktop/Appgateway_stg_https/modules/az_keyvault_appgw_policy/certificate/certificate2.pfx"

# password = "Plants@12345"

}

}

```

## variables.tf

```auto
variable "appgw_pid" {

type = any

default = ""

}

variable "appgw_key_perm" {

type = string

default = ""

}

variable "appgw_cert_perm" {

type = list(string)

default = [""]

}

variable "appgw_secret_perm" {

type = string

default = ""

}

variable "appgw_storage_perm" {

type = string

default = ""

}

variable "tenant_id" {

type = any

default = ""

}

variable "keyvault_id" {

type = any

default = ""

}

# variable "password" {

# default = ""

# type = string

# sensitive = true

# }

variable "certconfig" {

type = map(object({

name = string

# key_vault_id = any

certificate = optional(bool,true)

certificatename = optional(map(object({

contents = any

password = optional(any, null)

})))

}))

}

```

I want to parse it the password through environment variable like this:

```auto
$env:TF_VAR_certconfig_cert2_certificatename_app2 = '{"password":"Plants@12345"}'

```

but not able to read the password.plz help

Show quoted text

---

<div class="post-metadata">

**Author:** ![apparentlymart](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/apparentlymart/32/702_2.png) [@apparentlymart](https://discuss.hashicorp.com/u/apparentlymart)\
**Post date:** [June 24, 2024, 4:35pm UTC](https://discuss.hashicorp.com/t/not-able-to-parse-environment-variable-through-cli-on-terraform/67992/2 "2024-06-24T16:35:17Z")

</div>

Hi @SAURAVPADHY,

Your configuration does not declare any variable named `certconfig_cert2_certificatename_app2`, so the environment variable name you set will be totally ignored by Terraform. You can only use environment variables to set input variable names that are directly declared in your root module.

If your intention was to set `certconfig` then the correct environment variable name to use is `TF_VAR_certconfig`, and you will need to provide the entire value for that variable in the environment variable.

If you only want to set the passwords in the environment variable but have everything else set in a different way then you will need to declare a separate input variable for the passwords and then merge the two structures using expressions inside your module. This also has the advantage that you can declare the separate variable as sensitive so Terraform will know that it should not include values derived from it anywhere in the UI:

```auto
variable "certconfig_passwords" {
  type = map(string)

  sensitive = true
}

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/hashicorp/original/1X/79bf76adfd92a75631996933098f9ce29d37abf3.svg) [@system](https://discuss.hashicorp.com/u/system)\
**Post date:** [December 21, 2024, 4:35pm UTC](https://discuss.hashicorp.com/t/not-able-to-parse-environment-variable-through-cli-on-terraform/67992/3 "2024-12-21T16:35:53Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
