Cloud/Terraform

Terraform - RDS 생성

잇(IT) 2022. 7. 14. 09:38
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