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.
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"
}
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"
}
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"
}
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"
}
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
}
This resource supports the following arguments:
relational_database_name
- (Required) The name to use for your new Lightsail database resource. Names be unique within each AWS Region in your Lightsail account.availability_zone
- The Availability Zone in which to create your new database. Use the us-east-2a case-sensitive format.master_database_name
- (Required) The name of the master database created when the Lightsail database resource is created.master_password
- (Sensitive) The password for the master user of your new database. The password can include any printable ASCII character except "/", """, or "@".master_username
- The master user name for your new database.blueprint_id
- (Required) The blueprint ID for your new database. A blueprint describes the major engine version of a database. You can get a list of database blueprints IDs by using the AWS CLI command: aws lightsail get-relational-database-blueprints
bundle_id
- (Required) The bundle ID for your new database. A bundle describes the performance specifications for your database (see list below). You can get a list of database bundle IDs by using the AWS CLI command: aws lightsail get-relational-database-bundles
.preferred_backup_window
- The daily time range during which automated backups are created for your new database if automated backups are enabled. Must be in the hh24:mi-hh24:mi format. Example: 16:00-16:30
. Specified in Coordinated Universal Time (UTC).preferred_maintenance_window
- The weekly time range during which system maintenance can occur on your new database. Must be in the ddd:hh24:mi-ddd:hh24:mi format. Specified in Coordinated Universal Time (UTC). Example: Tue:17:00-Tue:17:30
publicly_accessible
- Specifies the accessibility options for your new database. A value of true specifies a database that is available to resources outside of your Lightsail account. A value of false specifies a database that is available only to your Lightsail resources in the same region as your database.apply_immediately
- When true , applies changes immediately. When false , applies changes during the preferred maintenance window. Some changes may cause an outage.backup_retention_enabled
- When true, enables automated backup retention for your database. When false, disables automated backup retention for your database. Disabling backup retention deletes all automated database backups. Before disabling this, you may want to create a snapshot of your database.skip_final_snapshot
- Determines whether a final database snapshot is created before your database is deleted. If true is specified, no database snapshot is created. If false is specified, a database snapshot is created before your database is deleted. You must specify the final relational database snapshot name parameter if the skip final snapshot parameter is false.final_snapshot_name
- (Required unless skip_final_snapshot = true
) The name of the database snapshot created if skip final snapshot is false, which is the default value for that parameter.tags
- (Optional) A map of tags to assign to the resource. To create a key-only tag, use an empty string as the value.A list of all available Lightsail Blueprints for Relational Databases the aws lightsail get-relational-database-blueprints aws cli command.
mysql_8_0
postgres_12
A Blueprint ID starts with a prefix of the engine type.
A Blueprint ID has a sufix of the engine version.
A list of all available Lightsail Bundles for Relational Databases the aws lightsail get-relational-database-bundles aws cli command.
small_1_0
small_ha_1_0
large_1_0
large_ha_1_0
A Bundle ID starts with one of the below size prefixes:
micro_
small_
medium_
large_
A Bundle Id can have the following infix added in order to use the HA option of the selected bundle.
ha_
A Bundle ID ends with one of the following suffix: 1_0
This resource exports the following attributes in addition to the arguments above:
id
- The ARN of the Lightsail instance (matches arn
).arn
- The ARN of the Lightsail instance (matches id
).ca_certificate_identifier
- The certificate associated with the database.created_at
- The timestamp when the instance was created.engine
- The database software (for example, MySQL).engine_version
- The database engine version (for example, 5.7.23).cpu_count
- The number of vCPUs for the database.ram_size
- The amount of RAM in GB for the database.disk_size
- The size of the disk for the database.master_endpoint_port
- The master endpoint network port for the database.master_endpoint_address
- The master endpoint fqdn for the database.secondary_availability_zone
- Describes the secondary Availability Zone of a high availability database. The secondary database is used for failover support of a high availability database.support_code
- The support code for the database. Include this code in your email to support when you have questions about a database in Lightsail. This code enables our support team to look up your Lightsail information more easily.tags_all
- A map of tags assigned to the resource, including those inherited from the provider default_tags
configuration block.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'