- autoscaling_attachment 생성
# 19.autoattach.tf
resource "aws_autoscaling_attachment" "tf-asattach" {
autoscaling_group_name = aws_autoscaling_group.tf_atsg.id
lb_target_group_arn = aws_lb_target_group.tf-albtg.id
}
- Load Balancer에 이전에 생성한 auto scaling group를 attachment 시킨다.
- rds 생성
- sh 파일에 health.html 파일을 생성했기 때문에 albtg의 health check를 위한 path도 /health.html로 변경해주어야 한다.
# 20.rds.tf
resource "aws_db_instance" "tf-rds" {
allocated_storage = 20
storage_type = "gp2"
engine = "mysql"
engine_version = "8.0"
instance_class = "db.t2.micro"
name = "wordpress"
username = "root"
password = "It12345!"
parameter_group_name = "default.mysql8.0"
availability_zone = "ap-northeast-2a"
db_subnet_group_name = aws_db_subnet_group.tf-dbsg.id
vpc_security_group_ids = [aws_security_group.tf-sg.id]
skip_final_snapshot = true
tags = {
"Name" = "tf-rds"
}
}
resource "aws_db_subnet_group" "tf-dbsg" {
name = "tf-dbsg"
subnet_ids = [aws_subnet.tf-rds-a.id, aws_subnet.tf-rds-c.id]
}
- rds 생성
# install.sh
#! /bin/bash
sudo su -
yum install -y wget httpd
amazon-linux-extras enable php7.2
amazon-linux-extras enable lamp-mariadb10.2-php7.2
yum install -y php-cli php-pdo php-fpm php-json php-mysqlnd mariadb php
wget https://ko.wordpress.org/latest-ko_KR.tar.gz
tar xvfz latest-ko_KR.tar.gz
cp -a wordpress/* /var/www/html/
chown apache.apache /var/www/html/*
sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php/g' /etc/httpd/conf/httpd.conf
cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.ph
sed -i 's/database_name_here/wordpress/g' /var/www/html/wp-config.php
sed -i 's/username_here/root/g' /var/www/html/wp-config.php
sed -i 's/password_here/It12345!/g' /var/www/html/wp-config.php
sed -i 's/localhost/wordpress.cefhawigq64q.ap-northeast-2.rds.amazonaws.com/g' /var/www/html/wp-config.php
cat > /var/www/html/health.html << EOF
<html>
<body>
<h1>AWS_TERRAFORM_WEBSERVER</h1>
</body>
</html>
EOF
systemctl enable httpd
systemctl start httpd
- wordpress 생성을 위한 sh 파일
728x90
'Cloud > Terraform' 카테고리의 다른 글
Terraform - 07/19 (0) | 2022.07.19 |
---|---|
Terraform - 7/15 (0) | 2022.07.15 |
Terraform - 07/14 (0) | 2022.07.14 |
Terraform - RDS 생성 (0) | 2022.07.14 |
Terraform - Auto Scaling Tracking Policy 생성 및 Load Test로 Auto Scaling 테스트 (0) | 2022.07.10 |