How to access to Terraform resource output

Viewed 111

I have a resource task which gives the next output:

aws_eks_node_group.managed_workers["es"]:
resource "aws_eks_node_group" "managed_workers" {
    ami_type        = "AL2_x86_64"
    arn             = "arn:aws:eks:eu-west-1:xxxxx:nodegroup/EKS/EKS_-nodegroup-CI-es/b2be06b7-e5fe-b346-0e29-ec3f459f7b2c"
    capacity_type   = "ON_DEMAND"
    cluster_name    = "EKS_CLuster"
    disk_size       = 20
    id              = "EKS:EKS_-API-nodegroup-CI-es"
    instance_types  = [
        "m5.xlarge",
    ]
    labels          = {
        "autoscalergroup" = "pool"
        "lifecycle"       = "OnDemand"
    }
    node_group_name = "worker-node-nodegroup-1"
    node_role_arn   = "arn:aws:iam::xxxxx:role/EKS_workernode"
    release_version = "1.18.9-20210722"
    resources       = [
        {
            autoscaling_groups              = [
                {
                    name = "eks-xxx-xxx-xx"
                },
            ]
            remote_access_security_group_id = "sg-xxxx"
        },
    ]

I'm trying to use the autoscaling_groups.name on this way:

resource "aws_autoscaling_group_tag" "nodetags" {
  for_each = aws_eks_node_group.managed_workers

  autoscaling_group_name = each.value.resources.autoscaling_groups.name

But I'm not able to access to resources.autoscaling_groups.name with success.. Someone know how to access to this data?

Thanks

1 Answers

resources and autoscaling_groups are both lists.

Use each.value.resources[0].autoscaling_groups[0].name

Related