-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
326 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
plugin "terraform" { | ||
enabled = true | ||
preset = "recommended" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# OVH mysql DBaaS | ||
|
||
Create a OVH managed database instance (mysql engine only). | ||
|
||
<!-- don't remove this line used to keep some space before auto generated docs --> | ||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.3 | | ||
| <a name="requirement_ovh"></a> [ovh](#requirement\_ovh) | ~> 0.26.0 | | ||
| <a name="requirement_time"></a> [time](#requirement\_time) | ~> 0.9.1 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_ovh"></a> [ovh](#provider\_ovh) | ~> 0.26.0 | | ||
| <a name="provider_time"></a> [time](#provider\_time) | ~> 0.9.1 | | ||
|
||
## Modules | ||
|
||
No modules. | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [ovh_cloud_project_database.instance](https://registry.terraform.io/providers/ovh/ovh/latest/docs/resources/cloud_project_database) | resource | | ||
| [ovh_cloud_project_database_database.database](https://registry.terraform.io/providers/ovh/ovh/latest/docs/resources/cloud_project_database_database) | resource | | ||
| [ovh_cloud_project_database_ip_restriction.iprestriction](https://registry.terraform.io/providers/ovh/ovh/latest/docs/resources/cloud_project_database_ip_restriction) | resource | | ||
| [ovh_cloud_project_database_user.user](https://registry.terraform.io/providers/ovh/ovh/latest/docs/resources/cloud_project_database_user) | resource | | ||
| [time_static.last_update](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/static) | resource | | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| <a name="input_cloud_project_id"></a> [cloud\_project\_id](#input\_cloud\_project\_id) | The OVH public cloud project id | `string` | n/a | yes | | ||
| <a name="input_customer"></a> [customer](#input\_customer) | Customer for the current deployment | `string` | `""` | no | | ||
| <a name="input_environment"></a> [environment](#input\_environment) | Environment for the current deployment | `string` | `""` | no | | ||
| <a name="input_mysql_allowed_ips"></a> [mysql\_allowed\_ips](#input\_mysql\_allowed\_ips) | IPs cidrs allowed to access the database | `list(string)` | `null` | no | | ||
| <a name="input_mysql_databases"></a> [mysql\_databases](#input\_mysql\_databases) | Name of the databases to create | `list(string)` | `[]` | no | | ||
| <a name="input_mysql_flavor"></a> [mysql\_flavor](#input\_mysql\_flavor) | Flavor of the database | `string` | `"db1-4"` | no | | ||
| <a name="input_mysql_nodes"></a> [mysql\_nodes](#input\_mysql\_nodes) | Nodes of the database | <pre>list(object({<br> region = string<br> network_id = string<br> subnet_id = string<br> }))</pre> | <pre>[<br> {<br> "network_id": null,<br> "region": "GRA5",<br> "subnet_id": null<br> }<br>]</pre> | no | | ||
| <a name="input_mysql_plan"></a> [mysql\_plan](#input\_mysql\_plan) | Plan of the database | `string` | `"essential"` | no | | ||
| <a name="input_mysql_users"></a> [mysql\_users](#input\_mysql\_users) | Users of the database | <pre>list(object({<br> name = string<br> }))</pre> | <pre>[<br> {<br> "name": "root"<br> }<br>]</pre> | no | | ||
| <a name="input_mysql_version"></a> [mysql\_version](#input\_mysql\_version) | Version of the database | `string` | `"14"` | no | | ||
| <a name="input_name"></a> [name](#input\_name) | Name to be used on all the resources as identifier | `string` | n/a | yes | | ||
| <a name="input_tags"></a> [tags](#input\_tags) | Default tags to add to resources | `map(any)` | `{}` | no | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_endpoints"></a> [endpoints](#output\_endpoints) | n/a | | ||
| <a name="output_id"></a> [id](#output\_id) | n/a | | ||
| <a name="output_nodes"></a> [nodes](#output\_nodes) | n/a | | ||
| <a name="output_status"></a> [status](#output\_status) | n/a | | ||
| <a name="output_users"></a> [users](#output\_users) | n/a | | ||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
resource "ovh_cloud_project_database" "instance" { | ||
service_name = var.cloud_project_id | ||
description = var.name | ||
engine = "mysql" | ||
version = var.mysql_version | ||
plan = var.mysql_plan | ||
flavor = var.mysql_flavor | ||
dynamic "nodes" { | ||
for_each = var.mysql_nodes | ||
content { | ||
region = nodes.value.region | ||
network_id = nodes.value.network_id | ||
subnet_id = nodes.value.subnet_id | ||
} | ||
} | ||
} | ||
|
||
resource "ovh_cloud_project_database_user" "user" { | ||
engine = "mysql" | ||
count = length(var.mysql_users) | ||
service_name = var.cloud_project_id | ||
cluster_id = ovh_cloud_project_database.instance.id | ||
name = var.mysql_users[count.index].name | ||
} | ||
|
||
resource "ovh_cloud_project_database_ip_restriction" "iprestriction" { | ||
count = var.mysql_allowed_ips == null ? 0 : length(var.mysql_allowed_ips) | ||
service_name = ovh_cloud_project_database.instance.service_name | ||
engine = ovh_cloud_project_database.instance.engine | ||
cluster_id = ovh_cloud_project_database.instance.id | ||
ip = var.mysql_allowed_ips[count.index] | ||
} | ||
|
||
resource "ovh_cloud_project_database_database" "database" { | ||
count = length(var.mysql_databases) | ||
service_name = ovh_cloud_project_database.instance.service_name | ||
engine = ovh_cloud_project_database.instance.engine | ||
cluster_id = ovh_cloud_project_database.instance.id | ||
name = var.mysql_databases[count.index] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
locals { | ||
# NOTE: ovh resources does not support tags (yet) | ||
# tflint-ignore: terraform_unused_declarations | ||
interpolated_tags = merge({ | ||
"Name" = var.name, | ||
"Customer" = var.customer, | ||
"Environment" = var.environment, | ||
"ManagedBy" = "Terraform", | ||
"LastModifiedAt" = time_static.last_update.rfc3339, | ||
}, | ||
var.tags | ||
) | ||
} | ||
|
||
resource "time_static" "last_update" { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
output "id" { | ||
value = ovh_cloud_project_database.instance.id | ||
} | ||
|
||
output "endpoints" { | ||
value = ovh_cloud_project_database.instance.endpoints | ||
} | ||
|
||
output "nodes" { | ||
value = ovh_cloud_project_database.instance.nodes | ||
} | ||
|
||
output "status" { | ||
value = ovh_cloud_project_database.instance.status | ||
} | ||
|
||
output "users" { | ||
value = ovh_cloud_project_database_user.user[*] | ||
sensitive = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
terraform { | ||
required_providers { | ||
ovh = { | ||
source = "ovh/ovh" | ||
version = "~> 0.26.0" | ||
} | ||
time = { | ||
source = "hashicorp/time", | ||
version = "~> 0.9.1" | ||
} | ||
} | ||
required_version = "~> 1.3" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
variable "name" { | ||
description = "Name to be used on all the resources as identifier" | ||
type = string | ||
} | ||
|
||
variable "customer" { | ||
description = "Customer for the current deployment" | ||
type = string | ||
default = "" | ||
} | ||
|
||
variable "environment" { | ||
description = "Environment for the current deployment" | ||
type = string | ||
default = "" | ||
} | ||
|
||
variable "tags" { | ||
description = "Default tags to add to resources" | ||
type = map(any) | ||
default = {} | ||
} | ||
|
||
# bellow are specific modules variables | ||
variable "cloud_project_id" { | ||
description = "The OVH public cloud project id" | ||
type = string | ||
} | ||
|
||
variable "mysql_flavor" { | ||
description = "Flavor of the database" | ||
type = string | ||
default = "db1-4" | ||
} | ||
|
||
variable "mysql_nodes" { | ||
description = "Nodes of the database" | ||
type = list(object({ | ||
region = string | ||
network_id = string | ||
subnet_id = string | ||
})) | ||
default = [ | ||
{ | ||
region = "GRA5" | ||
network_id = null | ||
subnet_id = null | ||
} | ||
] | ||
} | ||
|
||
variable "mysql_plan" { | ||
description = "Plan of the database" | ||
type = string | ||
default = "essential" | ||
} | ||
|
||
variable "mysql_version" { | ||
description = "Version of the database" | ||
type = string | ||
default = "14" | ||
} | ||
|
||
variable "mysql_users" { | ||
description = "Users of the database" | ||
type = list(object({ | ||
name = string | ||
})) | ||
default = [ | ||
{ | ||
name = "root" | ||
} | ||
] | ||
} | ||
|
||
variable "mysql_allowed_ips" { | ||
description = "IPs cidrs allowed to access the database" | ||
type = list(string) | ||
default = null | ||
} | ||
|
||
variable "mysql_databases" { | ||
description = "Name of the databases to create" | ||
type = list(string) | ||
# if empty only the default database will be created (defaultdb) | ||
default = [] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.