am trying to create the redis cache server and update the redis hostname & Primary access key to Azure function app setting to connect the azure function app to connect redis server.
below is my code
Redi Cache server:
resource “azurerm_redis_cache” “redis” {
name = var.redis_cache_name
location = var.location
resource_group_name = var.resource_group_name
capacity = var.capacity
family = var.family
sku_name = var.sku_name
enable_non_ssl_port = false
redis_configuration {
maxmemory_policy = “allkeys-lru” # Eviction policy
maxmemory_reserved = “30”
maxfragmentationmemory_reserved = “30”
}
}
output “redis_hostname” {
value = azurerm_redis_cache.redis.name
}
output “redis_primary_key” {
value = azurerm_redis_cache.redis.primary_access_key
}
Main.tf:
module “redis_cache” {
source = “./modules/redis_cache”
redis_cache_name = var.redis_cache_name
location = var.location
resource_group_name = module.resource_group.web_app_resource_group_id
capacity = var.redis_capacity
family = var.redis_family
sku_name = var.redis_sku_name
redis_subnet_id = module.network.api_plink_subnet_id
vnet_id = module.network.vnet_id
}
output “redis_cache” {
value = {
hostname = module.redis_cache.redis_hostname
key = module.redis_cache.redis_primary_access_key
}
}
#App Service
module “private_web_app” {
source = “./modules/private_web_app”
private_api_app_name = var.api_app_name
resource_group_name = module.resource_group.web_app_resource_group_id
location = var.location
app_service_plan_id = module.app_service_plan.app_service_plan_id
private_api_subnet_id = module.network.private_api_subnet_id
cosmosdb_account_endpoint = module.database.cosmosdb_account_endpoint
cosmosdb_account_key = module.database.cosmosdb_account_key
redis_hostname = module.redis_cache.redis_hostname
redis_primary_key = module.redis_cache.redis_primary_access_key
vnet_id = module.network.vnet_id
}
getting below error during the validation
Error: Unsupported attribute
│
│ on main.tf line 67, in module “private_web_app”:
│ 67: redis_hostname = module.redis_cache.redis_hostname
│ ├────────────────
│ │ module.redis_cache is a object
│
│ This object does not have an attribute named “redis_hostname”.
╵
╷
│ Error: Unsupported attribute
│
│ on main.tf line 68, in module “private_web_app”:
│ 68: redis_primary_key = module.redis_cache.redis_primary_access_key
│ ├────────────────
│ │ module.redis_cache is a object
│
│ This object does not have an attribute named “redis_primary_access_key”.