user658182
user658182

Reputation: 2350

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"
  }

Upvotes: 6

Views: 20650

Answers (2)

Justin W.
Justin W.

Reputation: 1007

Updated terraform syntax

You can use set_list

For example:

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

Upvotes: 9

The Fool
The Fool

Reputation: 20420

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}"
}

Upvotes: 12

Related Questions