random access memories

Writing Files with Terraform and `templatefile`

I wanted to be able to write an ssh stanza to my ~/.ssh directory after terraform apply. Below is a simple configuration.

Configuration

main.tf

provider "local" {}


resource "local_file" "ssh-stanza" {
    filename = pathexpand("~/.ssh/my-ssh-config")
    content  = templatefile("templates/stanza.tftpl", {ip = resource.ip}
}

templates/stanza.tftpl

Host my-server
    Host ${ip}

Links

Local File Provider

templatefile