Skip to content

Instantly share code, notes, and snippets.

@janeczku
Last active November 17, 2020 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janeczku/ba2f9b2686ec401cbe363582886cb4fd to your computer and use it in GitHub Desktop.
Save janeczku/ba2f9b2686ec401cbe363582886cb4fd to your computer and use it in GitHub Desktop.
EKS Launch Template /w Cloud-Init Userdata

Terraform Example: Create EC2 Launch Template with Cloud-Init Userdata

Create Cloud-Init template

data "template_file" "cloud_init" {
  template = "${file("init.tpl")}"
  template = <<EOF
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==BOUNDARY=="

--==BOUNDARY==
Content-Type: text/cloud-config; charset="us-ascii"

write_files:
- path: /etc/sysctl.d/55-elasticsearch.conf
  owner: root
  content: |
    vm.max_map_count=262144
runcmd:
- sysctl -w vm.max_map_count=262144

--==BOUNDARY==--\
EOF
}

Create EC2 Launch Template

resource "aws_launch_template" "foo" {
  ...
  user_data = "${base64encode(data.template_file.cloud_init.rendered)}"
  ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment