Terraform Provisioners

What are provisioners?

file

resource “aws_instance” “myvm” {
. . .

Provisioner “file” {
Source = “<path to local file/directory>”
Destination = “<target machine path>”
}
}

local-exec

resource "aws_instance" "demo_vm_1" {
provider = aws.aws_west
ami = data.aws_ami.myAmi.id
instance_type = var.type

provisioner "local-exec" {
command = "echo \"VM 1 Public IP: \" ${self.public_ip} >> /mymachines/message1.txt"
}

tags = {
name = "Demo VM 1"
}
}

resource "aws_instance" "demo_vm_2" {
provider = aws.aws_west
ami = data.aws_ami.myAmi.id
instance_type = var.type

provisioner "local-exec" {
command = "echo \"VM 2 Public IP: \" ${self.public_ip} >> /mymachines/message2.txt"
}

tags = {
name = "Demo VM 2"
}
}

remote-exec

connection {
type = "ssh"
user = "ubuntu"
private_key = file(“<path to private key file>”)
host = aws_instance.myvm.public_ip
}

provisioner "remote-exec" {
inline = [
"chmod +x /tmp/setup.sh",
"/tmp/setup.sh args",
]
}

--

--

--

https://letsdotech.dev

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How I prepared for my first week at a Coding Bootcamp

What is the best way to learn code? Code TECHNIQ PRO course.

Learn to code with Code TECHNIQ PRO course, a career building learning program.

Reverse Engineering a Gameboy Advance game: Understanding the Mischievous DMA — Part 2

Kubernetes Cluster Autoscaler

Modern Engineering Buzzwords You Should Not Miss

Key Engineering Buzzwords In The Industry

Continuous Confidence: Defining Metrics That Count

58% OFF Coboc Black Color 3 ft.30AWG

[Datacamp] Intermediate Python — Loops

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Let's Do Tech

Let's Do Tech

https://letsdotech.dev

More from Medium

Generate SSH key using terraform for multiple environments

Automate Alibaba Cloud infra building with Terraform (step 1)

Terraform

Executing Terraform Scripts on CI/CD Pipeline using Self-Hosted Runners