terraform-aws-modules / terraform-aws-autoscaling

Terraform module to create AWS Auto Scaling resources 🇺🇦
https://registry.terraform.io/modules/terraform-aws-modules/autoscaling/aws
Apache License 2.0
293 stars 556 forks source link

Not able to send any signal from user-data file executed on alb to terraform as an success or error after execution #128

Closed sachingawas229 closed 3 years ago

sachingawas229 commented 3 years ago

Hi,

I am running following code on my terraform project,

resource "aws_launch_template" "ArmorVoxLaunchTemplate" {
  image_id      = var.base_ami
  instance_type = var.armorvox_instance_type
  iam_instance_profile {
    name = var.iam_instance_profile
  }
  monitoring {
    enabled = false
  }
  vpc_security_group_ids = [aws_security_group.ArmorVoxSG.id]
  block_device_mappings {
    device_name = "/dev/xvda"
    ebs {
      volume_size           = var.volume_size
      delete_on_termination = true
      volume_type           = "gp2"
    }
  }
  //user_data = filebase64("${path.module}/scripts/armorvox.sh")
  user_data = base64encode(templatefile("${path.module}/scripts/armorvox.sh", {
    Region              = var.region
    ResourcesBucket     = var.resources_bucket
  }))
}

passing a variable to a user data and execute it on init to copy files from s3 and place it on ec2, however in CLoudformation I had a option of using wait for condition but in Terraform there is no way to stop terraform from executing further before we know that scrip is successful or failed. Can anyone put some light on this. I have already used remot-exec but that doesnt solve the purpose because it is just a hack. I want something which I can use to let terraform know stop because something is wrong.

bryantbiggs commented 3 years ago

hi @sachingawas229 your two options are:

  1. the remote exec as you have mentioned (https://github.com/hashicorp/terraform/issues/4668#issuecomment-419575242)
  2. or using an initial lifecycle hook
github-actions[bot] commented 2 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.