github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/website/source/docs/providers/aws/r/db_instance.html.markdown (about) 1 --- 2 layout: "aws" 3 page_title: "AWS: aws_db_instance" 4 sidebar_current: "docs-aws-resource-db-instance" 5 description: |- 6 Provides an RDS instance resource. 7 --- 8 9 # aws\_db\_instance 10 11 Provides an RDS instance resource. A DB instance is an isolated database 12 environment in the cloud. A DB instance can contain multiple user-created 13 databases. 14 15 Changes to a DB instance can occur when you manually change a 16 parameter, such as `allocated_storage`, and are reflected in the next maintenance 17 window. Because of this, Terraform may report a difference in its planning 18 phase because a modification has not yet taken place. You can use the 19 `apply_immediately` flag to instruct the service to apply the change immediately 20 (see documentation below). 21 22 When upgrading the major version of an engine, `allow_major_version_upgrade` must be set to `true` 23 24 ~> **Note:** using `apply_immediately` can result in a 25 brief downtime as the server reboots. See the AWS Docs on [RDS Maintenance][2] 26 for more information. 27 28 29 ## Example Usage 30 31 ``` 32 resource "aws_db_instance" "default" { 33 allocated_storage = 10 34 engine = "mysql" 35 engine_version = "5.6.17" 36 instance_class = "db.t1.micro" 37 name = "mydb" 38 username = "foo" 39 password = "bar" 40 db_subnet_group_name = "my_database_subnet_group" 41 parameter_group_name = "default.mysql5.6" 42 } 43 ``` 44 45 ## Argument Reference 46 47 For more detailed documentation about each argument, refer to 48 the [AWS official documentation](http://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html). 49 50 The following arguments are supported: 51 52 * `allocated_storage` - (Required unless a `snapshot_identifier` or `replicate_source_db` is provided) The allocated storage in gigabytes. 53 * `engine` - (Required unless a `snapshot_identifier` or `replicate_source_db` is provided) The database engine to use. 54 * `engine_version` - (Optional) The engine version to use. 55 * `identifier` - (Optional) The name of the RDS instance, if omitted, Terraform will assign a random, unique name 56 * `instance_class` - (Required) The instance type of the RDS instance. 57 * `storage_type` - (Optional) One of "standard" (magnetic), "gp2" (general 58 purpose SSD), or "io1" (provisioned IOPS SSD). The default is "io1" if 59 `iops` is specified, "standard" if not. 60 * `final_snapshot_identifier` - (Optional) The name of your final DB snapshot 61 when this DB instance is deleted. If omitted, no final snapshot will be 62 made. 63 * `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 `false`. 64 * `copy_tags_to_snapshot` – (Optional, boolean) On delete, copy all Instance `tags` to 65 the final snapshot (if `final_snapshot_identifier` is specified). Default 66 `false` 67 * `name` - (Optional) The DB name to create. If omitted, no database is created 68 initially. 69 * `password` - (Required unless a `snapshot_identifier` or `replicate_source_db` is provided) Password for the master DB user. Note that this may 70 show up in logs, and it will be stored in the state file. 71 * `username` - (Required unless a `snapshot_identifier` or `replicate_source_db` is provided) Username for the master DB user. 72 * `availability_zone` - (Optional) The AZ for the RDS instance. 73 * `backup_retention_period` - (Optional) The days to retain backups for. Must be 74 `1` or greater to be a source for a [Read Replica][1]. 75 * `backup_window` - (Optional) The backup window. 76 * `iops` - (Optional) The amount of provisioned IOPS. Setting this implies a 77 storage_type of "io1". 78 * `maintenance_window` - (Optional) The window to perform maintenance in. 79 Syntax: "ddd:hh24:mi-ddd:hh24:mi". Eg: "Mon:00:00-Mon:03:00". 80 See [RDS Maintenance Window docs](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/AdjustingTheMaintenanceWindow.html) for more. 81 * `multi_az` - (Optional) Specifies if the RDS instance is multi-AZ 82 * `port` - (Optional) The port on which the DB accepts connections. 83 * `publicly_accessible` - (Optional) Bool to control if instance is publicly accessible. Defaults to `false`. 84 * `vpc_security_group_ids` - (Optional) List of VPC security groups to associate. 85 * `security_group_names` - (Optional/Deprecated) List of DB Security Groups to associate. 86 Only used for [DB Instances on the _EC2-Classic_ Platform](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_VPC.html#USER_VPC.FindDefaultVPC). 87 * `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. 88 * `parameter_group_name` - (Optional) Name of the DB parameter group to associate. 89 * `option_group_name` - (Optional) Name of the DB option group to associate. 90 * `storage_encrypted` - (Optional) Specifies whether the DB instance is encrypted. The default is `false` if not specified. 91 * `apply_immediately` - (Optional) Specifies whether any database modifications 92 are applied immediately, or during the next maintenance window. Default is 93 `false`. See [Amazon RDS Documentation for more information.](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.DBInstance.Modifying.html) 94 * `replicate_source_db` - (Optional) Specifies that this resource is a Replicate 95 database, and to use this value as the source database. This correlates to the 96 `identifier` of another Amazon RDS Database to replicate. See 97 [DB Instance Replication][1] and 98 [Working with PostgreSQL and MySQL Read Replicas](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ReadRepl.html) for 99 more information on using Replication. 100 * `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. 101 * `license_model` - (Optional, but required for some DB engines, i.e. Oracle SE1) License model information for this DB instance. 102 * `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. 103 * `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. 104 * `monitoring_role_arn` - (Optional) The ARN for the IAM role that permits RDS to send 105 enhanced monitoring metrics to CloudWatch Logs. You can find more information on the [AWS Documentation](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_Monitoring.html) 106 what IAM permissions are needed to allow Enhanced Monitoring for RDS Instances. 107 * `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. 108 * `kms_key_id` - (Optional) The ARN for the KMS encryption key. 109 * `character_set_name` - (Optional) The character set name to use for DB encoding in Oracle instances. This can't be changed. 110 [Oracle Character Sets Supported in Amazon RDS](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Appendix.OracleCharacterSets.html) 111 * `tags` - (Optional) A mapping of tags to assign to the resource. 112 * `timezone` - (Optional) Time zone of the DB instance. `timezone` is currently only supported by Microsoft SQL Server. 113 The `timezone` can only be set on creation. See [MSSQL User Guide](http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_SQLServer.html#SQLServer.Concepts.General.TimeZone) for more information 114 115 ~> **NOTE:** Removing the `replicate_source_db` attribute from an existing RDS 116 Replicate database managed by Terraform will promote the database to a fully 117 standalone database. 118 119 ## Attributes Reference 120 121 The following attributes are exported: 122 123 * `id` - The RDS instance ID. 124 * `address` - The address of the RDS instance. 125 * `arn` - The ARN of the RDS instance. 126 * `allocated_storage` - The amount of allocated storage 127 * `availability_zone` - The availability zone of the instance 128 * `backup_retention_period` - The backup retention period 129 * `backup_window` - The backup window 130 * `endpoint` - The connection endpoint 131 * `engine` - The database engine 132 * `engine_version` - The database engine version 133 * `instance_class`- The RDS instance class 134 * `maintenance_window` - The instance maintenance window 135 * `multi_az` - If the RDS instance is multi AZ enabled 136 * `name` - The database name 137 * `port` - The database port 138 * `status` - The RDS instance status 139 * `username` - The master username for the database 140 * `storage_encrypted` - Specifies whether the DB instance is encrypted 141 * `hosted_zone_id` - The canonical hosted zone ID of the DB instance (to be used in a Route 53 Alias record) 142 143 On Oracle instances the following is exported additionally: 144 145 * `character_set_name` - The character set used on Oracle instances. 146 147 148 <a id="timeouts"></a> 149 ## Timeouts 150 151 `aws_db_instance` provides the following 152 [Timeouts](/docs/configuration/resources.html#timeouts) configuration options: 153 154 - `create` - (Default `40 minutes`) Used for Creating Instances, Replicas, and 155 restoring from Snapshots 156 - `update` - (Default `80 minutes`) Used for Database modifications 157 - `delete` - (Default `40 minutes`) Used for destroying databases. This includes 158 the time required to take snapshots 159 160 [1]: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.Replication.html 161 [2]: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_UpgradeDBInstance.Maintenance.html 162 163 ## Import 164 165 DB Instances can be imported using the `identifier`, e.g. 166 167 ``` 168 $ terraform import aws_db_instance.default mydb-rds-instance 169 ```