Skip to content

Commit

Permalink
Merge pull request #2 from sbernier-corp/feature-readonlyreplicas-and…
Browse files Browse the repository at this point in the history
…-volume-encryption

Feature readonlyreplicas and volume encryption
  • Loading branch information
vlandemaine-orange authored Sep 2, 2020
2 parents 768d3ea + 18bb9cc commit 7db304f
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 117 deletions.
219 changes: 106 additions & 113 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,122 +1,115 @@
# Flexible Engine RDS Terraform Module

Terraform module which creates RDS on Flexible Engine.
Available datastore are:

* PostgreSQL
* MySQL
* SQLServer

More details about supported version in followed link https://www.terraform.io/docs/providers/flexibleengine/d/rds_flavors_v1.html


## TF version : 0.13

## Usage : Terraform

```hcl
module "rds" {
source = "terraform-flexibleengine-modules/rds/flexibleengine"
version = "1.0.0"
vpc_name = "vpc-main"
subnet_name = "subnet-cce"
db_type = "MySQL"
db_version = "5.6.35"
db_flavor = "rds.mysql.s1.medium"
db_sg = "sg-test-rds"
db_tcp_port = "8635"
db_backup_starttime = "08:00-09:00"
db_backup_keepdays = 4
db_root_password = "FooBarPasswd1234!"
rds_ha_enable = false
rds_ha_replicamode = "async"
rds_instance_name = "rds_mysql_foo"
rds_instance_volume_type = "COMMON"
rds_instance_volume_size = 100
rds_instance_az = ["eu-west-0a"]
}
```

## Usage : Terragrunt

```hcl
################################
### Terragrunt Configuration ###
################################
terraform {
source = "terraform-flexibleengine-modules/rds/flexibleengine"
version = "1.0.0"
}
include {
path = find_in_parent_folders()
}
##################
### Parameters ###
##################
inputs = {
vpc_name = "vpc-main"
subnet_name = "subnet-cce"
db_type = "MySQL"
db_version = "5.6.35"
db_flavor = "rds.mysql.s1.medium"
db_sg = "sg-test-rds"
db_tcp_port = "8635"
db_backup_starttime = "08:00-09:00"
db_backup_keepdays = 4
db_root_password = "FooBarPasswd1234!"
rds_ha_enable = false
rds_ha_replicamode = "async"
rds_instance_name = "rds_mysql_foo"
rds_instance_volume_type = "COMMON"
rds_instance_volume_size = 100
rds_instance_az = ["eu-west-0a"]
}
```

## Databases HA flavor

If you are using an RDS in HA mode, you must add ".ha" to your flavor.

Exemple : if you are using the flavor rds.mysql.s1.medium, the HA flavor is rds.mysql.s1.medium.ha

Refer to [the FE RDS Documentation](https://docs.prod-cloud-ocb.orange-business.com/usermanual/rds/en-us_topic_dashboard.html)
# Flexible Engine RDS Terraform Module

Terraform module which creates RDS on Flexible Engine.
Available datastore are:

* PostgreSQL
* MySQL
* SQLServer

More details about supported version in followed link https://www.terraform.io/docs/providers/flexibleengine/d/rds_flavors_v1.html


## TF version : 0.13

## Usage : Terraform

```hcl
module "rds" {
source = "terraform-flexibleengine-modules/rds/flexibleengine"
version = "1.0.0"
vpc_name = "vpc-main"
subnet_name = "subnet-cce"
db_type = "MySQL"
db_version = "5.6.35"
db_flavor = "rds.mysql.s1.medium"
db_sg = "sg-test-rds"
db_tcp_port = "8635"
db_backup_starttime = "08:00-09:00"
db_backup_keepdays = 4
db_root_password = "FooBarPasswd1234!"
rds_ha_enable = false
rds_ha_replicamode = "async"
rds_instance_name = "rds_mysql_foo"
rds_instance_volume_type = "COMMON"
rds_instance_volume_size = 100
rds_instance_az = ["eu-west-0a"]
}
```

## Usage : Terragrunt

```hcl
################################
### Terragrunt Configuration ###
################################
terraform {
source = "terraform-flexibleengine-modules/rds/flexibleengine"
version = "1.0.0"
}
include {
path = find_in_parent_folders()
}
##################
### Parameters ###
##################
inputs = {
vpc_name = "vpc-main"
subnet_name = "subnet-cce"
db_type = "MySQL"
db_version = "5.6.35"
db_flavor = "rds.mysql.s1.medium"
db_sg = "sg-test-rds"
db_tcp_port = "8635"
db_backup_starttime = "08:00-09:00"
db_backup_keepdays = 4
db_root_password = "FooBarPasswd1234!"
rds_ha_enable = false
rds_ha_replicamode = "async"
rds_instance_name = "rds_mysql_foo"
rds_instance_volume_type = "COMMON"
rds_instance_volume_size = 100
rds_instance_az = ["eu-west-0a"]
}
```

## Databases HA flavor

If you are using an RDS in HA mode, you must add ".ha" to your flavor.

Exemple : if you are using the flavor rds.mysql.s1.medium, the HA flavor is rds.mysql.s1.medium.ha

Refer to [the FE RDS Documentation](https://docs.prod-cloud-ocb.orange-business.com/usermanual/rds/en-us_topic_dashboard.html)

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| db\_backup\_keepdays | keep days of database backup | string | `0` | no |
| db\_backup\_starttime | Range of start time of database backup (Exemple : 08:00-09:00) | string | `` | no |
| db\_flavor | Flavor of database. Check Terraform and FE documentation to get flavor list | string | `` | yes |
| db\_root\_password | root password of RDS | string | `` | yes |
| db\_sg | name of RDS security group | string | `` | yes |
| db\_tcp\_port | TCP port of database | string | `` | yes |
| db\_type | Type of database. Can be MySQL, PostgreSQL, SQLServer | string | `` | yes |
| db\_version | Version of database. Check Terraform and FE documentation to get version list | string | `` | yes |
| rds\_ha\_enable | To enable HA of RDS | string | `false` | no |
| rds\_ha\_replicamode | To enable HA of RDS | string | `` | no |
| rds\_instance\_az | Availability zones of RDS instance (Multiple AZ must be specified if you are using HA) | list(string) | `[eu-west-0a]` | no |
| rds\_instance\_name | name of RDS instances | string | `` | yes |
| rds\_instance\_volume\_size | Volume size of instances | string | `0` | yes |
| rds\_instance\_volume\_type | Volume type of instances | string | `COMMON` | no |
| subnet\_name | Name of the data subnet | string | `` | yes |
| vpc\_name | Name of the VPC | string | `` | yes |
|------|-------------|------|---------|:--------:|
| db\_backup\_keepdays | keep days of database backup | `number` | `3` | no |
| db\_backup\_starttime | start time of database backup (Exemple : 08:00-09:00) | `string` | `"01:00-02:00"` | no |
| db\_flavor | Flavor of database. Check Terraform and FE documentation to get flavor list | `string` | `""` | no |
| db\_root\_password | root password of RDS | `string` | `""` | no |
| db\_sg | name of RDS security group to create | `string` | `""` | no |
| db\_tcp\_port | TCP port of database | `string` | `""` | no |
| db\_type | Type of database. Can be MySQL, PostgreSQL, SQLServer | `string` | `""` | no |
| db\_version | Version of database. Check Terraform and FE documentation to get version list | `string` | `""` | no |
| rds\_ha\_enable | To enable HA of RDS | `bool` | `false` | no |
| rds\_ha\_replicamode | To enable HA of RDS | `string` | `""` | no |
| rds\_instance\_az | Availability zones of RDS instance (Multiple AZ must be specified if you are using HA) | `list(string)` | <pre>[<br> "eu-west-0a"<br>]</pre> | no |
| rds\_instance\_name | name of RDS instances | `string` | `""` | no |
| rds\_instance\_volume\_encryption\_id | KMS Key id for encryption | `string` | `null` | no |
| rds\_instance\_volume\_size | Volume size of instances | `number` | `0` | no |
| rds\_instance\_volume\_type | Volume type of instances | `string` | `"COMMON"` | no |
| rds\_read\_replicat\_list | n/a | <pre>list(object({<br> name = string<br> flavor = string<br> availability_zone = string<br> volume_type = string<br> disk_encryption_id = string<br> }))</pre> | n/a | yes |
| subnet\_name | Name of the data subnet | `string` | `""` | no |
| vpc\_name | Name of the VPC | `string` | `""` | no |

## Outputs

| Name | Description |
|------|-------------|
| id | Instance id |
| nodes | List of RDS nodes |
| private_ips | Private IP address list of nodes |
| public_ips | Public IP address list of nodes |
| private\_ips | Private IP address list of nodes |
| public\_ips | Public IP address list of nodes |

20 changes: 18 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ resource "flexibleengine_rds_instance_v3" "instance" {
subnet_id = data.flexibleengine_vpc_subnet_v1.subnet_v1.id
vpc_id = data.flexibleengine_vpc_v1.vpc.id
volume {
type = var.rds_instance_volume_type
size = var.rds_instance_volume_size
type = var.rds_instance_volume_type
size = var.rds_instance_volume_size
disk_encryption_id = var.rds_instance_volume_encryption_id
}
flavor = var.db_flavor
ha_replication_mode = var.rds_ha_enable ? var.rds_ha_replicamode : null
Expand All @@ -33,3 +34,18 @@ resource "flexibleengine_rds_instance_v3" "instance" {
keep_days = var.db_backup_keepdays
}
}

resource "flexibleengine_rds_read_replica_v3" "instances" {

count = length(var.rds_read_replicat_list) > 0 ? length(var.rds_read_replicat_list) : 0

name = var.rds_read_replicat_list[count.index]["name"]
flavor = var.rds_read_replicat_list[count.index]["flavor"]
availability_zone = var.rds_read_replicat_list[count.index]["availability_zone"]
replica_of_id = flexibleengine_rds_instance_v3.instance.id

volume {
type = var.rds_read_replicat_list[count.index]["volume_type"]
disk_encryption_id = var.rds_read_replicat_list[count.index]["disk_encryption_id"]
}
}
8 changes: 7 additions & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ output "nodes" {
value = flexibleengine_rds_instance_v3.instance.nodes
}

output "id" {
description = "Instance id"
value = flexibleengine_rds_instance_v3.instance.id
}


output "private_ips" {
description = "Private IP address list of nodes"
value = flexibleengine_rds_instance_v3.instance.private_ips
Expand All @@ -11,4 +17,4 @@ output "private_ips" {
output "public_ips" {
description = "Public IP address list of nodes"
value = flexibleengine_rds_instance_v3.instance.public_ips
}
}
18 changes: 17 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,24 @@ variable "rds_instance_volume_size" {
type = number
}

variable "rds_instance_volume_encryption_id" {
description = "KMS Key id for encryption"
default = null
type = string
}

variable "rds_instance_az" {
description = "Availability zones of RDS instance (Multiple AZ must be specified if you are using HA)"
default = ["eu-west-0a"]
type = list(string)
}
}

variable "rds_read_replicat_list" {
type = list(object({
name = string
flavor = string
availability_zone = string
volume_type = string
disk_encryption_id = string
}))
}

0 comments on commit 7db304f

Please sign in to comment.