Resource: aws_lightsail_database

Provides a Lightsail Database. Amazon Lightsail is a service to provide easy virtual private servers with custom software already setup. See What is Amazon Lightsail? for more information.

Example Usage

Basic mysql blueprint

resource "aws_lightsail_database" "test" {
  relational_database_name = "test"
  availability_zone        = "us-east-1a"
  master_database_name     = "testdatabasename"
  master_password          = "testdatabasepassword"
  master_username          = "test"
  blueprint_id             = "mysql_8_0"
  bundle_id                = "micro_1_0"
}

Basic postrgres blueprint

resource "aws_lightsail_database" "test" {
  relational_database_name = "test"
  availability_zone        = "us-east-1a"
  master_database_name     = "testdatabasename"
  master_password          = "testdatabasepassword"
  master_username          = "test"
  blueprint_id             = "postgres_12"
  bundle_id                = "micro_1_0"
}

Custom backup and maintenance windows

Below is an example that sets a custom backup and maintenance window. Times are specified in UTC. This example will allow daily backups to take place between 16:00 and 16:30 each day. This example also requires any maintiance tasks (anything that would cause an outage, including changing some attributes) to take place on Tuesdays between 17:00 and 17:30. An action taken against this database that would cause an outage will wait until this time window to make the requested changes.

resource "aws_lightsail_database" "test" {
  relational_database_name     = "test"
  availability_zone            = "us-east-1a"
  master_database_name         = "testdatabasename"
  master_password              = "testdatabasepassword"
  master_username              = "test"
  blueprint_id                 = "postgres_12"
  bundle_id                    = "micro_1_0"
  preferred_backup_window      = "16:00-16:30"
  preferred_maintenance_window = "Tue:17:00-Tue:17:30"
}

Final Snapshots

To enable creating a final snapshot of your database on deletion, use the final_snapshot_name argument to provide a name to be used for the snapshot.

resource "aws_lightsail_database" "test" {
  relational_database_name     = "test"
  availability_zone            = "us-east-1a"
  master_database_name         = "testdatabasename"
  master_password              = "testdatabasepassword"
  master_username              = "test"
  blueprint_id                 = "postgres_12"
  bundle_id                    = "micro_1_0"
  preferred_backup_window      = "16:00-16:30"
  preferred_maintenance_window = "Tue:17:00-Tue:17:30"
  final_snapshot_name          = "MyFinalSnapshot"
}

Apply Immediately

To enable applying changes immediately instead of waiting for a maintiance window, use the apply_immediately argument.

resource "aws_lightsail_database" "test" {
  relational_database_name = "test"
  availability_zone        = "us-east-1a"
  master_database_name     = "testdatabasename"
  master_password          = "testdatabasepassword"
  master_username          = "test"
  blueprint_id             = "postgres_12"
  bundle_id                = "micro_1_0"
  apply_immediately        = true
}

Argument Reference

This resource supports the following arguments:

Blueprint Ids

A list of all available Lightsail Blueprints for Relational Databases the aws lightsail get-relational-database-blueprints aws cli command.

Examples

Prefix

A Blueprint ID starts with a prefix of the engine type.

Suffix

A Blueprint ID has a sufix of the engine version.

Bundles

A list of all available Lightsail Bundles for Relational Databases the aws lightsail get-relational-database-bundles aws cli command.

Examples

Prefix

A Bundle ID starts with one of the below size prefixes:

Infixes (Optional for HA Database)

A Bundle Id can have the following infix added in order to use the HA option of the selected bundle.

Suffix

A Bundle ID ends with one of the following suffix: 1_0

Attribute Reference

This resource exports the following attributes in addition to the arguments above:

Import

In Terraform v1.5.0 and later, use an import block to import Lightsail Databases using their name. For example:

import {
  to = aws_lightsail_database.foo
  id = "bar"
}

Using terraform import, import Lightsail Databases using their name. For example:

% terraform import aws_lightsail_database.foo 'bar'