Skip to content

Commit a987b21

Browse files
committed
added azure support without backup and restore funtionality
1 parent c337564 commit a987b21

File tree

11 files changed

+501
-0
lines changed

11 files changed

+501
-0
lines changed

examples/complete/azure/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## Mysql Example
2+
![squareops_avatar]
3+
4+
[squareops_avatar]: https://squareops.com/wp-content/uploads/2022/12/squareops-logo.png
5+
6+
### [SquareOps Technologies](https://squareops.com/) Your DevOps Partner for Accelerating cloud journey.
7+
<br>
8+
This example will be very useful for users who are new to a module and want to quickly learn how to use it. By reviewing the examples, users can gain a better understanding of how the module works, what features it supports, and how to customize it to their specific needs.
9+
10+
## Requirements
11+
12+
No requirements.
13+
14+
## Providers
15+
16+
| Name | Version |
17+
|------|---------|
18+
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | 3.70.0 |
19+
20+
## Modules
21+
22+
| Name | Source | Version |
23+
|------|--------|---------|
24+
| <a name="module_azure"></a> [azure](#module\_azure) | squareops/mysql/kubernetes//provider/azure | n/a |
25+
| <a name="module_mysql"></a> [mysql](#module\_mysql) | squareops/mysql/kubernetes | n/a |
26+
27+
## Resources
28+
29+
| Name | Type |
30+
|------|------|
31+
| [azurerm_kubernetes_cluster.primary](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/kubernetes_cluster) | data source |
32+
33+
## Inputs
34+
35+
No inputs.
36+
37+
## Outputs
38+
39+
| Name | Description |
40+
|------|-------------|
41+
| <a name="output_mysql_credential"></a> [mysql\_credential](#output\_mysql\_credential) | MySQL credentials used for accessing the MySQL database. |
42+
| <a name="output_mysql_endpoints"></a> [mysql\_endpoints](#output\_mysql\_endpoints) | MySQL endpoints in the Kubernetes cluster. |
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
primary:
2+
affinity:
3+
nodeAffinity:
4+
requiredDuringSchedulingIgnoredDuringExecution:
5+
nodeSelectorTerms:
6+
- matchExpressions:
7+
- key: "Addons-Services"
8+
operator: In
9+
values:
10+
- "true"
11+
12+
secondary:
13+
affinity:
14+
nodeAffinity:
15+
requiredDuringSchedulingIgnoredDuringExecution:
16+
nodeSelectorTerms:
17+
- matchExpressions:
18+
- key: "Addons-Services"
19+
operator: In
20+
values:
21+
- "true"

examples/complete/azure/main.tf

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
locals {
2+
name = "mysql"
3+
region = "eastus"
4+
environment = "prod"
5+
additional_tags = {
6+
Owner = "organization_name"
7+
Expires = "Never"
8+
Department = "Engineering"
9+
}
10+
store_password_to_secret_manager = true
11+
mysqldb_custom_credentials_enabled = false
12+
mysqldb_custom_credentials_config = {
13+
root_user = "root"
14+
root_password = "RJDRIFsYC8ZS1WQuV0ps"
15+
custom_username = "admin"
16+
custom_user_password = "NCPFUKEMd7rrWuvMAa73"
17+
replication_user = "replicator"
18+
replication_password = "nvAHhm1uGQNYWVw6ZyAH"
19+
exporter_user = "mysqld_exporter"
20+
exporter_password = "ZawhvpueAehRdKFlbjaq"
21+
}
22+
custom_user_username = "custom"
23+
azure_storage_account_name = ""
24+
azure_container_name = ""
25+
}
26+
27+
module "azure" {
28+
source = "squareops/mysql/kubernetes//provider/azure"
29+
cluster_name = ""
30+
resource_group_name = ""
31+
resource_group_location = ""
32+
environment = local.environment
33+
name = local.name
34+
store_password_to_secret_manager = local.store_password_to_secret_manager
35+
mysqldb_custom_credentials_enabled = local.mysqldb_custom_credentials_enabled
36+
mysqldb_custom_credentials_config = local.mysqldb_custom_credentials_config
37+
custom_user_username = local.mysqldb_custom_credentials_enabled ? "" : local.custom_user_username
38+
storage_resource_group_name = ""
39+
storage_account_name = ""
40+
}
41+
42+
module "mysql" {
43+
source = "squareops/mysql/kubernetes"
44+
mysqldb_config = {
45+
name = local.name
46+
values_yaml = file("./helm/values.yaml")
47+
environment = local.environment
48+
architecture = "replication"
49+
storage_class_name = "infra-service-sc"
50+
custom_user_username = local.mysqldb_custom_credentials_enabled ? "" : local.custom_user_username
51+
primary_db_volume_size = "10Gi"
52+
secondary_db_volume_size = "10Gi"
53+
secondary_db_replica_count = 2
54+
store_password_to_secret_manager = local.store_password_to_secret_manager
55+
}
56+
mysqldb_custom_credentials_enabled = local.mysqldb_custom_credentials_enabled
57+
mysqldb_custom_credentials_config = local.mysqldb_custom_credentials_config
58+
root_password = local.mysqldb_custom_credentials_enabled ? "" : module.azure.root_password
59+
metric_exporter_pasword = local.mysqldb_custom_credentials_enabled ? "" : module.azure.metric_exporter_pasword
60+
mysqldb_replication_user_password = local.mysqldb_custom_credentials_enabled ? "" : module.azure.mysqldb_replication_user_password
61+
custom_user_password = local.mysqldb_custom_credentials_enabled ? "" : module.azure.custom_user_password
62+
bucket_provider_type = "azure"
63+
mysqldb_backup_enabled = false
64+
mysqldb_backup_config = {
65+
bucket_uri = "https://${local.azure_storage_account_name}.blob.core.windows.net/${local.azure_container_name}"
66+
azure_storage_account_name = local.azure_storage_account_name
67+
azure_container_name = local.azure_container_name
68+
cron_for_full_backup = "* * 1 * *"
69+
}
70+
mysqldb_restore_enabled = false
71+
mysqldb_restore_config = {
72+
bucket_uri = "https://${local.azure_storage_account_name}.blob.core.windows.net/${local.azure_container_name}"
73+
azure_storage_account_name = local.azure_storage_account_name
74+
azure_container_name = local.azure_container_name
75+
file_name = "mongodumpfull_20230710_132301.gz"
76+
}
77+
mysqldb_exporter_enabled = true
78+
}

examples/complete/azure/outputs.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "mysql_endpoints" {
2+
value = module.mysql.mysqldb_endpoints
3+
description = "MySQL endpoints in the Kubernetes cluster."
4+
}
5+
6+
output "mysql_credential" {
7+
value = local.store_password_to_secret_manager ? null : module.mysql.mysqldb_credential
8+
description = "MySQL credentials used for accessing the MySQL database."
9+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
provider "azurerm" {
2+
features {}
3+
}
4+
5+
data "azurerm_kubernetes_cluster" "primary" {
6+
name = ""
7+
resource_group_name = ""
8+
}
9+
10+
provider "kubernetes" {
11+
host = data.azurerm_kubernetes_cluster.primary.kube_config.0.host
12+
username = data.azurerm_kubernetes_cluster.primary.kube_config.0.username
13+
password = data.azurerm_kubernetes_cluster.primary.kube_config.0.password
14+
client_certificate = base64decode(data.azurerm_kubernetes_cluster.primary.kube_config.0.client_certificate)
15+
client_key = base64decode(data.azurerm_kubernetes_cluster.primary.kube_config.0.client_key)
16+
cluster_ca_certificate = base64decode(data.azurerm_kubernetes_cluster.primary.kube_config.0.cluster_ca_certificate)
17+
}
18+
19+
provider "helm" {
20+
kubernetes {
21+
host = data.azurerm_kubernetes_cluster.primary.kube_config.0.host
22+
client_key = base64decode(data.azurerm_kubernetes_cluster.primary.kube_config.0.client_key)
23+
client_certificate = base64decode(data.azurerm_kubernetes_cluster.primary.kube_config.0.client_certificate)
24+
cluster_ca_certificate = base64decode(data.azurerm_kubernetes_cluster.primary.kube_config.0.cluster_ca_certificate)
25+
}
26+
}

main.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ resource "helm_release" "mysqldb_backup" {
4848
cron_for_full_backup = var.mysqldb_backup_config.cron_for_full_backup,
4949
custom_user_username = "root",
5050
bucket_provider_type = var.bucket_provider_type,
51+
azure_storage_account_name = var.bucket_provider_type == "azure" ? var.azure_storage_account_name : ""
52+
azure_storage_account_key = var.bucket_provider_type == "azure" ? var.azure_storage_account_key : ""
53+
azure_container_name = var.bucket_provider_type == "azure" ? var.azure_container_name : ""
5154
annotations = var.bucket_provider_type == "s3" ? "eks.amazonaws.com/role-arn: ${var.iam_role_arn_backup}" : "iam.gke.io/gcp-service-account: ${var.service_account_backup}"
5255
})
5356
]
@@ -69,6 +72,9 @@ resource "helm_release" "mysqldb_restore" {
6972
s3_bucket_region = var.bucket_provider_type == "s3" ? var.mysqldb_restore_config.s3_bucket_region : "",
7073
custom_user_username = "root",
7174
bucket_provider_type = var.bucket_provider_type,
75+
azure_storage_account_name = var.bucket_provider_type == "azure" ? var.azure_storage_account_name : ""
76+
azure_storage_account_key = var.bucket_provider_type == "azure" ? var.azure_storage_account_key : ""
77+
azure_container_name = var.bucket_provider_type == "azure" ? var.azure_container_name : ""
7278
annotations = var.bucket_provider_type == "s3" ? "eks.amazonaws.com/role-arn: ${var.iam_role_arn_restore}" : "iam.gke.io/gcp-service-account: ${var.service_account_restore}"
7379
})
7480
]

provider/azure/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Azure Provider Module
2+
3+
## Requirements
4+
5+
No requirements.
6+
7+
## Providers
8+
9+
| Name | Version |
10+
|------|---------|
11+
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | n/a |
12+
| <a name="provider_random"></a> [random](#provider\_random) | n/a |
13+
14+
## Modules
15+
16+
No modules.
17+
18+
## Resources
19+
20+
| Name | Type |
21+
|------|------|
22+
| [azurerm_key_vault.mysql-secret](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/key_vault) | resource |
23+
| [azurerm_key_vault_secret.mysql-secret](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/key_vault_secret) | resource |
24+
| [azurerm_role_assignment.pod_identity_assignment_backup](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) | resource |
25+
| [azurerm_role_assignment.secretadmin_backup](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) | resource |
26+
| [azurerm_role_assignment.secretadmin_restore](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) | resource |
27+
| [azurerm_role_assignment.service_account_token_creator_backup](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) | resource |
28+
| [azurerm_role_assignment.service_account_token_creator_restore](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) | resource |
29+
| [azurerm_user_assigned_identity.mysql_backup_identity](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/user_assigned_identity) | resource |
30+
| [azurerm_user_assigned_identity.mysql_restore_identity](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/user_assigned_identity) | resource |
31+
| [azurerm_user_assigned_identity.pod_identity_backup](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/user_assigned_identity) | resource |
32+
| [random_password.mysqldb_custom_user_password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
33+
| [random_password.mysqldb_exporter_user_password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
34+
| [random_password.mysqldb_replication_user_password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
35+
| [random_password.mysqldb_root_password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
36+
| [azurerm_client_config.current](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/client_config) | data source |
37+
| [azurerm_subscription.current](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/subscription) | data source |
38+
39+
## Inputs
40+
41+
| Name | Description | Type | Default | Required |
42+
|------|-------------|------|---------|:--------:|
43+
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | Name of the Azure AKS cluster | `string` | `""` | no |
44+
| <a name="input_custom_user_username"></a> [custom\_user\_username](#input\_custom\_user\_username) | n/a | `string` | `""` | no |
45+
| <a name="input_environment"></a> [environment](#input\_environment) | Environment in which the infrastructure is being deployed (e.g., production, staging, development) | `string` | `"test"` | no |
46+
| <a name="input_mysqldb_custom_credentials_config"></a> [mysqldb\_custom\_credentials\_config](#input\_mysqldb\_custom\_credentials\_config) | Specify the configuration settings for MySQL to pass custom credentials during creation | `any` | <pre>{<br> "custom_user_password": "",<br> "custom_username": "",<br> "exporter_password": "",<br> "exporter_user": "",<br> "replication_password": "",<br> "replication_user": "",<br> "root_password": "",<br> "root_user": ""<br>}</pre> | no |
47+
| <a name="input_mysqldb_custom_credentials_enabled"></a> [mysqldb\_custom\_credentials\_enabled](#input\_mysqldb\_custom\_credentials\_enabled) | Specifies whether to enable custom credentials for MySQL database. | `bool` | `false` | no |
48+
| <a name="input_name"></a> [name](#input\_name) | Name identifier for module to be added as suffix to resources | `string` | `"test"` | no |
49+
| <a name="input_resource_group_location"></a> [resource\_group\_location](#input\_resource\_group\_location) | Azure region | `string` | `"East US"` | no |
50+
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | Azure Resource Group name | `string` | `""` | no |
51+
| <a name="input_storage_account_name"></a> [storage\_account\_name](#input\_storage\_account\_name) | n/a | `string` | `""` | no |
52+
| <a name="input_storage_resource_group_name"></a> [storage\_resource\_group\_name](#input\_storage\_resource\_group\_name) | Azure Storage account Resource Group name | `string` | `""` | no |
53+
| <a name="input_store_password_to_secret_manager"></a> [store\_password\_to\_secret\_manager](#input\_store\_password\_to\_secret\_manager) | Specifies whether to store the credentials in GCP secret manager. | `bool` | `false` | no |
54+
55+
## Outputs
56+
57+
| Name | Description |
58+
|------|-------------|
59+
| <a name="output_custom_user_password"></a> [custom\_user\_password](#output\_custom\_user\_password) | custom user's password of mysqldb |
60+
| <a name="output_metric_exporter_pasword"></a> [metric\_exporter\_pasword](#output\_metric\_exporter\_pasword) | mysqldb\_exporter user's password of mysqldb |
61+
| <a name="output_mysqldb_replication_user_password"></a> [mysqldb\_replication\_user\_password](#output\_mysqldb\_replication\_user\_password) | replicator user's password of mysqldb |
62+
| <a name="output_root_password"></a> [root\_password](#output\_root\_password) | Root user's password of mysqldb |

0 commit comments

Comments
 (0)