Giter VIP home page Giter VIP logo

terraform-aws-postgresql-rds's Introduction

terraform-aws-postgresql-rds

CircleCI

A Terraform module to create an Amazon Web Services (AWS) PostgreSQL Relational Database Server (RDS).

Usage

module "postgresql_rds" {
  source = "github.com/azavea/terraform-aws-postgresql-rds"
  vpc_id = "vpc-20f74844"
  allocated_storage = "32"
  engine_version = "9.4.4"
  instance_type = "db.t2.micro"
  storage_type = "gp2"
  database_identifier = "jl23kj32sdf"
  database_name = "hector"
  database_username = "hector"
  database_password = "secret"
  database_port = "5432"
  backup_retention_period = "30"
  backup_window = "04:00-04:30"
  maintenance_window = "sun:04:30-sun:05:30"
  auto_minor_version_upgrade = false
  multi_availability_zone = true
  storage_encrypted = false
  subnet_group = aws_db_subnet_group.default.name
  parameter_group = aws_db_parameter_group.default.name
  monitoring_interval = "60"
  deletion_protection = true
  cloudwatch_logs_exports = ["postgresql"]

  alarm_cpu_threshold = "75"
  alarm_disk_queue_threshold = "10"
  alarm_free_disk_threshold = "5000000000"
  alarm_free_memory_threshold = "128000000"
  alarm_actions = ["arn:aws:sns..."]
  ok_actions = ["arn:aws:sns..."]
  insufficient_data_actions = ["arn:aws:sns..."]

  project = "Something"
  environment = "Staging"
}

Note about Enhanced Monitoring support

If the monitoring_interval passed as an input to this module is 0, an empty monitoring_role_arn value will be passed to the aws_db_instance resource.

This is because, if a value for monitoring_role_arn is passed to an aws_db_instance, along with a monitoring_interval of 0, the following error will occur:

InvalidParameterCombination: You must specify a MonitoringInterval value other than 0 when you specify a MonitoringRoleARN value.

If you're curious to know more, see the discussion within hashicorp/terraform-provider-aws#315.

Variables

  • vpc_id - ID of VPC meant to house database
  • project - Name of project this VPC is meant to house (default: Unknown)
  • environment - Name of environment this VPC is targeting (default: Unknown)
  • allocated_storage - Storage allocated to database instance (default: 32)
  • engine_version - Database engine version (default: 11.5)
  • instance_type - Instance type for database instance (default: db.t3.micro)
  • storage_type - Type of underlying storage for database (default: gp2)
  • iops - The amount of provisioned IOPS. Setting this implies a storage_type of io1 (default: 0)
  • database_identifier - Identifier for RDS instance
  • snapshot_identifier - The name of the snapshot (if any) the database should be created from
  • database_name - Name of database inside storage engine
  • database_username - Name of user inside storage engine
  • database_password - Database password inside storage engine
  • database_port - Port on which database will accept connections (default 5432)
  • backup_retention_period - Number of days to keep database backups (default: 30)
  • backup_window - 30 minute time window to reserve for backups (default: 04:00-04:30)
  • maintenance_window - 60 minute time window to reserve for maintenance (default: sun:04:30-sun:05:30)
  • auto_minor_version_upgrade - Minor engine upgrades are applied automatically to the DB instance during the maintenance window (default: true)
  • final_snapshot_identifier - Identifier for final snapshot if skip_final_snapshot is set to false (default: terraform-aws-postgresql-rds-snapshot)
  • skip_final_snapshot - Flag to enable or disable a snapshot if the database instance is terminated (default: true)
  • copy_tags_to_snapshot - Flag to enable or disable copying instance tags to the final snapshot (default: false)
  • multi_availability_zone - Flag to enable hot standby in another availability zone (default: false)
  • storage_encrypted - Flag to enable storage encryption (default: false)
  • monitoring_interval - The interval, in seconds, between points when Enhanced Monitoring metrics are collected (default: 0)
  • deletion_protection - Flag to protect the database instance from deletion (default: false)
  • cloudwatch_logs_exports - List of logs to publish to CloudWatch Logs. See all available options. (default: ["postgresql, "upgrade"])
  • subnet_group - Database subnet group
  • parameter_group - Database engine parameter group (default: default.postgres11)
  • alarm_cpu_threshold - CPU alarm threshold as a percentage (default: 75)
  • alarm_disk_queue_threshold - Disk queue alarm threshold (default: 10)
  • alarm_free_disk_threshold - Free disk alarm threshold in bytes (default: 5000000000)
  • alarm_free_memory_threshold - Free memory alarm threshold in bytes (default: 128000000)
  • alarm_cpu_credit_balance_threshold - CPU credit balance threshold (default: 30). Only used for db.t* instance types
  • alarm_actions - List of ARNs to be notified via CloudWatch when alarm enters ALARM state
  • ok_actions - List of ARNs to be notified via CloudWatch when alarm enters OK state
  • insufficient_data_actions - List of ARNs to be notified via CloudWatch when alarm enters INSUFFICIENT_DATA state
  • tags - Extra tags to attach to the RDS resources (default: {})

Outputs

  • id - The database instance ID
  • database_security_group_id - Security group ID of the database
  • hosted_zone_id - The zone id for the autogenerated DNS name given in endpoint.
  • hostname - Public DNS name of database instance
  • port - Port of database instance
  • endpoint - Public DNS name and port separated by a colon Use this when creating a short-name DNS alias for the endpoint

terraform-aws-postgresql-rds's People

Contributors

dagvl avatar hectcastro avatar jeekajoo avatar olvesh avatar rbreslow avatar sharph avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terraform-aws-postgresql-rds's Issues

aws-RDS-next proposed changes

  • Enable Performance Insights by default
  • Stop supporting unencrypted storage. Generally the performance impact should be negligible.
  • Remove "Enhanced Monitoring" support - it's marginally more expensive but just provides used space (in enhanced) vs free space (in normal). Our implementation is also not great.
  • Default to not exporting logs to cloudwatch (in DB they just charge a large extra charge and you can view logs in DB directly). - Or remove this capability.

Review our projects and see what settings they are actually using.

add existing security group

could we add an input variable that allows us to use an existing security group instead of redefining a new one as mentioned in #15 ?

InvalidParameterCombination when upgrading from 2.5.0 to 2.6.0

A project was successfully using 2.5.0 of this module. An attempt to upgrade it to 2.6.0 caused the following exception:

* aws_db_instance.postgresql: Error modifying DB Instance dbtest: InvalidParameterCombination: A MonitoringRoleARN value is required if you specify a MonitoringInterval value other than 0.
        status code: 400, request id: 5afb5277-7312-4f52-8628-3ec71b8eeafb

This was triggered with monitoring_interval = 60. If monitoring_interval = 0, then the error does not surface.

Consider how to integrate with default_tags

Copied from azavea/terraform-aws-vpc#29.

Version 3.38.0 of the Terraform AWS Provider introduced a way to define a default set of tags that propagate to all AWS resources that support tags.

Any tags defined at the resource level are merged with tags defined at the provider level and are accessible via a new read-only attribute, tags_all.

e.g.:

# module.vpc.aws_vpc.default will be created
+ resource "aws_vpc" "default" {
    + arn                              = (known after apply)
    + assign_generated_ipv6_cidr_block = false
    + cidr_block                       = "10.0.0.0/16"
    + default_network_acl_id           = (known after apply)
    + default_route_table_id           = (known after apply)
    + default_security_group_id        = (known after apply)
    + dhcp_options_id                  = (known after apply)
    + enable_classiclink               = (known after apply)
    + enable_classiclink_dns_support   = (known after apply)
    + enable_dns_hostnames             = true
    + enable_dns_support               = true
    + id                               = (known after apply)
    + instance_tenancy                 = "default"
    + ipv6_association_id              = (known after apply)
    + ipv6_cidr_block                  = (known after apply)
    + main_route_table_id              = (known after apply)
    + owner_id                         = (known after apply)
    + tags                             = {
        + "Environment" = "Staging"
        + "Name"        = "vpcStaging"
        + "Project"     = "Something"
      }
    + tags_all                         = {
        + "Environment" = "Staging"
        + "Name"        = "vpcStaging"
        + "Project"     = "Something"
      }
  }

I think we should consider how we'd drop the Environment and Project tags and instructs folks to use default_tags.

Add support for provisioned IOPS storage (io1)

We already allow users to override the aws_db_instance.storage_type via the module's storage_type variable, but in order to fully support setting storage_type to io1, we need to add an iops variable to set the specific number of IOPS for the volume.

Add support for database instance deletion protection

The underlying aws_db_instance resource has support for deletion protection, which prevents the RDS instance from being deleted if enabled. We should surface this setting at the model level so that it can be modified to something other than its default value (false).

Add parameterized security groups

In #14, we created an empty default security group in order to give users the flexibility to define their own firewall rules. However, it would be useful to have some base rules that allows ingress/egress traffic on the database port, which can be a user-supplied parameter. We can then continue to output the security group id for further customization at the user's discretion.

You must specify a MonitoringInterval value other than 0 when you specify a MonitoringRoleARN value

It looks like the default functionality of this module is to specify a value for monitoring_role_arn on the aws_db_instance resource, and set the monitoring_interval to 0.

According to this Terraform error I received, the default functionality of this module may be broken:

Error: Error applying plan:

1 error(s) occurred:

* module.database.aws_db_instance.postgresql: 1 error(s) occurred:

* aws_db_instance.postgresql: Error creating DB Instance: InvalidParameterCombination: You must specify a MonitoringInterval value other than 0 when you specify a MonitoringRoleARN value.
	status code: 400, request id: d996bf5a-c269-4548-87ec-6b3676b7a9aa

Consider parameterizing allow_major_version_upgrade

If you try to upgrade the major version of a DB instance via Terraform, the apply operation will fail like:

Error: Error modifying DB Instance districtbuilder-staging: InvalidParameterCombination: The AllowMajorVersionUpgrade flag must be present when upgrading to a new major version.
        status code: 400, request id: 299dedfe-4b1e-4746-8b2a-5c562d9f8c89

The AWS docs don't rule out the possibility of modifying the DB engine via Terraform:

For major version upgrades, you must manually modify the DB engine version through the AWS Management Console, AWS CLI, or RDS API. For minor version upgrades, you can manually modify the engine version, or you can choose to enable auto minor version upgrades.

Paired with the use of name_prefix for the DB parameter group (PublicMapping/districtbuilder#478), we could have Terraform perform an entire major version upgrade. This would eliminate the need for us to ensure a parameter group exists and thread it through between version hops, freeing up more mental bandwidth for monitoring the upgrade process.

I could see us leaving this variable set to false when business is usual, but we set it to true when performing the upgrade.

See: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_instance#allow_major_version_upgrade

Make compatible with Terraform 0.12

This module isn't currently compatible with Terraform 0.12. The tags blocks and dimensions blocks in main.tf need to be explicitly defined as arguments with = {. The 0.12 upgrade guide explains why this version is more strict about the syntax.

We can also use new syntax for referencing expressions without quotes.

This could possibly be resolved with terraform 0.12upgrade. It would require a major version bump since the module would now require Terraform >= 0.12.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.