Hey guys, can someone help me to understand how to extract a value? Example: I need to access the asg name:
% tf state show module.cluster.aws_eks_node_group.kube-test
# module.cluster.aws_eks_node_group.kube-test:
resource "aws_eks_node_group" "kube-test" {
...
cluster_name = "kube-test"
...
resources = [
{
autoscaling_groups = [
{
name = "eks-kube-test-asdfasdf-asdf-asdf-asdf-fbbd59ec1d0e" <-- this value
},
]
remote_access_security_group_id = ""
},
]
...
Later, I’d like to use it like:
data "aws_autoscaling_group" "kube-test-asg" {
name = aws_eks_node_group.kube-test.resources[0].autoscaling_groups[0].name
}
I know I’m thinking about this all wrong. If someone can help me to understand how to extract that value I’d be appreciative. TIA
I was able to get this far:
data "aws_autoscaling_group" "asg_disco" {
name = aws_eks_node_group.apps.resources.0.autoscaling_groups.0.name
}
output "asg_name" {
value = data.aws_autoscaling_group.asg_disco
}
But, this will output all attributes for some reason:
myASG = {
"arn" = "arn:aws:autoscaling:us-west-2:123456789101:autoScalingGroup:asdf-a2f9-4ee1-9b34-67475966fc39:autoScalingGroupName/eks-test-stage-8cbee51c-qwerty-bf25-0f29-7f23c29bdb70"
"availability_zones" = toset([
"us-west-2a",
"us-west-2b",
"us-west-2c",
"us-west-2d",
])
"default_cooldown" = 300
"desired_capacity" = 4
"health_check_grace_period" = 15
"health_check_type" = "EC2"
"id" = "eks-test-stage-8cbee51c-qwerty-bf25-0f29-7f23c29bdb70"
"launch_configuration" = ""
"launch_template" = tolist([])
"load_balancers" = toset([])
"max_size" = 12
"min_size" = 4
"name" = "eks-test-stage-8cbee51c-qwerty-bf25-0f29-7f23c29bdb70"
"new_instances_protected_from_scale_in" = false
"placement_group" = ""
"service_linked_role_arn" = "arn:aws:iam::123456789101:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling"
"status" = ""
"target_group_arns" = toset([])
"termination_policies" = toset([
"AllocationStrategy",
"OldestInstance",
"OldestLaunchTemplate",
])
"vpc_zone_identifier" = "subnet-asdf,subnet-asdf,subnet-asdf,subnet-asdf"
}
I understand the limitation of the expression aws_eks_node_group.apps.resources.0.autoscaling_groups.0.name
but can someone think of a creative solution?
adding .name to the output did it
data “aws_autoscaling_group” “asg_disco” {
name = aws_eks_node_group.apps.resources.0.autoscaling_groups.0.name
}
output “asg_name” {
value = data.aws_autoscaling_group.asg_disco.name # ← super silly
}
PS: nobody should do this particular thing; bad idea.