Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TF cloud-init example
resource aws_instance some_instance {
ami = "${data.aws_ami.kubernetes.id}"
instance_type = "${var.instance_type}"
iam_instance_profile = "${var.instance_profile_name}"
key_name = "${var.ssh_key_name}"
subnet_id = "${var.subnet_id}"
vpc_security_group_ids = ["${var.security_group_ids}"]
user_data = "${data.template_cloudinit_config.master.rendered}"
}
data template_file cloud_config {
template = "${file("${path.module}/files/cloud-config.yaml")}"
vars {
something_to_subtitute_in = "${var.your_variable}"
}
}
data template_cloudinit_config master {
# A templated cloud-config
part {
filename = "cloud-config.yaml"
content_type = "text/cloud-config"
content = "${data.template_file.cloud_config.rendered}"
}
# You can also send files to the instance through TF + cloudinit
part {
filename = "init-master.sh"
content_type = "text/x-shellscript"
content = "${file("${path.module}/files/init-master.sh")}"
}
# Or maybe you want to inline something during this sequence
part {
content_type = "text/x-shellscript"
content = "/opt/puppetlabs/bin/puppet agent --test"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.