Skip to content

Commit eb0fec8

Browse files
authored
Merge pull request #1 from ShibraAmin18/azure
added azure support
2 parents 9b64986 + 442fbf8 commit eb0fec8

File tree

10 files changed

+329
-8
lines changed

10 files changed

+329
-8
lines changed

IAM.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## IAM Permission
1+
## AWS IAM Permission
22

33
The Policy required to deploy this module:
44
```hcl
@@ -33,3 +33,17 @@ The Policy required to deploy this module:
3333
]
3434
}
3535
```
36+
## Azure Role Permissions
37+
38+
```hcl
39+
permissions {
40+
actions = [
41+
"Microsoft.KeyVault/locations/deletedVaults/read",
42+
"Microsoft.KeyVault/vaults/delete",
43+
"Microsoft.KeyVault/vaults/read",
44+
"Microsoft.KeyVault/vaults/write",
45+
"Microsoft.Resources/subscriptions/providers/read",
46+
"Microsoft.Resources/subscriptions/resourcegroups/read"]
47+
not_actions = []
48+
}
49+
```

README.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,56 @@
66

77
### [SquareOps Technologies](https://squareops.com/) Your DevOps Partner for Accelerating cloud journey.
88
<br>
9-
This module allows users to customize the deployment by providing various input variables. Users can specify the name and environment of the Redis deployment, the chart and app version, the namespace in which the Redis deployment will be created, and whether to enable Grafana monitoring. The module also allows users to set the recovery window for the AWS Secrets Manager that is used to store the Redis password.
9+
This module allows users to customize the deployment by providing various input variables. Users can specify the name and environment of the Redis deployment, the chart and app version, the namespace in which the Redis deployment will be created, and whether to enable Grafana monitoring. This module provides options to create a new namespace, and to configure recovery windows for AWS Secrets Manager, Azure key vault & GCP secrets manager. With this module, users can easily deploy a highly available redis on AWS EKS, Azure AKS & GCP GKE Kubernetes clusters with the flexibility to customize their configurations according to their needs.
1010
<br><br>
1111
This module creates a Redis master and one or more Redis slaves, depending on the specified architecture. The module creates Kubernetes services for the Redis master and slave deployments, and exposes these services as endpoints that can be used to connect to the Redis database. Users can retrieve these endpoints using the module's outputs.
1212

1313
## Supported Versions :
1414

15-
| Redis Helm Chart Version | K8s supported version |
15+
| Redis Helm Chart Version | K8s supported version (EKS, AKS & GKE) |
1616
| :-----: | :--- |
1717
| **16.13.2** | **1.23,1.24,1.25,1.26,1.27** |
1818

1919
## Usage Example
2020

2121
```hcl
22+
module "aws" {
23+
source = "squareops/redis/kubernetes//provider/aws"
24+
environment = "prod"
25+
name = "redis"
26+
store_password_to_secret_manager = true
27+
custom_credentials_enabled = true
28+
custom_credentials_config = {
29+
password = "aajdhgduy3873683dh"
30+
}
31+
}
32+
2233
module "redis" {
23-
source = "squareops/redis/kubernetes"
34+
source = "squareops/redis/kubernetes"
2435
redis_config = {
2536
name = "redis"
26-
values_yaml = ""
37+
values_yaml = file("./helm/values.yaml")
2738
environment = "prod"
2839
architecture = "replication"
2940
slave_volume_size = "10Gi"
3041
master_volume_size = "10Gi"
3142
storage_class_name = "gp3"
3243
slave_replica_count = 2
3344
store_password_to_secret_manager = true
45+
secret_provider_type = "aws"
3446
}
3547
grafana_monitoring_enabled = true
36-
recovery_window_aws_secret = 0
3748
custom_credentials_enabled = true
3849
custom_credentials_config = {
3950
password = "aajdhgduy3873683dh"
4051
}
52+
redis_password = true ? "" : module.aws.redis_password
4153
}
4254
4355
```
44-
Refer [examples](https://github.com/squareops/terraform-kubernetes-redis/tree/main/examples/complete) for more details.
56+
- Refer [AWS examples](https://github.com/squareops/terraform-kubernetes-redis/tree/main/examples/complete/aws) for more details.
57+
- Refer [Azure examples](https://github.com/squareops/terraform-kubernetes-redis/tree/main/examples/complete/azure) for more details.
58+
- Refer [GCP examples](https://github.com/squareops/terraform-kubernetes-redis/tree/main/examples/complete/agcp) for more details.
4559

4660
## IAM Permissions
4761
The required IAM permissions to create resources from this module can be found [here](https://github.com/squareops/terraform-kubernetes-redis/blob/main/IAM.md)
@@ -54,7 +68,7 @@ The required IAM permissions to create resources from this module can be found [
5468
5. To deploy Prometheus/Grafana, please follow the installation instructions for each tool in their respective documentation.
5569
6. Once Prometheus and Grafana are deployed, the exporter can be configured to scrape metrics data from your application or system and send it to Prometheus.
5670
7. Finally, you can use Grafana to create custom dashboards and visualize the metrics data collected by Prometheus.
57-
8. This module is compatible with EKS version 1.23, which is great news for users deploying the module on an EKS cluster running that version. Review the module's documentation, meet specific configuration requirements, and test thoroughly after deployment to ensure everything works as expected.
71+
8. This module is compatible with EKS, AKS & GKE which is great news for users deploying the module on an AWS, Azure & GCP cloud. Review the module's documentation, meet specific configuration requirements, and test thoroughly after deployment to ensure everything works as expected.
5872
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
5973
## Requirements
6074

examples/complete/azure/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## Redis 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+
<!-- BEGIN_TF_DOCS -->
11+
## Requirements
12+
13+
No requirements.
14+
15+
## Providers
16+
17+
| Name | Version |
18+
|------|---------|
19+
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | 3.70.0 |
20+
21+
## Modules
22+
23+
| Name | Source | Version |
24+
|------|--------|---------|
25+
| <a name="module_azure"></a> [azure](#module\_azure) | squareops/redis/kubernetes//provider/azure | n/a |
26+
| <a name="module_redis"></a> [redis](#module\_redis) | squareops/redis/kubernetes | n/a |
27+
28+
## Resources
29+
30+
| Name | Type |
31+
|------|------|
32+
| [azurerm_kubernetes_cluster.primary](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/kubernetes_cluster) | data source |
33+
34+
## Inputs
35+
36+
No inputs.
37+
38+
## Outputs
39+
40+
| Name | Description |
41+
|------|-------------|
42+
| <a name="output_redis_credential"></a> [redis\_credential](#output\_redis\_credential) | Redis credentials used for accessing the database. |
43+
| <a name="output_redis_endpoints"></a> [redis\_endpoints](#output\_redis\_endpoints) | Redis endpoints in the Kubernetes cluster. |
44+
<!-- END_TF_DOCS -->
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
master:
2+
affinity:
3+
nodeAffinity:
4+
requiredDuringSchedulingIgnoredDuringExecution:
5+
nodeSelectorTerms:
6+
- matchExpressions:
7+
- key: "Addons-Services"
8+
operator: In
9+
values:
10+
- "true"
11+
12+
replica:
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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
locals {
2+
name = "redis"
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+
custom_credentials_enabled = true
12+
custom_credentials_config = {
13+
password = "aajdhgduy3873683dh"
14+
}
15+
}
16+
17+
module "azure" {
18+
source = "squareops/redis/kubernetes//provider/azure"
19+
resource_group_name = "prod-skaf-rg"
20+
resource_group_location = local.region
21+
environment = local.environment
22+
name = local.name
23+
store_password_to_secret_manager = local.store_password_to_secret_manager
24+
custom_credentials_enabled = local.custom_credentials_enabled
25+
custom_credentials_config = local.custom_credentials_config
26+
}
27+
28+
module "redis" {
29+
source = "squareops/redis/kubernetes"
30+
redis_config = {
31+
name = local.name
32+
values_yaml = file("./helm/values.yaml")
33+
environment = local.environment
34+
architecture = "replication"
35+
slave_volume_size = "10Gi"
36+
master_volume_size = "10Gi"
37+
storage_class_name = "infra-service-sc"
38+
slave_replica_count = 2
39+
store_password_to_secret_manager = local.store_password_to_secret_manager
40+
secret_provider_type = "azure"
41+
}
42+
grafana_monitoring_enabled = true
43+
custom_credentials_enabled = local.custom_credentials_enabled
44+
custom_credentials_config = local.custom_credentials_config
45+
redis_password = local.custom_credentials_enabled ? "" : module.azure.redis_password
46+
}

examples/complete/azure/output.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "redis_endpoints" {
2+
description = "Redis endpoints in the Kubernetes cluster."
3+
value = module.redis.redis_endpoints
4+
}
5+
6+
output "redis_credential" {
7+
description = "Redis credentials used for accessing the database."
8+
value = local.store_password_to_secret_manager ? null : module.redis.redis_credential
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 = "prod-skaf-aks"
7+
resource_group_name = "prod-skaf-rg"
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+
}

provider/azure/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Azure Terraform Redis Kubernetes Module
2+
3+
<!-- BEGIN_TF_DOCS -->
4+
## Requirements
5+
6+
No requirements.
7+
8+
## Providers
9+
10+
| Name | Version |
11+
|------|---------|
12+
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | n/a |
13+
| <a name="provider_random"></a> [random](#provider\_random) | n/a |
14+
15+
## Modules
16+
17+
No modules.
18+
19+
## Resources
20+
21+
| Name | Type |
22+
|------|------|
23+
| [azurerm_key_vault.redis-secret](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/key_vault) | resource |
24+
| [azurerm_key_vault_secret.redis-secret](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/key_vault_secret) | resource |
25+
| [random_password.redis_password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
26+
| [azurerm_client_config.current](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/client_config) | data source |
27+
| [azurerm_subscription.current](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/subscription) | data source |
28+
29+
## Inputs
30+
31+
| Name | Description | Type | Default | Required |
32+
|------|-------------|------|---------|:--------:|
33+
| <a name="input_custom_credentials_config"></a> [custom\_credentials\_config](#input\_custom\_credentials\_config) | Specify the configuration settings for Redis to pass custom credentials during creation. | `any` | <pre>{<br> "password": ""<br>}</pre> | no |
34+
| <a name="input_custom_credentials_enabled"></a> [custom\_credentials\_enabled](#input\_custom\_credentials\_enabled) | Specifies whether to enable custom credentials for Redis. | `bool` | `false` | no |
35+
| <a name="input_environment"></a> [environment](#input\_environment) | Environment in which the infrastructure is being deployed (e.g., production, staging, development) | `string` | `"test"` | no |
36+
| <a name="input_name"></a> [name](#input\_name) | Name identifier for module to be added as suffix to resources | `string` | `"test"` | no |
37+
| <a name="input_resource_group_location"></a> [resource\_group\_location](#input\_resource\_group\_location) | Azure resource group location | `string` | `""` | no |
38+
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | Azure resource group name | `string` | `""` | no |
39+
| <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 |
40+
41+
## Outputs
42+
43+
| Name | Description |
44+
|------|-------------|
45+
| <a name="output_redis_password"></a> [redis\_password](#output\_redis\_password) | n/a |
46+
<!-- END_TF_DOCS -->

provider/azure/main.tf

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
data "azurerm_client_config" "current" {}
2+
3+
data "azurerm_subscription" "current" {}
4+
5+
resource "random_password" "redis_password" {
6+
count = var.custom_credentials_enabled ? 0 : 1
7+
length = 20
8+
special = false
9+
}
10+
11+
resource "azurerm_key_vault" "redis-secret" {
12+
count = var.store_password_to_secret_manager ? 1 : 0
13+
name = format("%s-%s-%s", var.environment, var.name, "key-vault")
14+
resource_group_name = var.resource_group_name
15+
location = var.resource_group_location
16+
sku_name = "standard"
17+
tenant_id = data.azurerm_client_config.current.tenant_id
18+
enabled_for_disk_encryption = true
19+
soft_delete_retention_days = 7
20+
21+
access_policy {
22+
tenant_id = data.azurerm_client_config.current.tenant_id
23+
object_id = data.azurerm_client_config.current.object_id
24+
key_permissions = [
25+
"Get",
26+
"List",
27+
]
28+
secret_permissions = [
29+
"Set",
30+
"Get",
31+
"List",
32+
"Delete",
33+
"Purge",
34+
]
35+
}
36+
}
37+
38+
resource "azurerm_key_vault_secret" "redis-secret" {
39+
count = var.store_password_to_secret_manager ? 1 : 0
40+
depends_on = [azurerm_key_vault.redis-secret[0]]
41+
name = format("%s-%s-%s", var.environment, var.name, "secret")
42+
value = var.custom_credentials_enabled ? jsonencode(
43+
{
44+
"redis_username" : "root",
45+
"redis_password" : "${var.custom_credentials_config.password}"
46+
47+
}) : jsonencode(
48+
{
49+
"redis_username" : "root",
50+
"redis_password" : "${random_password.redis_password[0].result}"
51+
})
52+
content_type = "application/json"
53+
key_vault_id = azurerm_key_vault.redis-secret[0].id
54+
}
55+
56+
output "redis_password" {
57+
value = var.custom_credentials_enabled ? null : nonsensitive(random_password.redis_password[0].result)
58+
}

0 commit comments

Comments
 (0)