Initial put
This commit is contained in:
parent
f4e809b02e
commit
1b0212fb94
25
quickstart/101-azure-functions/README.md
Normal file
25
quickstart/101-azure-functions/README.md
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# Azure Function App
|
||||||
|
This template deploys an Azure Function App.
|
||||||
|
|
||||||
|
## Terraform resource types
|
||||||
|
|
||||||
|
- [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet)
|
||||||
|
- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
|
||||||
|
- [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string)
|
||||||
|
- [azurerm_storage_account](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account)
|
||||||
|
- [azurerm_app_service_plan](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/app_service_plan)
|
||||||
|
- [azurerm_function_app](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/function_app)
|
||||||
|
- [azurerm_application_insights](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/application_insights)
|
||||||
|
|
||||||
|
## Variables
|
||||||
|
|
||||||
|
| Name | Description | Default value |
|
||||||
|
|-|-|-|
|
||||||
|
| `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg |
|
||||||
|
| `resource_group_location` | Location of the resource group. | eastus |
|
||||||
|
| `appName` | The name of the function app that you wish to create. | fnapp${random_string.unique_id.result} |
|
||||||
|
| `storageAccountType` | Storage Account type. Possible values are: Standard_LRS, Standard_GRS, Standard_RAGRS. | Standard_LRS |
|
||||||
|
| `appInsightsLocation` | Location for Application Insights. | "" |
|
||||||
|
| `runtime` | The language worker runtime to load in the function app. Possible values are: node, dotnet, java. | node |
|
||||||
|
|
||||||
|
## Example
|
82
quickstart/101-azure-functions/main.tf
Normal file
82
quickstart/101-azure-functions/main.tf
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
resource "random_pet" "rg_name" {
|
||||||
|
prefix = var.resource_group_name_prefix
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_resource_group" "rg" {
|
||||||
|
location = var.resource_group_location
|
||||||
|
name = random_pet.rg_name.id
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "random_string" "unique_id" {
|
||||||
|
length = 8
|
||||||
|
special = false
|
||||||
|
}
|
||||||
|
|
||||||
|
locals {
|
||||||
|
functionAppName = var.appName
|
||||||
|
hostingPlanName = var.appName
|
||||||
|
applicationInsightsName = var.appName
|
||||||
|
storageAccountName = "${random_string.unique_id.result}azfunctions"
|
||||||
|
functionWorkerRuntime = var.runtime
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_storage_account" "storageAccount" {
|
||||||
|
name = local.storageAccountName
|
||||||
|
location = azurerm_resource_group.rg.location
|
||||||
|
resource_group_name = azurerm_resource_group.rg.name
|
||||||
|
account_tier = "Standard"
|
||||||
|
account_replication_type = var.storageAccountType
|
||||||
|
|
||||||
|
enable_https_traffic_only = true
|
||||||
|
allow_blob_public_access = false
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_app_service_plan" "hostingPlan" {
|
||||||
|
name = local.hostingPlanName
|
||||||
|
location = azurerm_resource_group.rg.location
|
||||||
|
resource_group_name = azurerm_resource_group.rg.name
|
||||||
|
kind = "FunctionApp"
|
||||||
|
sku {
|
||||||
|
tier = "Dynamic"
|
||||||
|
size = "Y1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_function_app" "functionApp" {
|
||||||
|
name = local.functionAppName
|
||||||
|
location = azurerm_resource_group.rg.location
|
||||||
|
resource_group_name = azurerm_resource_group.rg.name
|
||||||
|
app_service_plan_id = azurerm_app_service_plan.hostingPlan.id
|
||||||
|
storage_account_name = azurerm_storage_account.storageAccount.name
|
||||||
|
storage_account_access_key = azurerm_storage_account.storageAccount.primary_access_key
|
||||||
|
os_type = "linux"
|
||||||
|
version = "~4"
|
||||||
|
|
||||||
|
app_settings = {
|
||||||
|
"AzureWebJobsStorage" = "DefaultEndpointsProtocol=https;AccountName=${azurerm_storage_account.storageAccount.name};EndpointSuffix=${azurerm_storage_account.storageAccount.primary_blob_endpoint};AccountKey=${azurerm_storage_account.storageAccount.primary_access_key}"
|
||||||
|
"WEBSITE_CONTENTAZUREFILECONNECTIONSTRING" = "DefaultEndpointsProtocol=https;AccountName=${azurerm_storage_account.storageAccount.name};EndpointSuffix=${azurerm_storage_account.storageAccount.primary_blob_endpoint};AccountKey=${azurerm_storage_account.storageAccount.primary_access_key}"
|
||||||
|
"WEBSITE_CONTENTSHARE" = lower(local.functionAppName)
|
||||||
|
"FUNCTIONS_EXTENSION_VERSION" = "~4"
|
||||||
|
"WEBSITE_NODE_DEFAULT_VERSION" = "~14"
|
||||||
|
"APPINSIGHTS_INSTRUMENTATIONKEY" = azurerm_application_insights.applicationInsights.instrumentation_key
|
||||||
|
"FUNCTIONS_WORKER_RUNTIME" = local.functionWorkerRuntime
|
||||||
|
}
|
||||||
|
|
||||||
|
identity {
|
||||||
|
type = "SystemAssigned"
|
||||||
|
}
|
||||||
|
|
||||||
|
site_config {
|
||||||
|
ftps_state = "FtpsOnly"
|
||||||
|
min_tls_version = "1.2"
|
||||||
|
}
|
||||||
|
|
||||||
|
https_only = true
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_application_insights" "applicationInsights" {
|
||||||
|
name = local.applicationInsightsName
|
||||||
|
location = var.appInsightsLocation
|
||||||
|
resource_group_name = azurerm_resource_group.rg.name
|
||||||
|
application_type = "web"
|
||||||
|
}
|
19
quickstart/101-azure-functions/outputs.tf
Normal file
19
quickstart/101-azure-functions/outputs.tf
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
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_app_service_plan.hostingPlan.name
|
||||||
|
}
|
||||||
|
|
||||||
|
output "function_app_name" {
|
||||||
|
value = azurerm_function_app.functionApp.name
|
||||||
|
}
|
||||||
|
|
||||||
|
output "application_insights_name" {
|
||||||
|
value = azurerm_application_insights.applicationInsights.name
|
||||||
|
}
|
18
quickstart/101-azure-functions/providers.tf
Normal file
18
quickstart/101-azure-functions/providers.tf
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
terraform {
|
||||||
|
required_version = ">=1.0"
|
||||||
|
|
||||||
|
required_providers {
|
||||||
|
azurerm = {
|
||||||
|
source = "hashicorp/azurerm"
|
||||||
|
version = "~>3.0"
|
||||||
|
}
|
||||||
|
random = {
|
||||||
|
source = "hashicorp/random"
|
||||||
|
version = "~>3.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
provider "azurerm" {
|
||||||
|
features {}
|
||||||
|
}
|
42
quickstart/101-azure-functions/variables.tf
Normal file
42
quickstart/101-azure-functions/variables.tf
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
variable "resource_group_name_prefix" {
|
||||||
|
type = string
|
||||||
|
default = "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" {
|
||||||
|
type = string
|
||||||
|
default = "eastus"
|
||||||
|
description = "Location of the resource group."
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "appName" {
|
||||||
|
type = string
|
||||||
|
default = "fnapp${random_string.unique_id.result}"
|
||||||
|
description = "The name of the function app that you wish to create."
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "storageAccountType" {
|
||||||
|
type = string
|
||||||
|
default = "Standard_LRS"
|
||||||
|
validation {
|
||||||
|
condition = contains(["Standard_LRS", "Standard_GRS", "Standard_RAGRS"], var.storageAccountType)
|
||||||
|
error_message = "Must be one of Standard_LRS, Standard_GRS, Standard_RAGRS"
|
||||||
|
}
|
||||||
|
description = "Storage Account type"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "appInsightsLocation" {
|
||||||
|
type = string
|
||||||
|
description = "Location for Application Insights"
|
||||||
|
}
|
||||||
|
|
||||||
|
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."
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user