hashicorp / terraform-k8s

Terraform Cloud Operator for Kubernetes
https://learn.hashicorp.com/tutorials/terraform/kubernetes-operator?in=terraform/kubernetes
Mozilla Public License 2.0
454 stars 71 forks source link

Fixing conversion of null value #130

Open jtyr opened 2 years ago

jtyr commented 2 years ago

Community Note


This PR is fixing handling of outputs that contain null. In the current implementation, if an output contains anywhere a value that is null, that output key is skipped completely. For example if the output is the result from the random_password resource:

resource "random_password" "password" {
  length           = 16
  special          = true
  override_special = "!#$%&*()-_=+[]{}<>:?"
}

output "password" {
  description = "Password output"
  value       = random_password.password
  sensitive   = true
}

the keepers key is completely missing in the outputs.

$ kubectl get secret -o yaml test-outputs | yq e '.data.password' - | base64 -d 
{"id":"none","length":16,"lower":true,"min_lower":0,"min_numeric":0,"min_special":0,"min_upper":0,"number":true,"override_special":"!#$%&*()-_=+[]{}<>:?","result":"Z3i?:ZbQ#RzmPwk<","special":true,"upper":true,}

As a consequence of skipping the keepers from outputs, there is also an extra , at the end of the encoded output.

With this PR applied, the outputs contain the keepers and even if it would be skipped, the extra , would not be added:

$ kubectl get secret -o yaml test-outputs | yq e '.data.password' - | base64 -d 
{"id":"none","keepers":null,"length":16,"lower":true,"min_lower":0,"min_numeric":0,"min_special":0,"min_upper":0,"number":true,"override_special":"!#$%&*()-_=+[]{}<>:?","result":"Z3i?:ZbQ#RzmPwk<","special":true,"upper":true}

Release note for CHANGELOG:

Fix for handling null values in outputs.