CodexBloom - Programming Q&A Platform

Terraform Not Creating RDS Instance Due to 'DB Security Group Not Defined' scenarios

πŸ‘€ Views: 0 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-26
terraform aws rds HCL

I'm sure I'm missing something obvious here, but I'm building a feature where After trying multiple solutions online, I still can't figure this out..... I've looked through the documentation and I'm still confused about I'm trying to provision an RDS instance in AWS using Terraform, but I keep working with an behavior that states `behavior: db_security_group not defined`. I've defined my security group separately and am trying to reference it in my RDS resource, but it seems like Terraform need to find it. My Terraform version is 1.3.0, and I'm using the AWS provider version 4.0.0. Here’s the relevant part of my code: ```hcl resource "aws_security_group" "db_sg" { name = "db_security_group" description = "Allow access to the database" vpc_id = aws_vpc.main.id ingress { from_port = 5432 to_port = 5432 protocol = "tcp" cidr_blocks = ["10.0.0.0/16"] } } resource "aws_db_instance" "mydb" { identifier = "mydb" engine = "postgres" instance_class = "db.t3.micro" allocated_storage = 20 db_subnet_group_name = aws_db_subnet_group.mydb_subnet_group.name vpc_security_group_ids = [aws_security_group.db_sg.id] username = "admin" password = "P@ssw0rd" skip_final_snapshot = true } ``` I made sure the security group is created before the RDS instance, and I’ve also run `terraform plan` to double-check that everything is in order, but the behavior keeps popping up. I've tried reordering the resources and adding `depends_on`, but nothing seems to resolve the scenario. Any suggestions on how I can troubleshoot or fix this question? What's the best practice here? I'm working on a CLI tool that needs to handle this. Any help would be greatly appreciated! For context: I'm using Hcl on Windows. Has anyone else encountered this? For context: I'm using Hcl on Ubuntu 22.04. I'd love to hear your thoughts on this. This issue appeared after updating to Hcl LTS. Thanks, I really appreciate it! I've been using Hcl for about a year now. Am I missing something obvious? The project is a service built with Hcl.