I have an attribute “my_code” in my terraform code. For this currently, users provide the input like this
my_code = "15"
but we want to change it from a number to a list so that users can provide either the number which they are doing right now (so that it remains backward compatible) like above or they can provide a list of numbers like below
my_code = ["15", "20"]
Currently my terraform code looks like below
my_code = lookup(all_operations, "my_code", null)
I was thinking of doing something like below so that it takes both values. If it’s a number it will convert it to a list and if it’s already a list it will keep it as it is.
my_code = can(list, lookup(all_operations, "my_code", null)) ? [lookup(all_operations, "my_code", null)] : lookup(all_operations, "my_code", null)
But with this error I am getting below error
my_code = can(list, lookup(all_operations, "my_code", null)) ? [lookup(all_operations, "my_code", null)] : lookup(all_operations, "my_code", null)
│
│ A reference to a resource type must be followed by at least one attribute
│ access, specifying the resource name
Tried like below
my_code = type(lookup(all_operations, "my_code", null)) == list(any) ? lookup(all_operations, "my_code", null) : [lookup(all_operations, "my_code", null)]
got the same error
my_code = type(lookup(all_operations, "my_code", null)) == list(any) ? lookup(all_operations, "my_code", null) : [lookup(all_operations, "my_code", null)]
│
│ A reference to a resource type must be followed by at least one attribute
│ access, specifying the resource name
Any help would be greatly appreciated. Thanks in advance