forked from networknuts/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocal-provisioner.tf
38 lines (32 loc) · 1003 Bytes
/
local-provisioner.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
provider "aws" {
region = "ap-south-1" #mumbai region
}
resource "aws_instance" "sampleserver" {
ami = "ami-0c1a7f89451184c8b" #this ami is specific to mumbai region
instance_type = "t2.micro"
tags = {
Name = "local-provisioner"
}
#this will run at creation
provisioner "local-exec" {
command = "echo Server IP address is ${self.private_ip}"
}
#if you want to send output to a file
#this will run at creation
provisioner "local-exec" {
command = "echo ${self.private_ip} > file_${aws_instance.sampleserver.id}.txt"
}
#multiple times provisioner can be defined
provisioner "local-exec" {
working_dir = "/tmp"
command = "echo ${aws_instance.sampleserver.private_ip} >> sampleserver-ips.txt"
}
provisioner "local-exec" {
command = "echo ${aws_instance.sampleserver.private_ip} >> /tmp/sampleserver-ips.txt"
}
#this will run at destroy
provisioner "local-exec" {
when = destroy
command = "echo Server is destroyed"
}
}