hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.4k stars 9.5k forks source link

append collection function #25035

Open iancward opened 4 years ago

iancward commented 4 years ago

Current Terraform Version

v0.12.24

Use-cases

It would be nice to be able to append items to a list, instead of creating an arbitrary list simply to use the concat() function

Attempted Solutions

To add items to a list, you must create a new list and use the concat() function.

variable "input_list" {
  type = list(string)
  default = ["one", "two", "three"]
}

locals {
  new_value = "four"
  merged_list = concat(var.input_list, [local.new_value])
}

Proposal

A new apppend() function that takes a list and a value, and adds the value to the list.

variable "input_list" {
  type = list(string)
  default = ["one", "two", "three"]
}

locals {
  new_value = "four"
  merged_list = append(var.input_list, local.new_value)
}

References

crw commented 6 months ago

Thank you for your continued interest in this issue.

Terraform version 1.8 launches with support of provider-defined functions. It is now possible to implement your own functions! We would love to see this implemented as a provider-defined function.

Please see the provider-defined functions documentation to learn how to implement functions in your providers. If you are new to provider development, learn how to create a new provider with the Terraform Plugin Framework. If you have any questions, please visit the Terraform Plugin Development category in our official forum.

We hope this feature unblocks future function development and provides more flexibility for the Terraform community. Thank you for your continued support of Terraform!