Accessing nested output object from a module

I am trying to deploy Karpenter, following the docs of AWS terraform module here.

The terraform code is pretty simple:

module "eks" {
  source = "terraform-aws-modules/eks"

  # Shown just for connection between cluster and Karpenter sub-module below
  eks_managed_node_groups = {
    initial = {
      instance_types = ["t3.medium"]

      min_size     = 1
      max_size     = 3
      desired_size = 1

module "karpenter" {
  source = "terraform-aws-modules/eks/aws//modules/karpenter"

  cluster_name = module.eks.cluster_name

  irsa_oidc_provider_arn          = module.eks.oidc_provider_arn
  irsa_namespace_service_accounts = ["karpenter:karpenter"]

  create_iam_role = false
  iam_role_arn    = module.eks.eks_managed_node_groups["initial"].iam_role_arn

  tags = {
    Environment = "dev"
    Terraform   = "true"

My challenge is with this line:

 iam_role_arn    = module.eks.eks_managed_node_groups["initial"].iam_role_arn

How can I write it in CDKTF? I can generate the module code from terraform, and I can see there is eksCluster.eksManagedNodeGroupsOutput (my code is in TypeScript) of type string. I tried many things using Fn and Token and so far the best I could do is

Token.asStringMap(Fn.element(Fn.values(Token.asStringMap(eksCluster.eksManagedNodeGroupsOutput)), 0))

Store that as output and consume it in another module using:

const eksRemoteState = new DataTerraformRemoteState(
      hostname: "",
      organization: "<>",
      workspaces: {
        name: "eks",

Fn.element(Fn.values(eksRemoteState.get("node-group")), 0)

Which is very error prune, but seems to work. i would like to have something like Fn.element just to get values from map, but I couldn’t find anything.

Hi @omerlh1 :wave:

You are probably looking for Fn.lookup()? It requires you to specify a default value though, which is sometimes a bit verbose but it’s the best thing to use at this time, I’d say.

Thanks! That solved it :slight_smile: