2014-07-24 05:34:59 +02:00
---
layout: "aws"
page_title: "AWS: aws_db_instance"
sidebar_current: "docs-aws-resource-db-instance"
2014-10-22 05:21:56 +02:00
description: |-
Provides an RDS instance resource.
2014-07-24 05:34:59 +02:00
---
# aws\_db\_instance
2016-01-14 21:55:39 +01:00
Provides an RDS instance resource. A DB instance is an isolated database
environment in the cloud. A DB instance can contain multiple user-created
databases.
2015-12-18 18:22:21 +01:00
Changes to a DB instance can occur when you manually change a
parameter, such as `allocated_storage` , and are reflected in the next maintenance
2016-08-11 18:32:54 +02:00
window. Because of this, Terraform may report a difference in its planning
2015-12-18 18:22:21 +01:00
phase because a modification has not yet taken place. You can use the
2016-01-14 21:55:39 +01:00
`apply_immediately` flag to instruct the service to apply the change immediately
(see documentation below).
2015-12-18 18:22:21 +01:00
2016-01-14 21:55:39 +01:00
~> **Note:** using `apply_immediately` can result in a
brief downtime as the server reboots. See the AWS Docs on [RDS Maintenance][2]
2015-12-18 18:22:21 +01:00
for more information.
2014-07-24 05:34:59 +02:00
## Example Usage
```
resource "aws_db_instance" "default" {
2016-03-18 21:15:30 +01:00
allocated_storage = 10
engine = "mysql"
engine_version = "5.6.17"
instance_class = "db.t1.micro"
name = "mydb"
username = "foo"
password = "bar"
db_subnet_group_name = "my_database_subnet_group"
parameter_group_name = "default.mysql5.6"
2014-07-24 05:34:59 +02:00
}
```
## Argument Reference
2015-06-15 18:07:01 +02:00
For more detailed documentation about each argument, refer to
2016-01-14 21:55:39 +01:00
the [AWS official documentation ](https://docs.aws.amazon.com/AmazonRDS/latest/CommandLineReference/CLIReference-cmd-ModifyDBInstance.html ).
2015-05-26 01:14:27 +02:00
2014-07-24 05:34:59 +02:00
The following arguments are supported:
2015-09-09 14:06:53 +02:00
* `allocated_storage` - (Required unless a `snapshot_identifier` or `replicate_source_db` is provided) The allocated storage in gigabytes.
* `engine` - (Required unless a `snapshot_identifier` or `replicate_source_db` is provided) The database engine to use.
2015-11-04 00:57:51 +01:00
* `engine_version` - (Optional) The engine version to use.
2016-03-18 21:15:30 +01:00
* `identifier` - (Optional) The name of the RDS instance, if omitted, Terraform will assign a random, unique name
2014-07-24 05:34:59 +02:00
* `instance_class` - (Required) The instance type of the RDS instance.
2015-01-30 19:01:10 +01:00
* `storage_type` - (Optional) One of "standard" (magnetic), "gp2" (general
purpose SSD), or "io1" (provisioned IOPS SSD). The default is "io1" if
`iops` is specified, "standard" if not.
2015-01-28 17:48:30 +01:00
* `final_snapshot_identifier` - (Optional) The name of your final DB snapshot
when this DB instance is deleted. If omitted, no final snapshot will be
made.
2016-05-20 19:33:25 +02:00
* `skip_final_snapshot` - (Optional) Determines whether a final DB snapshot is created before the DB instance is deleted. If true is specified, no DBSnapshot is created. If false is specified, a DB snapshot is created before the DB instance is deleted, using the value from `final_snapshot_identifier` . Default is true.
2015-10-16 18:20:24 +02:00
* `copy_tags_to_snapshot` – (Optional, boolean) On delete, copy all Instance `tags` to
the final snapshot (if `final_snapshot_identifier` is specified). Default
`false`
2015-01-28 17:48:30 +01:00
* `name` - (Optional) The DB name to create. If omitted, no database is created
initially.
2015-09-09 14:06:53 +02:00
* `password` - (Required unless a `snapshot_identifier` or `replicate_source_db` is provided) Password for the master DB user. Note that this may
2015-01-28 17:48:30 +01:00
show up in logs, and it will be stored in the state file.
2015-09-09 14:06:53 +02:00
* `username` - (Required unless a `snapshot_identifier` or `replicate_source_db` is provided) Username for the master DB user.
2014-07-24 05:34:59 +02:00
* `availability_zone` - (Optional) The AZ for the RDS instance.
2015-05-13 18:21:06 +02:00
* `backup_retention_period` - (Optional) The days to retain backups for. Must be
2015-05-21 16:49:46 +02:00
`1` or greater to be a source for a [Read Replica][1].
2014-07-24 05:34:59 +02:00
* `backup_window` - (Optional) The backup window.
2015-01-30 19:01:10 +01:00
* `iops` - (Optional) The amount of provisioned IOPS. Setting this implies a
storage_type of "io1".
2014-07-29 08:51:24 +02:00
* `maintenance_window` - (Optional) The window to perform maintenance in.
2015-05-25 17:09:32 +02:00
Syntax: "ddd:hh24:mi-ddd:hh24:mi". Eg: "Mon:00:00-Mon:03:00".
2016-01-14 21:55:39 +01:00
See [RDS Maintenance Window docs ](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/AdjustingTheMaintenanceWindow.html ) for more.
2014-07-24 05:34:59 +02:00
* `multi_az` - (Optional) Specifies if the RDS instance is multi-AZ
2014-07-29 08:51:24 +02:00
* `port` - (Optional) The port on which the DB accepts connections.
2016-06-10 23:55:36 +02:00
* `publicly_accessible` - (Optional) Bool to control if instance is publicly accessible. Defaults to `false` .
2015-01-14 18:28:25 +01:00
* `vpc_security_group_ids` - (Optional) List of VPC security groups to associate.
2015-02-23 22:22:52 +01:00
* `security_group_names` - (Optional/Deprecated) List of DB Security Groups to associate.
2016-01-14 21:55:39 +01:00
Only used for [DB Instances on the _EC2-Classic_ Platform ](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_VPC.html#USER_VPC.FindDefaultVPC ).
2015-09-08 15:10:54 +02:00
* `db_subnet_group_name` - (Optional) Name of DB subnet group. DB instance will be created in the VPC associated with the DB subnet group. If unspecified, will be created in the `default` VPC, or in EC2 Classic, if available.
2014-10-22 23:22:30 +02:00
* `parameter_group_name` - (Optional) Name of the DB parameter group to associate.
2016-06-24 10:15:01 +02:00
* `option_group_name` - (Optional) Name of the DB option group to associate.
2015-04-03 21:19:41 +02:00
* `storage_encrypted` - (Optional) Specifies whether the DB instance is encrypted. The default is `false` if not specified.
* `apply_immediately` - (Optional) Specifies whether any database modifications
2015-03-31 16:41:37 +02:00
are applied immediately, or during the next maintenance window. Default is
2016-01-14 21:55:39 +01:00
`false` . See [Amazon RDS Documentation for more information. ](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.DBInstance.Modifying.html )
2015-05-21 22:06:22 +02:00
* `replicate_source_db` - (Optional) Specifies that this resource is a Replicate
2015-05-13 18:21:06 +02:00
database, and to use this value as the source database. This correlates to the
`identifier` of another Amazon RDS Database to replicate. See
[DB Instance Replication][1] and
2016-01-14 21:55:39 +01:00
[Working with PostgreSQL and MySQL Read Replicas ](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ReadRepl.html ) for
2015-05-13 18:21:06 +02:00
more information on using Replication.
2015-06-30 22:33:13 +02:00
* `snapshot_identifier` - (Optional) Specifies whether or not to create this database from a snapshot. This correlates to the snapshot ID you'd find in the RDS console, e.g: rds:production-2015-06-26-06-05.
2015-11-09 15:59:09 +01:00
* `license_model` - (Optional, but required for some DB engines, i.e. Oracle SE1) License model information for this DB instance.
2015-12-08 15:13:26 +01:00
* `auto_minor_version_upgrade` - (Optional) Indicates that minor engine upgrades will be applied automatically to the DB instance during the maintenance window. Defaults to true.
2015-12-30 08:58:23 +01:00
* `allow_major_version_upgrade` - (Optional) Indicates that major version upgrades are allowed. Changing this parameter does not result in an outage and the change is asynchronously applied as soon as possible.
2016-06-02 19:06:37 +02:00
* `monitoring_role_arn` - (Optional) The ARN for the IAM role that permits RDS to send
enhanced monitoring metrics to CloudWatch Logs. You can find more information on the [AWS Documentation ](http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_Monitoring.html )
2016-02-01 23:32:38 +01:00
what IAM permissions are needed to allow Enhanced Monitoring for RDS Instances.
* `monitoring_interval` - (Optional) The interval, in seconds, between points when Enhanced Monitoring metrics are collected for the DB instance. To disable collecting Enhanced Monitoring metrics, specify 0. The default is 0. Valid Values: 0, 1, 5, 10, 15, 30, 60.
2016-06-02 19:06:37 +02:00
* `kms_key_id` - (Optional) The ARN for the KMS encryption key.
2016-01-27 21:20:18 +01:00
* `character_set_name` - (Optional) The character set name to use for DB encoding in Oracle instances. This can't be changed.
2016-01-27 18:39:00 +01:00
[Oracle Character Sets Supported in Amazon RDS ](http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Appendix.OracleCharacterSets.html )
2016-03-17 00:20:40 +01:00
* `tags` - (Optional) A mapping of tags to assign to the resource.
2015-05-13 18:21:06 +02:00
2015-05-21 22:06:22 +02:00
~> **NOTE:** Removing the `replicate_source_db` attribute from an existing RDS
2015-05-13 18:21:06 +02:00
Replicate database managed by Terraform will promote the database to a fully
standalone database.
2014-07-24 05:34:59 +02:00
## Attributes Reference
The following attributes are exported:
* `id` - The RDS instance ID.
* `address` - The address of the RDS instance.
2015-12-08 17:52:17 +01:00
* `arn` - The ARN of the RDS instance.
2014-07-24 05:34:59 +02:00
* `allocated_storage` - The amount of allocated storage
* `availability_zone` - The availability zone of the instance
* `backup_retention_period` - The backup retention period
* `backup_window` - The backup window
* `endpoint` - The connection endpoint
* `engine` - The database engine
* `engine_version` - The database engine version
* `instance_class` - The RDS instance class
* `maintenance_window` - The instance maintenance window
* `multi_az` - If the RDS instance is multi AZ enabled
* `name` - The database name
* `port` - The database port
* `status` - The RDS instance status
* `username` - The master username for the database
2015-03-11 19:37:56 +01:00
* `storage_encrypted` - Specifies whether the DB instance is encrypted
2014-07-24 05:34:59 +02:00
2016-01-27 18:39:00 +01:00
On Oracle instances the following is exported additionally:
* `character_set_name` - The character set used on Oracle instances.
2016-01-14 21:55:39 +01:00
[1]: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.Replication.html
[2]: https://docs.aws.amazon.com/fr_fr/AmazonRDS/latest/UserGuide/USER_UpgradeDBInstance.Maintenance.html
2016-07-21 00:28:59 +02:00
## Import
DB Instances can be imported using the `identifier` , e.g.
```
$ terraform import aws_db_instance.default mydb-rds-instance
2016-08-11 18:32:54 +02:00
```