Search code examples
setterraformterraform-template-file

how to create a set in terraform


I am trying to create a set to use as an argument in the setproduct function in terraform. When I try:

toset([a,b,c])

I get an error saying I can't convert a tuple to a list. I've tried various things like using tolist and ... and just having one pair of () braces in various places but I still can't get this to work - would anyone know how I can create a set from a,b and c?


Solution

  • set must have elements of the same type. Thus it can be:

    # set of strings
    toset(["a", "b", "c"])
    
    # set of numbers
    toset([1, 2, 3])
    
    # set of lists
    toset([["b"], ["c", 4], [3,3]])
    

    You can't mix types, so the error you are getting is because your are mixing types, e.g. list and number

    # will not work because different types
    toset([["b"], ["c", 4], 3])