103 lines
3.7 KiB
HCL
103 lines
3.7 KiB
HCL
|
|
# Create a random pet to generate a unique resource group name
|
|
resource "random_pet" "rg_name" {
|
|
prefix = var.resource_group_name_prefix
|
|
}
|
|
|
|
# Create a resource group
|
|
resource "azurerm_resource_group" "example" {
|
|
location = var.resource_group_location
|
|
name = random_pet.rg_name.id
|
|
}
|
|
|
|
# Random String for unique naming of resources
|
|
resource "random_string" "name" {
|
|
length = 8
|
|
special = false
|
|
upper = false
|
|
lower = true
|
|
numeric = false
|
|
}
|
|
|
|
# Create a storage account
|
|
resource "azurerm_storage_account" "example" {
|
|
name = coalesce(var.sa_name, random_string.name.result)
|
|
resource_group_name = azurerm_resource_group.example.name
|
|
location = azurerm_resource_group.example.location
|
|
account_tier = var.sa_account_tier
|
|
account_replication_type = var.sa_account_replication_type
|
|
}
|
|
|
|
# Create a storage container
|
|
resource "azurerm_storage_container" "example" {
|
|
name = "example-flexcontainer"
|
|
storage_account_id = azurerm_storage_account.example.id
|
|
container_access_type = "private"
|
|
}
|
|
|
|
# Create a Log Analytics workspace for Application Insights
|
|
resource "azurerm_log_analytics_workspace" "example" {
|
|
name = coalesce(var.ws_name, random_string.name.result)
|
|
location = azurerm_resource_group.example.location
|
|
resource_group_name = azurerm_resource_group.example.name
|
|
sku = "PerGB2018"
|
|
retention_in_days = 30
|
|
}
|
|
|
|
# Create an Application Insights instance for monitoring
|
|
resource "azurerm_application_insights" "example" {
|
|
name = coalesce(var.ai_name, random_string.name.result)
|
|
location = azurerm_resource_group.example.location
|
|
resource_group_name = azurerm_resource_group.example.name
|
|
application_type = "web"
|
|
workspace_id = azurerm_log_analytics_workspace.example.id
|
|
}
|
|
|
|
# Create a service plan
|
|
resource "azurerm_service_plan" "example" {
|
|
name = coalesce(var.asp_name, random_string.name.result)
|
|
resource_group_name = azurerm_resource_group.example.name
|
|
location = azurerm_resource_group.example.location
|
|
sku_name = "FC1"
|
|
os_type = "Linux"
|
|
}
|
|
|
|
data "archive_file" "function_app" {
|
|
type = "zip"
|
|
source_dir = "${path.module}/.."
|
|
output_path = "${path.module}/function_app.zip"
|
|
excludes = [".git", ".gitea", "iac", "helm-chart", ".terraform*", ".vscode"]
|
|
}
|
|
|
|
# Create a function app
|
|
resource "azurerm_function_app_flex_consumption" "example" {
|
|
name = coalesce(var.fa_name, random_string.name.result)
|
|
resource_group_name = azurerm_resource_group.example.name
|
|
location = azurerm_resource_group.example.location
|
|
service_plan_id = azurerm_service_plan.example.id
|
|
|
|
storage_container_type = "blobContainer"
|
|
storage_container_endpoint = "${azurerm_storage_account.example.primary_blob_endpoint}${azurerm_storage_container.example.name}"
|
|
storage_authentication_type = "StorageAccountConnectionString"
|
|
storage_access_key = azurerm_storage_account.example.primary_access_key
|
|
runtime_name = var.runtime_name
|
|
runtime_version = var.runtime_version
|
|
maximum_instance_count = 50
|
|
instance_memory_in_mb = 2048
|
|
|
|
zip_deploy_file = data.archive_file.function_app.output_path
|
|
|
|
site_config {
|
|
application_insights_connection_string = azurerm_application_insights.example.connection_string
|
|
}
|
|
|
|
app_settings = {
|
|
"OLLAMA_HOST" = "http://harbor.freshbrewed.science:11444"
|
|
"OLLAMA_MODEL" = "gemma4:e4b"
|
|
"JOKE_PROMPT" = "tell me a dad joke about programming"
|
|
"PORT" = "80"
|
|
"SCM_DO_BUILD_DURING_DEPLOYMENT" = "true"
|
|
"ENABLE_ORYX_BUILD" = "true"
|
|
}
|
|
}
|