Skip to content

Instantly share code, notes, and snippets.

@phinze
Created April 15, 2015 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phinze/2f1d347d9a59e06d7fdb to your computer and use it in GitHub Desktop.
Save phinze/2f1d347d9a59e06d7fdb to your computer and use it in GitHub Desktop.
Terraform Example: injecting config into an AWS instance
variable "instance_type" {
default = "t2.micro"
}
variable "region" {
default = "us-west-2"
}
variable "custom" {
default = "env-specific-value"
}
module "ami" {
source = "github.com/terraform-community-modules/tf_aws_ubuntu_ami/ebs"
region = "${var.region}"
distribution = "trusty"
instance_type = "${var.instance_type}"
}
resource "aws_instance" "web" {
ami = "${module.ami.ami_id}"
instance_type = "${var.instance_type}"
key_name = "tftest"
connection {
user = "ubuntu"
agent = true
}
provisioner "remote-exec" {
inline = [
"echo ${self.public_ip} | sudo tee /var/run/public_ip",
"echo ${var.custom} | sudo tee /var/run/custom"
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment