How does local-exec provisioner work in Terraform

0 votes

Hi Guys,

I have created one EC2 instance in AWS using Terraform code. I want to save the Private IP of the instance in my local system. How can I do that?

Jul 23, 2020 in Terraform by akhtar
• 38,260 points
5,861 views

1 answer to this question.

0 votes

Hi@akhtar,

You can use a local-exec provisioner to do this task. The local-exec provisioner invokes a local executable after a resource is created. This invokes a process on the machine running the Terraform, not on the resource. You can see the remote-exec provisioned to run commands on the resource. I have attached one example below for your reference.

resource "aws_instance" "web" {
  provisioner "local-exec" {
    command = "echo ${aws_instance.web.private_ip} >> private_ips.txt"
  }
}
answered Jul 23, 2020 by MD
• 95,460 points

Related Questions In Terraform

0 votes
1 answer

How to create one key in AWS using terraform?

Hi@akhtar, You can use aws_key_pair resource n terraform. ...READ MORE

answered Jun 11, 2020 in Terraform by MD
• 95,460 points
1,506 views
0 votes
1 answer

How to create a folder in S3 bucket using terraform?

Hi@akhtar, You can use aws_s3_bucket_object resource to create one ...READ MORE

answered Jun 11, 2020 in Terraform by MD
• 95,460 points
10,797 views
0 votes
1 answer

How to run local command using terraform?

Hi@akhtar, You can use provisioner keyword to run ...READ MORE

answered Jun 15, 2020 in Terraform by MD
• 95,460 points
1,817 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,117 views
0 votes
1 answer
0 votes
1 answer

What is the remote-exec provisioner in Terraform?

Hi@akhtar, You can use a remote-exec provisioner to ...READ MORE

answered Jul 23, 2020 in Terraform by MD
• 95,460 points
3,670 views
0 votes
1 answer

How does Terraform work?

Hi@akhtar, Terraform produce an execution plan delineate, what ...READ MORE

answered Sep 29, 2020 in Terraform by MD
• 95,460 points
1,194 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