main.tf 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. data "aws_rds_certificate" "latest" {
  2. latest_valid_till = true
  3. id = "rds-ca-rsa4096-g1"
  4. }
  5. locals {
  6. # GovCloud and Commercial use different CA certs
  7. ca_cert_identifier = var.aws_partition == "aws" ? "rds-ca-2019" : "rds-ca-rsa4096-g1"
  8. }
  9. output "ca_cert_identifier" {
  10. value = {
  11. "current" : local.ca_cert_identifier,
  12. "latest" : data.aws_rds_certificate.latest.id
  13. }
  14. }
  15. module "jira_db" {
  16. source = "terraform-aws-modules/rds/aws"
  17. version = "v4.2.0"
  18. identifier = var.identifier # this is the RDS identifier, not the DB name
  19. db_name = "jira" # the DB name
  20. engine = "postgres"
  21. auto_minor_version_upgrade = true
  22. allow_major_version_upgrade = false
  23. # The three of these must be consistent
  24. engine_version = var.environment == "test" ? "12" : "12.8" # If you do not specify the minor version, it uses the latest. If you do specify
  25. # the minor version, turn off auto_minor_version_upgrade.
  26. family = "postgres12" # DB parameter group
  27. major_engine_version = "12" # DB option group
  28. instance_class = var.instance_type
  29. allocated_storage = var.jira_rds_storage
  30. storage_encrypted = true
  31. kms_key_id = module.jira_key.key_arn
  32. ca_cert_identifier = local.ca_cert_identifier
  33. # NOTE: Do NOT use 'user' as the value for 'username' as it throws:
  34. # "Error creating DB Instance: InvalidParameterValue: MasterUsername
  35. # user cannot be used as it is a reserved word used by the engine"
  36. username = "jira"
  37. password = "YourPwdShouldBeLongAndSecure!"
  38. port = "5432"
  39. vpc_security_group_ids = [aws_security_group.jira_rds_sg.id]
  40. backup_window = "00:00-03:00"
  41. maintenance_window = "Mon:03:00-Mon:06:00"
  42. # Backup retention is from 0 to 35
  43. backup_retention_period = var.environment == "test" ? 0 : 35
  44. tags = merge(var.standard_tags, var.tags)
  45. enabled_cloudwatch_logs_exports = ["postgresql", "upgrade"]
  46. # DB subnet group
  47. subnet_ids = var.subnets
  48. create_db_subnet_group = true
  49. # Snapshot name upon DB deletion
  50. final_snapshot_identifier_prefix = "${var.identifier}-final-snapshot"
  51. # Database Deletion Protection
  52. deletion_protection = var.instance_termination_protection
  53. }