rds.tf 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #------------------------------------
  2. # RDS Cluster
  3. #------------------------------------
  4. resource "aws_kms_key" "customer_portal_kms" {
  5. description = "RDS KMS Key"
  6. enable_key_rotation = true
  7. }
  8. resource "aws_db_subnet_group" "customer_portal_rds_subnets" {
  9. name = "customer_portal_rds_subnets"
  10. description = "Customer Portal RDS Private subnet"
  11. subnet_ids = [ element(var.subnets,0), element(var.subnets,1), element(var.subnets,2) ]
  12. }
  13. resource "aws_db_instance" "postgres" {
  14. allocated_storage = 20
  15. storage_type = "gp2"
  16. engine = "postgres"
  17. db_subnet_group_name = aws_db_subnet_group.customer_portal_rds_subnets.name
  18. vpc_security_group_ids = [ aws_security_group.postgres.id, ]
  19. instance_class = "db.t2.small"
  20. identifier = "customerportal"
  21. name = "customerportal"
  22. username = "portal"
  23. password = "foobarbaz"
  24. kms_key_id = aws_kms_key.customer_portal_kms.arn
  25. storage_encrypted = "true"
  26. ca_cert_identifier = "rds-ca-2017"
  27. }
  28. #------------------------------------
  29. # Security Groups
  30. #------------------------------------
  31. resource "aws_security_group" "postgres" {
  32. name = "customer_portal_postgres_inbound_sg"
  33. description = "Allow Customer Portal HTTP Traffic Inbound"
  34. vpc_id = var.vpc_id
  35. }
  36. resource "aws_security_group_rule" "customer_portal_postgres_inbound" {
  37. security_group_id = aws_security_group.postgres.id
  38. type = "ingress"
  39. from_port = 5432
  40. to_port = 5432
  41. protocol = "tcp"
  42. cidr_blocks = ["10.0.0.0/8"]
  43. }