Skip to content

Instantly share code, notes, and snippets.

@himlohiya
Last active November 30, 2018 21:04
Show Gist options
  • Save himlohiya/091df5cf3d91f95c47b04ea0c410d557 to your computer and use it in GitHub Desktop.
Save himlohiya/091df5cf3d91f95c47b04ea0c410d557 to your computer and use it in GitHub Desktop.
resource "aws_instance" "example" {
ami = "${lookup(var.AMIS, var.AWS_REGION)}"
instance_type = "t2.micro"
# the VPC subnet
subnet_id = "${aws_subnet.main-public-1.id}"
# the security group
vpc_security_group_ids = ["${aws_security_group.allow-ssh.id}"]
# the public SSH key
key_name = "${aws_key_pair.mykeypair.key_name}"
# user data
user_data = "${data.template_cloudinit_config.cloudinit-example.rendered}"
provisioner "local-exec" {
command = "echo ${aws_instance.example.private_ip} >> abc.txt"
}
provisioner "file" {
source = "script.sh"
destination = "/tmp/script.sh"
}
provisioner "remote-exec" {
inline = [
"chmod +x /tmp/script.sh",
"sudo /tmp/script.sh"
]
}
connection {
user = "${var.INSTANCE_USERNAME}"
private_key = "${file("${var.PATH_TO_PRIVATE_KEY}")}"
}
}
output "ip" {
value = "${aws_instance.example.public_ip}"
}
resource "aws_ebs_volume" "ebs-volume-1" {
availability_zone = "eu-west-1a"
size = 20
type = "gp2"
tags {
Name = "extra volume data"
}
}
resource "aws_volume_attachment" "ebs-volume-1-attachment" {
device_name = "${var.INSTANCE_DEVICE_NAME}"
volume_id = "${aws_ebs_volume.ebs-volume-1.id}"
instance_id = "${aws_instance.example.id}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment