resource "aws_security_group" "allow_rds-sg" {
name = "allow_rds-sg"
description = "Allow rds-sg inbound traffic"
vpc_id = aws_vpc.vpc-10-10-0-0.id
ingress {
description = "rds from VPC"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
tags = {
Name = "allow_rds"
}
}
resource "aws_db_instance" "test_rds" {
allocated_storage = 50
storage_type = "gp2"
engine = "mysql"
engine_version = "5.7.21"
instance_class = "db.t2.micro"
identifier = "tf-db"
name = "dbtest"
username = "admin"
password = "It12345!"
db_subnet_group_name = aws_db_subnet_group.tf-rdsg.id
vpc_security_group_ids = [aws_security_group.allow_rds-sg.id]
backup_retention_period = 0
skip_final_snapshot = true
apply_immediately = true
tags = {
"name" = "dbtest"
}
}
resource "aws_db_subnet_group" "tf-rdsg" {
name = "tf-rdsg"
subnet_ids = [aws_subnet.sub-pri5-10-10-7-0.id, aws_subnet.sub-pri6-10-10-8-0.id]
}
- identifier을 작성해야 DB 생성시 이름이 자동으로 설정되지 않는다.
728x90
'Cloud > Terraform' 카테고리의 다른 글
Terraform - 7/15 (0) | 2022.07.15 |
---|---|
Terraform - 07/14 (0) | 2022.07.14 |
Terraform - Auto Scaling Tracking Policy 생성 및 Load Test로 Auto Scaling 테스트 (0) | 2022.07.10 |
Terraform - Auto Scaling Attachment 생성 (0) | 2022.07.10 |
Terraform - Launch Configuration과 Auto Scaling Group 구성 및 작동 확인 (0) | 2022.07.10 |