Skip to content

Commit

Permalink
mysql provider and mysql_database resource.
Browse files Browse the repository at this point in the history
Allows databases on pre-existing MySQL servers to be created and managed
by Terraform.
  • Loading branch information
apparentlymart committed Dec 17, 2015
0 parents commit df813d4
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
72 changes: 72 additions & 0 deletions index.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
layout: "mysql"
page_title: "Provider: MySQL"
sidebar_current: "docs-mysql-index"
description: |-
A provider for MySQL Server.
---

# MySQL Provider

[MySQL](http://www.mysql.com) is a relational database server. The MySQL
provider exposes resources used to manage the configuration of resources
in a MySQL server.

Use the navigation to the left to read about the available resources.

## Example Usage

The following is a minimal example:

```
# Configure the MySQL provider
provider "mysql" {
endpoint = "my-database.example.com:3306"
username = "app-user"
password = "app-password"
}
# Create a Database
resource "mysql_database" "app" {
name = "my_awesome_app"
}
```

This provider can be used in conjunction with other resources that create
MySQL servers. For example, ``aws_db_instance`` is able to create MySQL
servers in Amazon's RDS service.

```
# Create a database server
resource "aws_db_instance" "default" {
engine = "mysql"
engine_version = "5.6.17"
instance_class = "db.t1.micro"
name = "initial_db"
username = "rootuser"
password = "rootpasswd"
# etc, etc; see aws_db_instance docs for more
}
# Configure the MySQL provider based on the outcome of
# creating the aws_db_instance.
provider "mysql" {
endpoint = "${aws_db_instance.default.endpoint}"
username = "${aws_db_instance.default.username}"
password = "${aws_db_instance.default.password}"
}
# Create a second database, in addition to the "initial_db" created
# by the aws_db_instance resource above.
resource "mysql_database" "app" {
name = "another_db"
}
```

## Argument Reference

The following arguments are supported:

* `endpoint` - (Required) The address of the MySQL server to use. Most often a "hostname:port" pair, but may also be an absolute path to a Unix socket when the host OS is Unix-compatible.
* `username` - (Required) Username to use to authenticate with the server.
* `password` - (Optional) Password for the given user, if that user has a password.
54 changes: 54 additions & 0 deletions r/database.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
layout: "mysql"
page_title: "MySQL: mysql_database"
sidebar_current: "docs-mysql-resource-database"
description: |-
Creates and manages a database on a MySQL server.
---

# mysql\_database

The ``mysql_database`` resource creates and manages a database on a MySQL
server.

~> **Caution:** The ``mysql_database`` resource can completely delete your
database just as easily as it can create it. To avoid costly accidents,
consider setting
[``prevent_destroy``](/docs/configuration/resources.html#prevent_destroy)
on your database resources as an extra safety measure.

## Example Usage

```
resource "mysql_database" "app" {
name = "my_awesome_app"
}
```

## Argument Reference

The following arguments are supported:

* `name` - (Required) The name of the database. This must be unique within
a given MySQL server and may or may not be case-sensitive depending on
the operating system on which the MySQL server is running.

* `default_character_set` - (Optional) The default character set to use when
a table is created without specifying an explicit character set. Defaults
to "utf8".

* `default_collation` - (Optional) The default collation to use when a table
is created without specifying an explicit collation. Defaults to
``utf8_general_ci``. Each character set has its own set of collations, so
changing the character set requires also changing the collation.

Note that the defaults for character set and collation above do not respect
any defaults set on the MySQL server, so that the configuration can be set
appropriately even though Terraform cannot see the server-level defaults. If
you wish to use the server's defaults you must consult the server's
configuration and then set the ``default_character_set`` and
``default_collation`` to match.

## Attributes Reference

No further attributes are exported.

0 comments on commit df813d4

Please sign in to comment.