Skip to content

Instantly share code, notes, and snippets.

@khushi20218
Created August 13, 2020 07:05
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 khushi20218/feb8ed5f38368d351ee99587e5dec485 to your computer and use it in GitHub Desktop.
Save khushi20218/feb8ed5f38368d351ee99587e5dec485 to your computer and use it in GitHub Desktop.
resource "aws_instance" "wordpress" {
ami = "ami-0732b62d310b80e97"
instance_type = "t2.micro"
subnet_id = aws_subnet.pub_subnet1.id
security_groups = [aws_security_group.tf_wp_sg.id]
key_name = "key1"
tags = {
Name = "wordpress"
}
}
resource "null_resource" "wp-sql-connection" {
depends_on = [
aws_instance.mysql
]
connection {
type = "ssh"
user = "ec2-user"
private_key = file("C:/Users/HP/Downloads/mykey.pem")
host = aws_instance.wordpress.public_ip
}
provisioner "remote-exec" {
inline = [
"sudo su <<END",
"yum install docker httpd -y",
"systemctl enable docker",
"systemctl start docker",
"docker pull wordpress:5.1.1-php7.3-apache",
"sleep 30",
"docker run -dit -e WORDPRESS_DB_HOST=${aws_instance.mysql.private_ip} -e WORDPRESS_DB_USER=wpuser -e WORDPRESS_DB_PASSWORD=wppass -e WORDPRESS_DB_NAME=wpdb -p 80:80 wordpress:5.1.1-php7.3-apache",
"END",
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment