Created
August 19, 2019 11:01
-
-
Save afcastano/2ab13e1db142e23c672473f535d179c9 to your computer and use it in GitHub Desktop.
AWS WP Servers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# WP SERVERS ############################ | |
resource "aws_instance" "wp" { | |
ami = "${data.aws_ami.ubuntu.id}" | |
vpc_security_group_ids = [ | |
"${aws_security_group.wp.id}" | |
] | |
instance_type = "${var.aws_instance_type}" | |
subnet_id = "${aws_subnet.wp_subnet.id}" | |
key_name = "${aws_key_pair.demo_keys.key_name}" | |
tags { | |
Name = "wp-server-${count.index}" | |
SELECTOR = "wp" | |
} | |
count = 2 | |
} | |
# I would initialize the vm via user_data attribute, but velostrata does not like it. | |
# https://stackoverflow.com/questions/57016394/velostrata-migration-from-aws-to-gcp-failed-cloud-instance-boot-failed | |
resource "null_resource" "wp_provisioner" { | |
triggers = { | |
wp_instace = "${element(aws_instance.wp.*.private_ip, count.index)}" | |
} | |
provisioner "file" { | |
source = "scripts/init_velostrata.sh" | |
destination = "/tmp/init_velostrata.sh" | |
} | |
provisioner "file" { | |
source = "scripts/init_wp.sh" | |
destination = "/tmp/init_wp.sh" | |
} | |
provisioner "remote-exec" { | |
inline = [ | |
"chmod +x /tmp/init_velostrata.sh", | |
"chmod +x /tmp/init_wp.sh", | |
"/tmp/init_velostrata.sh", | |
"/tmp/init_wp.sh ${aws_db_instance.wp-db.address} ${var.aws_wp_db_user} ${var.aws_wp_db_password}", | |
] | |
} | |
connection { | |
type = "ssh" | |
private_key = "${tls_private_key.demo_private_key.private_key_pem}" | |
host = "${element(aws_instance.wp.*.private_ip, count.index)}" | |
user = "ubuntu" | |
bastion_host = "${aws_eip.bastion_eip.public_ip}" | |
bastion_private_key = "${tls_private_key.demo_private_key.private_key_pem}" | |
bastion_user = "ubuntu" | |
timeout = "30s" | |
} | |
depends_on = ["aws_eip_association.bastion_eip_assoc", "aws_instance.wp"] | |
count = 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment