Domain joining ec2 of autoscaling group in aws

18 Views Asked by At

I have existing domain join script that works fine for windows ec2 creation in terraform. Invoke powershell using null resource of terraform. Insatnce Id's are passed here when EC2 is created and ID is returned to main module. Below is script.

How can use this same script to pass instance id's when autoscaling using ASG ?. Any terraform reference script or git repo?

resource "null_resource" "provision" {
  count = var.provision ? var.instance_count : 0

  triggers = {
    current_instance_id = module.aws_instance.instance_ids[count.index]
    #powershell_script   = filemd5("${var.script_source}general/domain-join.ps1")
  }

  
  // use tmp local admin password
  provisioner "local-exec" {
    command     = "${var.script_source}general/domain-join.ps1 '${module.aws_instance.private_ips[count.index]}' '${var.instance_admin_account}' '${var.tmp_admin_password}' 'corp\\${var.svc_acct_username}' '${var.svc_acct_password}' '${module.aws_instance.names[count.index]}' '${var.domain_name}' '${var.organizational_unit_distinguished_name}'"
    interpreter = ["PowerShell", "-Command"]
  }
  
}
0

There are 0 best solutions below