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

Variable of type map<string, list> #6700

Closed
joshuaspence opened this issue May 17, 2016 · 8 comments
Closed

Variable of type map<string, list> #6700

joshuaspence opened this issue May 17, 2016 · 8 comments
Labels

Comments

@joshuaspence
Copy link
Contributor

I've just built Terraform from the master branch in order to play with list variables. I've noticed that it is not possible to create a variable of type map which maps string to list. For example, the following variable is invalid:

variable "availability_zones" {
  type = "map"

  default {
    ap-southeast-2 = ["ap-southeast-2a", "ap-southeast-2b", "ap-southeast-2c"]
    us-east-1      = ["us-east-1a", "us-east-1d", "us-east-1e"]
  }
}

The following error is reported:

Error loading Terraform: Error loading config: Error loading REDACTED/common_variables.tf: 'availability_zones' has a default value which is not of type 'map'

Is this expected or a bug?

@apparentlymart
Copy link
Contributor

Hi @joshuaspence!

The new variable type support in 0.7 (master, for now) only supports strings, lists of strings, and maps from string to string. More complex nested structures are not supported yet.

@jen20
Copy link
Contributor

jen20 commented May 17, 2016

Hi @joshuaspence! As @apparentlymart points out, for now it is only possible to have maps which are string -> string (as before). Internally there is some support for this, but it is not currently exposed and that is not planned for 0.7. We will circle back to this post-0.7, but for now I'll close this as "by design". Thanks for bringing it up!

@jen20 jen20 closed this as completed May 17, 2016
@joshuaspence
Copy link
Contributor Author

Is there an issue that I can follow for supporting this type of variable?

@MarcBittner
Copy link

I would second the request for this functionality.

@mieciu
Copy link

mieciu commented Oct 25, 2016

I've ran into exactly the same issue (having conditional region-az map) today...

@mieciu
Copy link

mieciu commented Oct 25, 2016

Workaround for not having list support in map could be done like this:

variable "region" {
  description = "AWS region"
  default = "us-east-1"
}
variable "availability_zones_in_ap_southeast_2" {
  description = "VPC-capable AZ's in ap-southeast-2 region"
  type = "list"
  default = [ "ap-southeast-2a", "ap-southeast-2b", "ap-southeast-2c" ]
}
variable "availability_zones_in_us_east_1" {
  description = "VPC-capable AZ's in us-east-1 region"
  type = "list"
  default = [ "us-east-1a", "us-east-1b" ,"us-east-1d" ]
}
variable "region_to_azs" {
  type = "map"
  default = {
    us-east-1 = "availability_zones_in_us_east_1"
    ap-southeast-2 = "availability_zones_in_ap_southeast_2"
  }

And this compiles fine without any single error.

However, in order to get that A-Z's list you'd need to do the following:

}
variable "availability_zones" {
  description = "choose proper AZ based on var.region variable"
  type = "list"
  default = ["${${lookup(var.region_to_azs,var.region)}}"]
}

which basically doesn't work 😞

@apparentlymart
Copy link
Contributor

Part of the set of changes that would make this (map of lists) possible is currently going on in hashicorp/hil#42. That addresses making the interpolation language be able to represent the element types of maps and lists so that it can be understood that indexing a map of lists produces a list.

There's still at least one follow up change required in Terraform to make variables accept such values, and likely more work at various layers in between to bring these things together.

This comment is mainly just to create a link between these issues to remind me to pay attention to this one later when posting follow-ups. :D

@ghost
Copy link

ghost commented Apr 18, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants