main.tf 1.8 KB

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