91 lines
3.3 KiB
HCL
91 lines
3.3 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 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. Custom container images require a Dedicated (or Premium)
|
|
# plan - Consumption/Flex Consumption plans don't support bring-your-own-container.
|
|
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 = var.asp_sku_name
|
|
os_type = "Linux"
|
|
}
|
|
|
|
# Create a function app that runs the prebuilt container image straight from Docker Hub
|
|
resource "azurerm_linux_function_app" "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_account_name = azurerm_storage_account.example.name
|
|
storage_account_access_key = azurerm_storage_account.example.primary_access_key
|
|
|
|
site_config {
|
|
application_insights_connection_string = azurerm_application_insights.example.connection_string
|
|
|
|
application_stack {
|
|
docker {
|
|
registry_url = "https://index.docker.io"
|
|
image_name = var.container_image_name
|
|
image_tag = var.container_image_tag
|
|
}
|
|
}
|
|
}
|
|
|
|
app_settings = {
|
|
"OLLAMA_HOST" = "http://harbor.freshbrewed.science:11444"
|
|
"OLLAMA_MODEL" = "gemma4:e4b"
|
|
"JOKE_PROMPT" = "tell me a dad joke about programming"
|
|
"PORT" = "80"
|
|
"WEBSITES_PORT" = "80"
|
|
"WEBSITES_ENABLE_APP_SERVICE_STORAGE" = "false"
|
|
}
|
|
}
|
|
|