can we start and stop EC2 instance using Terraform

+2 votes
Hi

Can we start or stop EC2 instances using Terraform template? If yes please give me any URL. I have searched lot, but i still cant find.
Aug 16, 2020 in Terraform by Lakshminarayanan
• 1,370 points

recategorized Aug 17, 2020 by MD 7,654 views

1 answer to this question.

0 votes

Hi@Lakshminarayanan,

You can use command inside your local-exec provisioner. I have attached one example below. You can configure AWS CLI in your local system and use a local-exec provisioner in your terraform code.

resource "aws_instance" "web" {
  provisioner "local-exec" {
    command = "echo ${aws_instance.web.private_ip} >> private_ips.txt"
  }
}

Try to use this approach, it may work.

answered Aug 17, 2020 by MD
• 95,460 points

Related Questions In Terraform

0 votes
1 answer

How to launch EC2 windows instance with powershell script using terraform?

Hi, In your Terraform code, you have written ...READ MORE

answered Jul 21, 2020 in Terraform by MD
• 95,460 points
4,306 views
0 votes
1 answer

How to attach Elastic IP in EC2 instance using Terraform code?

Hi@akhtar, You can use aws_eip resource in your ...READ MORE

answered Jul 22, 2020 in Terraform by MD
• 95,460 points
8,575 views
+2 votes
1 answer

How to attach an elastic load balancer with ec2 instance using Terraform?

Hi@akhtar, You can use aws_elb_attachment resource in Terraform. ...READ MORE

answered Aug 17, 2020 in Terraform by MD
• 95,460 points
2,894 views
0 votes
1 answer

How to launch one EC2 instance for WordPress using Terraform?

Hi@akhtar, You can use the aws_instance resource in Terraform. ...READ MORE

answered Sep 9, 2020 in Terraform by MD
• 95,460 points
850 views
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,020 points
2,714 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,034 views
0 votes
1 answer

How to attach an EBS volume to EC2 instance using terraform?

Hi@akhtar, You can use aws_volume_attachment resource to attach ...READ MORE

answered Jun 12, 2020 in Terraform by MD
• 95,460 points
8,865 views
0 votes
1 answer

How to do ssh in EC2 instance using Terraform?

Hi@akhtar, To ssh in your EC2 instance, you ...READ MORE

answered Jun 15, 2020 in Terraform by MD
• 95,460 points
7,195 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP