rds.tf 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 = var.private_subnets
  12. }
  13. # yeah, I alphabatized it. Don't you alphabatized your config files?
  14. resource "aws_db_instance" "postgres" {
  15. allocated_storage = 20
  16. apply_immediately = "true"
  17. auto_minor_version_upgrade = "true"
  18. db_subnet_group_name = aws_db_subnet_group.customer_portal_rds_subnets.name
  19. backup_window = "03:00-06:00"
  20. backup_retention_period = 7
  21. ca_cert_identifier = "rds-ca-rsa4096-g1"
  22. deletion_protection = var.environment == "test" ? "false" : "true"
  23. delete_automated_backups = "true"
  24. engine = "postgres"
  25. engine_version = var.environment == "test" ? "12" : "12.8"
  26. final_snapshot_identifier = "customerportal"
  27. instance_class = "db.t2.small"
  28. identifier = "customerportal"
  29. kms_key_id = aws_kms_key.customer_portal_kms.arn
  30. maintenance_window = "Mon:00:00-Mon:03:00"
  31. db_name = "customerportal"
  32. password = var.environment == "test" ? "foobarbaz" : "050ff734-fb33-9248-13e4-7d8ad2e899a0"
  33. port = 5432
  34. skip_final_snapshot = var.environment == "test" ? "true" : "false"
  35. storage_type = "gp2"
  36. storage_encrypted = "true"
  37. tags = merge(local.standard_tags, var.tags)
  38. username = "portal"
  39. vpc_security_group_ids = [aws_security_group.postgres.id, ]
  40. }
  41. #------------------------------------
  42. # Security Groups
  43. #------------------------------------
  44. resource "aws_security_group" "postgres" {
  45. name = "customer_portal_postgres_inbound_sg"
  46. description = "Allow Customer Portal HTTP Traffic Inbound"
  47. vpc_id = var.vpc_id
  48. }
  49. resource "aws_security_group_rule" "customer_portal_postgres_inbound" {
  50. security_group_id = aws_security_group.postgres.id
  51. type = "ingress"
  52. from_port = 5432
  53. to_port = 5432
  54. protocol = "tcp"
  55. cidr_blocks = ["10.0.0.0/8"]
  56. }