terraform-provider-helm icon indicating copy to clipboard operation
terraform-provider-helm copied to clipboard

Prevent setting variables with a `null` value

Open nitrocode opened this issue 4 years ago • 4 comments

Terraform, Provider, Kubernetes and Helm Versions

Terraform version: 0.15.x
Provider version: 2.1.2
Kubernetes version: 1.20

Affected Resource(s)

  • helm_release

Terraform Configuration Files

variable "disable_polling" {
  default = null
}

resource "helm_release" "this" {
  name = "external-secrets"

  # ... etc

  #### This will not work since DISABLE_POLLING will be enabled with a non null value
  #
  # set {
  #   name  = "env.DISABLE_POLLING"
  #   value = var.disable_polling
  # }

  # This is the workaround
  dynamic "set" {
    for_each = {
      for k, v in local.helm_values :
      k => v
      if v != null
    }
    content {
      name  = set.key
      value = set.value
    }
  }
}

locals {
  helm_values = {
    "nameOverride"        = "external-secrets"
    "env.DISABLE_POLLING" = var.disable_polling
  }
}

Debug Output

NOTE: In addition to Terraform debugging, please set HELM_DEBUG=1 to enable debugging info from helm.

Panic Output

Steps to Reproduce

  1. terraform apply

Expected Behavior

The helm_release resource should prevent any sets if the value is null

Actual Behavior

Using null caused a terraform error. The workaround of using dynamic eliminates the error and does what's expected.

Important Factoids

N/A

References

N/A

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

nitrocode avatar May 28 '21 21:05 nitrocode

same goes for values = [ ]. When I try this:

values = [
    file("settings/values.yaml"),
    fileexists("settings/helm/${var.environment}/values.yaml") ? file("settings/helm/${var.environment}/values.yaml") : null,
  ]

I got Null values are not allowed for this attribute value. if the second file not exist

jnmcfly avatar Mar 08 '22 09:03 jnmcfly

Imho, I'd expect Helm provider to set a value as passed to mimic the --set env.DISABLE_POLLING=null behavior. Alas, it's not possible with set {} directive.

anapsix avatar Dec 15 '22 15:12 anapsix

@jnmcfly instead of null, an empty string can be used and surrounded by compact()

  values = compact([
    file("${path.module}/settings/values.yaml"),
    fileexists("${path.module}/settings/helm/${var.environment}/values.yaml") ? file(
      "settings/helm/${var.environment}/values.yaml"
    ) : "",
  ])

@anapsix agreed! The helm provider should mimic the --set directive

nitrocode avatar Dec 16 '22 03:12 nitrocode

Marking this issue as stale due to inactivity. If this issue receives no comments in the next 30 days it will automatically be closed. If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. This helps our maintainers find and focus on the active issues. Maintainers may also remove the stale label at their discretion. Thank you!

github-actions[bot] avatar Dec 17 '23 00:12 github-actions[bot]