|
| 1 | +# Resource Group |
| 2 | +resource "azurerm_resource_group" "rg" { |
| 3 | + name = var.resource_group_name |
| 4 | + location = var.location |
| 5 | + |
| 6 | + # Output the resource group name |
| 7 | + provisioner "local-exec" { |
| 8 | + command = "echo Resource Group: ${self.name}" |
| 9 | + } |
| 10 | +} |
| 11 | + |
| 12 | +# Storage Account |
| 13 | +resource "azurerm_storage_account" "storage" { |
| 14 | + name = var.storage_account_name |
| 15 | + resource_group_name = azurerm_resource_group.rg.name |
| 16 | + location = azurerm_resource_group.rg.location |
| 17 | + account_tier = "Standard" |
| 18 | + account_replication_type = "LRS" |
| 19 | + |
| 20 | + depends_on = [azurerm_resource_group.rg] |
| 21 | + |
| 22 | + # Output the storage account name |
| 23 | + provisioner "local-exec" { |
| 24 | + command = "echo Storage Account: ${self.name}" |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +# Blob Container for Input Files |
| 29 | +resource "azurerm_storage_container" "input_container" { |
| 30 | + name = "input" |
| 31 | + storage_account_name = azurerm_storage_account.storage.name |
| 32 | + container_access_type = "private" |
| 33 | + |
| 34 | + depends_on = [azurerm_storage_account.storage] |
| 35 | + |
| 36 | + # Output the container name |
| 37 | + provisioner "local-exec" { |
| 38 | + command = "echo Input Container: ${self.name}" |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +# Blob Container for Output Files |
| 43 | +resource "azurerm_storage_container" "output_container" { |
| 44 | + name = "output" |
| 45 | + storage_account_name = azurerm_storage_account.storage.name |
| 46 | + container_access_type = "private" |
| 47 | + |
| 48 | + depends_on = [azurerm_storage_account.storage] |
| 49 | + |
| 50 | + # Output the container name |
| 51 | + provisioner "local-exec" { |
| 52 | + command = "echo Output Container: ${self.name}" |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +# Azure Function App |
| 57 | +resource "azurerm_function_app" "function_app" { |
| 58 | + name = var.function_app_name |
| 59 | + location = azurerm_resource_group.rg.location |
| 60 | + resource_group_name = azurerm_resource_group.rg.name |
| 61 | + storage_account_name = azurerm_storage_account.storage.name |
| 62 | + storage_account_access_key = azurerm_storage_account.storage.primary_access_key |
| 63 | + app_service_plan_id = azurerm_service_plan.asp.id |
| 64 | + os_type = "linux" |
| 65 | + |
| 66 | + app_settings = { |
| 67 | + FUNCTIONS_WORKER_RUNTIME = "python" |
| 68 | + } |
| 69 | + |
| 70 | + depends_on = [azurerm_service_plan.asp] |
| 71 | + |
| 72 | + # Output the function app name |
| 73 | + provisioner "local-exec" { |
| 74 | + command = "echo Function App: ${self.name}" |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +# Service Plan |
| 79 | +resource "azurerm_service_plan" "asp" { |
| 80 | + name = var.app_service_plan_name |
| 81 | + location = azurerm_resource_group.rg.location |
| 82 | + resource_group_name = azurerm_resource_group.rg.name |
| 83 | + os_type = "Linux" |
| 84 | + sku_name = "Y1" # Consumption plan |
| 85 | + |
| 86 | + depends_on = [azurerm_resource_group.rg] |
| 87 | + |
| 88 | + # Output the service plan name |
| 89 | + provisioner "local-exec" { |
| 90 | + command = "echo Service Plan: ${self.name}" |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +# Application Insights |
| 95 | +resource "azurerm_application_insights" "appinsights" { |
| 96 | + name = var.app_insights_name |
| 97 | + location = azurerm_resource_group.rg.location |
| 98 | + resource_group_name = azurerm_resource_group.rg.name |
| 99 | + application_type = "web" |
| 100 | + |
| 101 | + depends_on = [azurerm_resource_group.rg] |
| 102 | + |
| 103 | + # Output the application insights name |
| 104 | + provisioner "local-exec" { |
| 105 | + command = "echo Application Insights: ${self.name}" |
| 106 | + } |
| 107 | +} |
| 108 | + |
| 109 | +# Log Analytics Workspace |
| 110 | +resource "azurerm_log_analytics_workspace" "loganalytics" { |
| 111 | + name = var.log_analytics_workspace_name |
| 112 | + location = azurerm_resource_group.rg.location |
| 113 | + resource_group_name = azurerm_resource_group.rg.name |
| 114 | + sku = "PerGB2018" |
| 115 | + |
| 116 | + depends_on = [azurerm_resource_group.rg] |
| 117 | + |
| 118 | + # Output the log analytics workspace name |
| 119 | + provisioner "local-exec" { |
| 120 | + command = "echo Log Analytics Workspace: ${self.name}" |
| 121 | + } |
| 122 | +} |
| 123 | + |
| 124 | +# Key Vault |
| 125 | +resource "azurerm_key_vault" "keyvault" { |
| 126 | + name = var.key_vault_name |
| 127 | + location = azurerm_resource_group.rg.location |
| 128 | + resource_group_name = azurerm_resource_group.rg.name |
| 129 | + tenant_id = data.azurerm_client_config.current.tenant_id |
| 130 | + sku_name = "standard" |
| 131 | + |
| 132 | + depends_on = [azurerm_resource_group.rg] |
| 133 | + |
| 134 | + # Output the key vault name |
| 135 | + provisioner "local-exec" { |
| 136 | + command = "echo Key Vault: ${self.name}" |
| 137 | + } |
| 138 | +} |
| 139 | + |
| 140 | +# Data source to get tenant ID |
| 141 | +data "azurerm_client_config" "current" {} |
0 commit comments