Getting "known after apply" while using yamlencode

Hi,

When using yamlencode here, terraform plan show “known after apply”. Any suggestions to get the actual changes in plan itself?

locals {
  karpenter_nodes_list_resource_limits = [
    for node_group in var.karpenter_nodes_list : merge(node_group, {
      limits = node_group.maxNodeCount != null ? {
        resources = {
          cpu    = data.aws_ec2_instance_type.karpenter[node_group.instance_types[0]].default_vcpus * node_group.maxNodeCount
          memory = "${data.aws_ec2_instance_type.karpenter[node_group.instance_types[0]].memory_size * node_group.maxNodeCount}Mi"
        }
      } : null
    })
  ]
}

resource "helm_release" "karpenter_nodetemplates" {
  count        = var.karpenter.enabled ? 1 : 0
  name         = "karpenter-nodetemplates"
  chart        = "${path.module}/charts/node-template"
  timeout      = 300
  version      = yamldecode(file("${path.module}/charts/node-template/Chart.yaml")).version
  force_update = false
  values = [
yamlencode({
      nodeGroups = local.karpenter_nodes_list_resource_limits
      subnetSelector = {
        subnetIds = var.private_subnet_ids
      }
      securityGroupSelector = {
        securityGroupIds = var.node_security_group_id
      }
    })
  ]
}

Terraform plan:

~ values                     = [
          - <<-EOT
                "nodeGroups":
....
            EOT,
        ] -> (known after apply)

Best regards,
Prabhu

Hi @prabhu43,

Some part of the input to the yamlencode function is unknown, therefor the result is unknown. There’s nothing more that can be known from what is shown here.

If you want to figure out which parts of the yamlencode argument are unknown, you can assign the same data to a root module output which can be more easily inspected during the plan.

Hi @jbardin

Thanks for the response.

input to yamlencode depends on variables. does it make unknown?

Best regards,
Prabhu

Using a variable does not make it unknown in and of itself, it depends on whether the variable input is known or not (however if it’s a root module variable it must be known).

Yeah, variable usage is not in root module. will that be the reason?

Again, it depends on the inputs to the variables, not that they are variables. You also have the local which itself references other things. It would be easiest to inspect the values and see what exactly what is unknown. The complete plan output also may show what the problem is, since anything which is unknown must originate from a resource elsewhere in the plan.

Thanks jbardin. Will try that