Home > Software engineering >  How do I pass in user data to my eks nodes?
How do I pass in user data to my eks nodes?

Time:07-01

I want to pass in user data when my eks nodes deploy, but I'm not sure how to implement that since there isn't a user data argument.

Here's my eks node group resource block

resource "aws_eks_node_group" "nodes_eks" {

  cluster_name    = aws_eks_cluster.eks.name
  node_group_name = "eks-node-group"
  node_role_arn   = aws_iam_role.eks_nodes.arn
  subnet_ids      = module.vpc.private_subnets
  remote_access {
    ec2_ssh_key = aws_key_pair.bastion_auth.id

  }

  scaling_config {
    desired_size = 3
    max_size     = 6
    min_size     = 3
  }

  ami_type             = "AL2_x86_64"
  capacity_type        = "ON_DEMAND"
  force_update_version = false
  instance_types       = [var.instance_type]
  labels = {
    role = "nodes-pool-1"
  }

  version = var.k8s_version

  depends_on = [
    aws_iam_role_policy_attachment.amazon_eks_worker_node_policy,
    aws_iam_role_policy_attachment.amazon_eks_cni_policy,
    aws_iam_role_policy_attachment.amazon_ec2_container_registry_read_only,
  ]
}

All I want to do is run a simple script to install Apache when my nodes are created, but I don't know how without the user data argument

CodePudding user response:

You should use the launch_template configuration block as described in [1].


[1] https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/eks_node_group#launch_template-configuration-block

  • Related