Skip to content

Instantly share code, notes, and snippets.

@rahulwa
Created January 16, 2020 09:14
Show Gist options
  • Select an option

  • Save rahulwa/33f5d85d3cfd23613046d6d9677fe893 to your computer and use it in GitHub Desktop.

Select an option

Save rahulwa/33f5d85d3cfd23613046d6d9677fe893 to your computer and use it in GitHub Desktop.
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"] # Canonical
}
resource "aws_instance" "ec2_server" {
ami = "${data.aws_ami.ubuntu.id}"
instance_type = "${var.instance_type}"
iam_instance_profile = "${aws_iam_instance_profile.monitoring-server.name}"
key_name = "xxxx"
disable_api_termination = "true"
vpc_security_group_ids = "${var.security_group_ids}"
subnet_id = "${var.private_subnets_id}"
associate_public_ip_address = "false"
root_block_device = [{
volume_type = "gp2"
volume_size = 50
delete_on_termination = true
}]
volume_tags = "${var.tags}"
tags = "${var.tags}"
provisioner "remote-exec" {
inline = ["sudo apt update"]
connection {
type = "ssh"
user = "ubuntu"
agent = true
}
}
provisioner "local-exec" {
command = "ansible-playbook -u ubuntu -i '${self.private_ip},' -e aws_region=${var.aws_region} -e dns=${var.dns} -e grafana_admin_password=${var.grafana_admin_password} -e efs_mount_domain=${aws_efs_mount_target.prometheus.dns_name} playbook.yml"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment