How to power on AWS instance with Terraform - amazon-web-services

Sorry I am very new to Terraform.
I create AWS instance with Terraform successfully.
Then I power off the instance in AWS web management console.
How to power on the instance with Terraform?

You would have to use local-exec to run AWS CLI's start-instances.

You can use the instance_type value of aws_instance terraform resource.
instance_type : (Optional) The instance type to use for the instance.
Updates to this field will trigger a stop/start of the EC2 instance.

Related

How to destroy a resource with terraform TF file

I create a terraform file that create AWS EC2 instance on AWS console then i create an AMI from that instance, know i want to destroy running instance and keep AMI with terraform language, what should i do?
Thanks you attentions
Try
terraform destroy -target aws_instance.NAME
substitute your Terraformed EC2 instance's name

aws ec2 import-image via Terraform

I'm searching for the Terraform equivalent of "aws ec2 import-image --description "Windows 2008 OVA" --license-type --disk-containers file://containers.json" but cannot find a matching resource command in the documentation.
The purpose is to lift an OVA image out of S3 and covert to AMI so it can be used to launch EC2 instances.
There is an option in packer where you can create OVA by a builder and upload it to S3 and then create an AMI. Once you have the AMI, you can inject into your terraform script to launch it.
https://www.packer.io/docs/post-processors/amazon-import.html
https://github.com/terraform-providers/terraform-provider-aws/issues/5998
Right now terraform not supporting for ec2 image import

Can i start my AWS RDS instance in bootstrap action of EMR creation?

I am using a RDS instance as an external hive metastore, can i start my AWS RDS instance in bootstrap action of EMR creation?
Yes. you can. All EMR's EC2 instances will assume instance profile role - EMR_EC2_DefaultRole by default. Which means if you have proper permissions on that EC2 instance profile role that you use for EMR, you can run AWS CLI commands on your Bootstrap Action script to start RDS Instance.
https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-iam-roles.html
https://docs.aws.amazon.com/cli/latest/reference/rds/start-db-instance.html

How can I set existing EIPs to Auto scaled instances in AWS when they launch automatically?

I have cloud formation template which creates auto-scaling group with desired state 2. I need instances to be attached to existing eips when they get launched. How can I do this?
You need to write a custom user data script that assigns the elastic IP to the instance. You can not do this using CloudFormation templates yet. The AWS CLI to be used is: aws ec2 associate-address. For this, the best practice would be to assign and IAM role with ec2:AssociateAddress permission.
The command will look like this: aws ec2 associate-address --instance-id $INSTANCE_ID --allocation-id $ALLOCATION_ID --allow-reassociation
While the allocation id will need to be hardcoded in the template, you can get the instance id within the instance using the command: curl -s http://169.254.169.254/latest/meta-data/instance-id. Refer this thread
for more details.

How to add exisiting EC2 instances to an auto scaling group using Terraform

I am using terraform to build my infra and trying to add an existing ec2 instance to a new autoscaling group.
We can do that using the AWS CLI Here.
Is there a way to do it using terraform ?