Reputation: 104
I am using terraform-aws-eks module to deploy EKS clusters. I was hoping for some help turning node_groups map of maps into a variable so that I can modify a variables file for different environments. Here is the Map of Maps:
node_groups = {
example = {
desired_capacity = 1
max_capacity = 10
min_capacity = 1
instance_types = ["m5.large"]
capacity_type = "ON_DEMAND"
k8s_labels = {
Environment = "test"
GithubRepo = "terraform-aws-eks"
GithubOrg = "terraform-aws-modules"
}
additional_tags = {
ExtraTag = "example"
}
}
}
I want to be able to reference a variable instead of the map in main.tf e.g.
node_groups = var.node_groups
I'm struggling with the various levels of the list(Object) in variables.tf. Thanks in advance for the help.
Upvotes: 1
Views: 1151
Reputation: 74219
I think you're asking what might be a suitable type constraint for a variable accepting a data structure like this. If so, here's an attempt:
type = map(object({
desired_capacity = number
max_capacity = number
min_capacity = number
instance_types = set(string)
capacity_type = string
k8s_labels = map(string)
additional_tags = map(string)
}))
I made some guesses of your intent here:
instance_types
to be a set of strings rather than a list of strings because there isn't typically a meaningful ordering of instance types, and a set is an appropriate data structure for an unordered collection. However, if do intend to make use of the order that the instance types are set in then you might change this to list(string)
instead.k8s_labels
and additional_tags
it seems like these are just arbitarary key/value pairs chosen by the caller rather than a specific data structure specified by your module, so I constrained them as map(string)
rather than as a specific object type covering the exact attributes names you showed in your example. If you intend to require exactly Environment
, GithubRepo
and GithubOrg
attributes in k8s_labels
, rather than leaving it up to the caller to decide, then you can change that to be an object type instead of a map type.Upvotes: 1