trying diff technique

This commit is contained in:
Tom Archer 2024-11-01 08:25:36 -07:00 committed by lonegunmanb
parent ccffe42995
commit d9ceb6ca3d
3 changed files with 55 additions and 118 deletions

View File

@ -1,79 +1,32 @@
resource "random_pet" "rg_name" { resource "azurerm_resource_group" "az_rg" {
prefix = var.resource_group_name_prefix name = var.az_rg_name
location = var.location
} }
resource "azurerm_resource_group" "rg" { resource "azurerm_storage_account" "az_sa" {
location = var.resource_group_location name = var.az_sa_name
name = random_pet.rg_name.id resource_group_name = azurerm_resource_group.az_rg.name
location = azurerm_resource_group.az_rg.location
account_tier = var.az_sa_account_tier
account_replication_type = var.az_sa_account_replication_type
} }
resource "random_string" "unique_id" { resource "azurerm_app_service_plan" "az_asp" {
length = 8 name = var.az_asp_name
lower = true location = azurerm_resource_group.az_rg.location
numeric = false resource_group_name = azurerm_resource_group.az_rg.name
special = false
upper = false
}
resource "azurerm_storage_account" "storageAccount" { sku {
name = random_string.unique_id.result tier = var.az_asp_sku_tier
resource_group_name = azurerm_resource_group.rg.name size = "S1"
location = azurerm_resource_group.rg.location
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_service_plan" "hostingPlan" {
name = random_string.unique_id.result
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
os_type = "Linux"
sku_name = "P1v2"
}
resource "azurerm_linux_function_app" "example" {
name = "fnapp${random_string.unique_id.result}"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
service_plan_id = azurerm_service_plan.hostingPlan.id
storage_account_name = azurerm_storage_account.storageAccount.name
storage_account_access_key = azurerm_storage_account.storageAccount.primary_access_key
identity {
type = "SystemAssigned"
}
site_config {
application_stack {
python_version = "3.9"
}
} }
} }
resource "azurerm_function_app_function" "example" { resource "azurerm_function_app" "az_fa" {
name = "fnappfcn${random_string.unique_id.result}" name = var.az_fa_name
function_app_id = azurerm_linux_function_app.example.id location = azurerm_resource_group.az_rg.location
language = "Python" resource_group_name = azurerm_resource_group.az_rg.name
test_data = jsonencode({ app_service_plan_id = azurerm_app_service_plan.az_asp.id
"name" = "Azure" storage_account_name = azurerm_storage_account.az_sa.name
}) storage_account_access_key = azurerm_storage_account.az_sa.primary_access_key
config_json = jsonencode({
"bindings" = [
{
"authLevel" = "function"
"direction" = "in"
"methods" = [
"get",
"post",
]
"name" = "req"
"type" = "httpTrigger"
},
{
"direction" = "out"
"name" = "$return"
"type" = "http"
},
]
})
} }

View File

@ -1,19 +0,0 @@
output "resource_group_name" {
value = azurerm_resource_group.rg.name
}
output "storage_account_name" {
value = azurerm_storage_account.storageAccount.name
}
output "app_service_plan_name" {
value = azurerm_service_plan.hostingPlan.name
}
output "function_app_name" {
value = azurerm_function_app.functionApp.name
}
output "application_insights_name" {
value = azurerm_application_insights.applicationInsights.name
}

View File

@ -1,37 +1,40 @@
variable "resource_group_name_prefix" { variable "az_rg_name" {
type = string type = string
default = "rg" default = "azure-functions-example-rg"
description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription."
} }
variable "resource_group_location" { variable "location" {
type = string type = string
default = "eastus" default = "East US"
description = "Location of the resource group."
} }
variable "appName" { variable "az_sa_account_tier" {
type = string type = string
default = "fnapp" default = "Standard"
description = "The name of the function app that you wish to create."
} }
variable "storageAccountType" { variable "az_sa_account_replication_type" {
type = string type = string
default = "Standard_LRS" default = "LRS"
validation { }
condition = contains(["Standard_LRS", "Standard_GRS", "Standard_RAGRS"], var.storageAccountType)
error_message = "Must be one of Standard_LRS, Standard_GRS, Standard_RAGRS" variable "az_sa_name" {
} type = string
description = "Storage Account type" default = "examplefunctionssa"
}
variable "az_asp_name" {
type = string
default = "example-functions-service-plan"
}
variable "az_asp_sku_tier" {
type = string
default = "Standard"
}
variable "az_fa_name" {
type = string
default = "example-functions-app"
} }
variable "runtime" {
type = string
default = "node"
validation {
condition = contains(["node", "dotnet", "java"], var.runtime)
error_message = "Must be one of node, dotnet, java"
}
description = "The language worker runtime to load in the function app."
}