how can i attach existing ec2 instance to the newly creating autoscaling group using terraform??

76 views
Skip to first unread message

Syed Ruman

unread,
Feb 8, 2021, 6:47:04 AM2/8/21
to Terraform
I have existing EC2 instance which I want to attach for my newly created ASG using terraform.

Fernando 🐼

unread,
Feb 8, 2021, 7:08:43 AM2/8/21
to terrafo...@googlegroups.com
was the instance created by the ASG and then detached?
-- 


On Mon, 8 Feb 2021 at 11:47, Syed Ruman <syedr...@gmail.com> wrote:
I have existing EC2 instance which I want to attach for my newly created ASG using terraform.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/4f31aa2d-0215-4f1e-b5d3-0ae45d9523c8n%40googlegroups.com.

chamila

unread,
Feb 8, 2021, 7:15:58 AM2/8/21
to terrafo...@googlegroups.com
Sorry to restate what might be obvious. I did some searching since I was interested to see if this was possible and turns out this wasn't as of mid 2020 [1]. Might be better to open an issue in hashicorp/terraform repository if there isn't one already.

You might achieve a similar result by executing the corresponding AWS CLI command using a null_resource and a clever trigger but the state of that operation will not be under Terraform as part of the ASG/EC2 state.


Syed Ruman

unread,
Feb 8, 2021, 8:49:24 AM2/8/21
to terrafo...@googlegroups.com
@Fernando, Instance was launched before (did application configuration) and with that base setup I created AMI of that and gave that AMI in the launch template. I already have an instance running and want that instance to be part of my ASG.


You received this message because you are subscribed to a topic in the Google Groups "Terraform" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/terraform-tool/3EDSZRbp9Fg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/CAB2A5_nyjQ6Pcp79f4iH_VLnMA6OVruHT5jwQcH%2BW%3DCOXCs8Aw%40mail.gmail.com.

Fernando 🐼

unread,
Feb 8, 2021, 9:10:23 AM2/8/21
to terrafo...@googlegroups.com
If you have an AMI, why not just use the ASG to deploy the new pair of instances? 

--
Fernando 🐼

Syed Ruman

unread,
Feb 8, 2021, 10:20:33 AM2/8/21
to terrafo...@googlegroups.com
I did that, ASG created a new instance but then I had to manually terminate that old instance ( I have more than 20 service instances ), so if I implement ASG for all 20 services 20 templates and 20 ASG's will be there and any manual action will take time so..

Fernando 🐼

unread,
Feb 8, 2021, 10:27:57 AM2/8/21
to terrafo...@googlegroups.com
you can use aws cli to terminate your instances , or even filter by the ones that dont have the correct tag, and terminate all of them via web console.

-- 

Vijay Kumar

unread,
Feb 8, 2021, 11:51:54 AM2/8/21
to terrafo...@googlegroups.com
Even you can not add your already running instance in ASG via AWS console itself. Same also you can not do this from terraform. 

Terminate all the instances vai CLI if the instance is tagged. 

Regards,
Vijay K 



--
Thanks and Regards

Vijay Kumar
Contact No-9911334888

Syed Ruman

unread,
Feb 8, 2021, 12:06:09 PM2/8/21
to terrafo...@googlegroups.com
Hi Vijay,
We can attach an existing running instance from the console.
image.png


Vijay Kumar

unread,
Feb 8, 2021, 12:11:59 PM2/8/21
to terrafo...@googlegroups.com
Sorry i mean not from ASG.

Regards,
Vijay K 

Reply all
Reply to author
Forward
0 new messages