Skip to content

Instantly share code, notes, and snippets.

@khushi20218
Created August 13, 2020 07:21
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/1e8b086a98ab0a40f9924940b434fd59 to your computer and use it in GitHub Desktop.
Save khushi20218/1e8b086a98ab0a40f9924940b434fd59 to your computer and use it in GitHub Desktop.
resource "aws_instance" "mysql" {
depends_on = [
aws_instance.wordpress
]
ami = "ami-0732b62d310b80e97"
instance_type = "t2.micro"
subnet_id = aws_subnet.pvt_subnet2.id
security_groups = [aws_security_group.tf_sql_sg.id]
key_name = "key1"
user_data = <<END
#!/bin/bash
sudo yum install mariadb-server mysql -y
sudo systemctl enable mariadb.service
sudo systemctl start mariadb.service
mysql -u root <<EOF
create user 'wpuser'@'${aws_instance.wordpress.private_ip}' identified by 'wppass';
create database wpdb;
grant all privileges on wpdb.* to 'wpuser'@'${aws_instance.wordpress.private_ip}';
exit
EOF
END
tags = {
Name = "sql"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment