Hi,
I’ve following error after upgrading from Terraform 0.11.14 to 0.12.26:
Environment:
- provider “helm” (hashicorp/helm) 1.2.3
- provider “azurerm” (hashicorp/azurerm) 1.33.1
- provider “kubernetes” (hashicorp/kubernetes) 1.10.0
- provider “tls” (hashicorp/tls) 2.1.1
Command:
terraform plan -var-file myvalues.tfvars
Error message:
Error: Invalid index
on main.tf line 196, in module "mod1":
196: ingress_host = var.ingress["myval1"]
|----------------
| var.ingress is map of string with 1 element
The given key does not identify an element in this collection value.
Configuration files:
main.tf:
module "mod1" {
source = "../modules/mod1"
ingress_host = var.ingress["myval1"] #I believe here's the offending line
...
}
variables.tf:
variable "ingress" {
type = map(string)
description = "Map of ingress hosts"
default = {
myval1 = "address1.domain.com"
myval2 = "address1.domain.com
myval3 = "address1.domain.com"
}
}
myvalyes.tfvars file:
...
ingress={myval1="address1.mydomain.com", myval2="address2.mydomain.com", myval3="address3.mydomain.com"}
...
Module mod1 variables.tf:
variable "ingress_host" {
type = string
default = ""
description = ""
}
And honestly, I don’t understand what’s wrong with the ‘var.ingress[“myval1”]’ line. The original line for Terraform 0.11.14 was:
ingress_host = "${var.ingress["myval1"]}"
so I can’t see any issue with new format.
Upgrade from 0.11.14 to 0.12.26 went fine without any issues reported by ‘terraform 0.12upgrade’ command. The problem is that I can’t create new environments using the new version of Terraform. I would like to make sure that I can declare variable (map of strings) and then pass particular values as strings to modules installed locally.
Could you help me with this issue, please?