'Using Terraform's helm_release, how do I set array or list values?

For example, per the helm chart documentation for Drupal, the default value for accessModes is ["ReadWriteOnce"] which translates to the following in the YAML:

...
accessModes
- ReadWriteOnce

When using the Terraform helm_release resource, the following do not work and the yaml file always shows the default from above:

  set {
    name  = "persistence.accessModes"
    value = "ReadWriteMany"
  }
  set {
    name  = "persistence.accessModes"
    value = "[\"ReadWriteMany\"]"
  }
  set {
    name  = "persistence.accessModes"
    value = "- ReadWriteMany"
  }


Solution 1:[1]

You would set it the same way as with the helm CLI --set flag. For example, using the index notation.

As of Helm 2.5.0, it is possible to access list items using an array index syntax. For example, --set servers[0].port=80

set {
  name  = "persistence.accessModes[0]"
  value = "ReadWriteMany"
}

The alternative syntax is using curly braces. Where you can add the list items separated with a comma between the braces.

Lists can be expressed by enclosing values in { and }. For example, --set name={a, b, c}

set {
  name  = "persistence.accessModes"
  value = "{ReadWriteMany}"
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1