I'm building an infrastructure for a project I have, and I wonder if Terraform can get ec2's state. Basically, I need to create an ec2 with all the requirements, generate it to an AMI, and create an ASG. I want that the ec2 would stop after it's ready and only then to continue with the steps (AMI and ASG). Does anyone have any experience with that? help would be much appreciated Thanks!
CodePudding user response:
TF just launches your instance, it does not wait for it be fully running nor stopped. But you could stop it automatically from its user_data. So basically, the instance would run a user_data script that would stop it after launch.
In terms of TF, you would have to develop your own custom data source which would query the instance state iteratively till the instance is stopped.
CodePudding user response:
You can use "null_resource" with local-exec provisioner to run AMI creation, the local exec run will complete only after ami is ready. You can then provision ASG
