Skip to content

Commit

Permalink
Add option to define character set (#71)
Browse files Browse the repository at this point in the history
* Add option to define character set

* Document selection of character set

* Updated README.md

* Auto Format

Co-authored-by: actions-bot <[email protected]>
Co-authored-by: nitrocode <[email protected]>
Co-authored-by: cloudpossebot <[email protected]>
  • Loading branch information
4 people authored Jul 7, 2021
1 parent 3b6b1e8 commit cb41a4c
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,42 @@ module "rds_instance" {
]
}
```
### Character Sets

If you wish to create the database in a specific character set you can use one of the following options depending
on your database engine of choice.

For Oracle and Microsoft SQL you can specify charset name as an input variable
to this module. For example, for Microsoft SQL, you could use:
```hcl
module "rds_instance" {
...
charset_name = "Korean_Wansung_CI_AS"
...
}
```

For `mysql` and `mariadb` engines character set of the database can be defined via `db_parameter`. In this example
the database is created with `utf8mb4` (character set) and utf8mb4_unicode_ci (collation):

```hcl
module "rds_instance" {
...
db_parameter = [
{
name = "character_set_server"
value = "utf8mb4"
apply_method = "immediate"
},
{
name = "collation_server"
value = "utf8mb4_unicode_ci"
apply_method = "immediate"
}
]
...
}
```



Expand Down Expand Up @@ -230,6 +266,7 @@ Available targets:
| <a name="input_backup_retention_period"></a> [backup\_retention\_period](#input\_backup\_retention\_period) | Backup retention period in days. Must be > 0 to enable backups | `number` | `0` | no |
| <a name="input_backup_window"></a> [backup\_window](#input\_backup\_window) | When AWS can perform DB snapshots, can't overlap with maintenance window | `string` | `"22:00-03:00"` | no |
| <a name="input_ca_cert_identifier"></a> [ca\_cert\_identifier](#input\_ca\_cert\_identifier) | The identifier of the CA certificate for the DB instance | `string` | `null` | no |
| <a name="input_charset_name"></a> [charset\_name](#input\_charset\_name) | The character set name to use for DB encoding. [Oracle & Microsoft SQL only](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_instance#character_set_name). For other engines use `db_parameter` | `string` | `null` | no |
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {}<br>}</pre> | no |
| <a name="input_copy_tags_to_snapshot"></a> [copy\_tags\_to\_snapshot](#input\_copy\_tags\_to\_snapshot) | Copy tags from DB to a snapshot | `bool` | `true` | no |
| <a name="input_database_name"></a> [database\_name](#input\_database\_name) | The name of the database to create when the DB instance is created | `string` | n/a | yes |
Expand Down
36 changes: 36 additions & 0 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,42 @@ usage: |-
]
}
```
### Character Sets
If you wish to create the database in a specific character set you can use one of the following options depending
on your database engine of choice.
For Oracle and Microsoft SQL you can specify charset name as an input variable
to this module. For example, for Microsoft SQL, you could use:
```hcl
module "rds_instance" {
...
charset_name = "Korean_Wansung_CI_AS"
...
}
```
For `mysql` and `mariadb` engines character set of the database can be defined via `db_parameter`. In this example
the database is created with `utf8mb4` (character set) and utf8mb4_unicode_ci (collation):
```hcl
module "rds_instance" {
...
db_parameter = [
{
name = "character_set_server"
value = "utf8mb4"
apply_method = "immediate"
},
{
name = "collation_server"
value = "utf8mb4_unicode_ci"
apply_method = "immediate"
}
]
...
}
```
include:
- docs/targets.md
- docs/terraform.md
Expand Down
1 change: 1 addition & 0 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
| <a name="input_backup_retention_period"></a> [backup\_retention\_period](#input\_backup\_retention\_period) | Backup retention period in days. Must be > 0 to enable backups | `number` | `0` | no |
| <a name="input_backup_window"></a> [backup\_window](#input\_backup\_window) | When AWS can perform DB snapshots, can't overlap with maintenance window | `string` | `"22:00-03:00"` | no |
| <a name="input_ca_cert_identifier"></a> [ca\_cert\_identifier](#input\_ca\_cert\_identifier) | The identifier of the CA certificate for the DB instance | `string` | `null` | no |
| <a name="input_charset_name"></a> [charset\_name](#input\_charset\_name) | The character set name to use for DB encoding. [Oracle & Microsoft SQL only](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_instance#character_set_name). For other engines use `db_parameter` | `string` | `null` | no |
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {}<br>}</pre> | no |
| <a name="input_copy_tags_to_snapshot"></a> [copy\_tags\_to\_snapshot](#input\_copy\_tags\_to\_snapshot) | Copy tags from DB to a snapshot | `bool` | `true` | no |
| <a name="input_database_name"></a> [database\_name](#input\_database\_name) | The name of the database to create when the DB instance is created | `string` | n/a | yes |
Expand Down
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ resource "aws_db_instance" "default" {
port = var.database_port
engine = var.engine
engine_version = var.engine_version
character_set_name = var.charset_name
instance_class = var.instance_class
allocated_storage = var.allocated_storage
max_allocated_storage = var.max_allocated_storage
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ variable "major_engine_version" {
# https://docs.aws.amazon.com/cli/latest/reference/rds/create-option-group.html
}

variable "charset_name" {
type = string
description = "The character set name to use for DB encoding. [Oracle & Microsoft SQL only](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_instance#character_set_name). For other engines use `db_parameter`"
default = null
}

variable "license_model" {
type = string
description = "License model for this DB. Optional, but required for some DB Engines. Valid values: license-included | bring-your-own-license | general-public-license"
Expand Down

0 comments on commit cb41a4c

Please sign in to comment.