From 2d35de7f7a460d35682170ebd004c06b5262ac9d Mon Sep 17 00:00:00 2001 From: Joel Duverge Date: Mon, 12 Aug 2024 13:51:49 -0500 Subject: [PATCH 1/2] adding metrics and user data to asg for datadog --- main.tf | 8 +++++++- variables.tf | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 54794bb..3c31a96 100644 --- a/main.tf +++ b/main.tf @@ -40,6 +40,8 @@ resource "aws_autoscaling_group" "this" { wait_for_capacity_timeout = "15m" vpc_zone_identifier = var.asg_subnets + enabled_metrics = var.enabled_metrics + target_group_arns = concat( var.asg_additional_target_group_arns, [aws_lb_target_group.this.arn], @@ -87,6 +89,10 @@ resource "aws_ebs_volume" "data" { ) } +locals { + combined_user_data = "${data.template_cloudinit_config.this.rendered}\n${var.additional_user_data}" +} + resource "aws_launch_configuration" "this" { name_prefix = var.name associate_public_ip_address = false @@ -94,7 +100,7 @@ resource "aws_launch_configuration" "this" { image_id = var.ami_id instance_type = var.asg_instance_type key_name = var.asg_key_name - user_data_base64 = data.template_cloudinit_config.this.rendered + user_data = base64encode(local.combined_user_data) security_groups = concat( var.asg_additional_security_groups, diff --git a/variables.tf b/variables.tf index 342eaf6..58aefb9 100644 --- a/variables.tf +++ b/variables.tf @@ -111,6 +111,18 @@ variable "asg_subnets" { type = list(string) } +variable "enabled_metrics" { + description = "List of enabled metrics for the Auto Scaling Group" + type = list(string) + default = [] +} + +variable "user_data" { + description = "User data to configure the EC2 instances of Nexus" + type = string + default = "" +} + ######################################## # Networking Vars ######################################## @@ -133,6 +145,12 @@ variable "access_logs_prefix" { type = string } +variable "additional_user_data" { + description = "Additional user data to configure the EC2 instances" + type = string + default = "" +} + variable "availability_zone" { default = null description = "Specify the availability zone that the instance will be deployed in if using an EBS volume" From cded989732606a3276b8231a6c34fb006ce9f581 Mon Sep 17 00:00:00 2001 From: Joel Duverge Date: Mon, 12 Aug 2024 13:53:38 -0500 Subject: [PATCH 2/2] adding metrics and user data to asg for datadog --- variables.tf | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/variables.tf b/variables.tf index 58aefb9..ab7db5c 100644 --- a/variables.tf +++ b/variables.tf @@ -117,8 +117,8 @@ variable "enabled_metrics" { default = [] } -variable "user_data" { - description = "User data to configure the EC2 instances of Nexus" +variable "additional_user_data" { + description = "Additional user data to configure the EC2 instances" type = string default = "" } @@ -145,12 +145,6 @@ variable "access_logs_prefix" { type = string } -variable "additional_user_data" { - description = "Additional user data to configure the EC2 instances" - type = string - default = "" -} - variable "availability_zone" { default = null description = "Specify the availability zone that the instance will be deployed in if using an EBS volume"