Skip to content

Commit

Permalink
feat: Added redis secrets (#2086)
Browse files Browse the repository at this point in the history
added redis secrets
  • Loading branch information
mamari90 authored May 28, 2024
1 parent dfc5350 commit 3d74197
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/domains/mock-common/02_security.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
data "azurerm_redis_cache" "redis_cache" {
name = "${var.prefix}-${var.env_short}-redis"
resource_group_name = "${var.prefix}-${var.env_short}-data-rg"
}

data "azurerm_redis_cache" "redis_cache_ha" {
count = var.redis_ha_enabled ? 1 : 0
name = "${var.prefix}-${var.env_short}-${var.location_short}-redis"
resource_group_name = "${var.prefix}-${var.env_short}-data-rg"
}


resource "azurerm_resource_group" "sec_rg" {
name = "${local.product}-${var.domain}-sec-rg"
location = var.location
Expand Down Expand Up @@ -80,3 +92,22 @@ resource "azurerm_key_vault_secret" "mocker_cosmosdb_connection_string" {

key_vault_id = module.key_vault.id
}

resource "azurerm_key_vault_secret" "redis_password" {
name = "redis-password"
value = var.redis_ha_enabled ? data.azurerm_redis_cache.redis_cache_ha[0].primary_access_key : data.azurerm_redis_cache.redis_cache.primary_access_key

content_type = "text/plain"

key_vault_id = module.key_vault.id
}


resource "azurerm_key_vault_secret" "redis_hostname" {
name = "redis-hostname"
value = var.redis_ha_enabled ? data.azurerm_redis_cache.redis_cache_ha[0].hostname : data.azurerm_redis_cache.redis_cache.hostname

content_type = "text/plain"

key_vault_id = module.key_vault.id
}
7 changes: 7 additions & 0 deletions src/domains/mock-common/99_variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,10 @@ variable "cosmosdb_mongodb_max_throughput" {
default = 5000
}


variable "redis_ha_enabled" {
type = bool
description = "(Required) If true, enables the usage of HA redis instance"
default = false
}

5 changes: 5 additions & 0 deletions src/domains/mock-common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
| [azurerm_key_vault_access_policy.azdevops_iac_policy](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/key_vault_access_policy) | resource |
| [azurerm_key_vault_secret.ai_connection_string](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/key_vault_secret) | resource |
| [azurerm_key_vault_secret.mocker_cosmosdb_connection_string](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/key_vault_secret) | resource |
| [azurerm_key_vault_secret.redis_hostname](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/key_vault_secret) | resource |
| [azurerm_key_vault_secret.redis_password](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/key_vault_secret) | resource |
| [azurerm_private_dns_a_record.ingress](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_dns_a_record) | resource |
| [azurerm_resource_group.mock_ec_rg](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) | resource |
| [azurerm_resource_group.mock_payment_gateway_rg](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) | resource |
Expand All @@ -59,6 +61,8 @@
| [azurerm_monitor_action_group.slack](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/monitor_action_group) | data source |
| [azurerm_private_dns_zone.cosmos](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/private_dns_zone) | data source |
| [azurerm_private_dns_zone.internal](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/private_dns_zone) | data source |
| [azurerm_redis_cache.redis_cache](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/redis_cache) | data source |
| [azurerm_redis_cache.redis_cache_ha](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/redis_cache) | data source |
| [azurerm_resource_group.identity_rg](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/resource_group) | data source |
| [azurerm_resource_group.monitor_rg](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/resource_group) | data source |
| [azurerm_subnet.aks_subnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/subnet) | data source |
Expand Down Expand Up @@ -104,6 +108,7 @@
| <a name="input_mocker_cosmosdb_params"></a> [mocker\_cosmosdb\_params](#input\_mocker\_cosmosdb\_params) | n/a | <pre>object({<br> kind = string<br> capabilities = list(string)<br> offer_type = string<br> server_version = string<br> consistency_policy = object({<br> consistency_level = string<br> max_interval_in_seconds = number<br> max_staleness_prefix = number<br> })<br> main_geo_location_zone_redundant = bool<br> enable_free_tier = bool<br> additional_geo_locations = list(object({<br> location = string<br> failover_priority = number<br> zone_redundant = bool<br> }))<br> private_endpoint_enabled = bool<br> public_network_access_enabled = bool<br> is_virtual_network_filter_enabled = bool<br> backup_continuous_enabled = bool<br> container_default_ttl = number<br> })</pre> | n/a | yes |
| <a name="input_monitor_resource_group_name"></a> [monitor\_resource\_group\_name](#input\_monitor\_resource\_group\_name) | Monitor resource group name | `string` | n/a | yes |
| <a name="input_prefix"></a> [prefix](#input\_prefix) | n/a | `string` | n/a | yes |
| <a name="input_redis_ha_enabled"></a> [redis\_ha\_enabled](#input\_redis\_ha\_enabled) | (Required) If true, enables the usage of HA redis instance | `bool` | `false` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | n/a | `map(any)` | <pre>{<br> "CreatedBy": "Terraform"<br>}</pre> | no |

## Outputs
Expand Down

0 comments on commit 3d74197

Please sign in to comment.