From e32966e242d61fcde6131081d503ce530533de07 Mon Sep 17 00:00:00 2001 From: Xiaxin <92154856+xiaxyi@users.noreply.github.com> Date: Wed, 16 Nov 2022 13:56:21 +0800 Subject: [PATCH] Adding guidance for function app (#116) * adding guidance for function app --- .../201-function-app/.terraform-docs.yml | 11 +++ quickstart/201-function-app/.tflint.hcl | 71 +++++++++++++++++++ quickstart/201-function-app/main.tf | 47 ++++++++++++ quickstart/201-function-app/providers.tf | 13 ++++ .../201-function-app/readme.html.markdown | 41 +++++++++++ quickstart/201-function-app/variables.tf | 10 +++ 6 files changed, 193 insertions(+) create mode 100644 quickstart/201-function-app/.terraform-docs.yml create mode 100644 quickstart/201-function-app/.tflint.hcl create mode 100644 quickstart/201-function-app/main.tf create mode 100644 quickstart/201-function-app/providers.tf create mode 100644 quickstart/201-function-app/readme.html.markdown create mode 100644 quickstart/201-function-app/variables.tf diff --git a/quickstart/201-function-app/.terraform-docs.yml b/quickstart/201-function-app/.terraform-docs.yml new file mode 100644 index 00000000..2c473461 --- /dev/null +++ b/quickstart/201-function-app/.terraform-docs.yml @@ -0,0 +1,11 @@ +formatter: "markdown table" + +content: |- + {{ .Resources }} + {{ .Inputs }} + {{ .Providers }} + {{ .Requirements }} + +output: + file: readme.html.markdown + mode: inject diff --git a/quickstart/201-function-app/.tflint.hcl b/quickstart/201-function-app/.tflint.hcl new file mode 100644 index 00000000..b5e1ed23 --- /dev/null +++ b/quickstart/201-function-app/.tflint.hcl @@ -0,0 +1,71 @@ +/* +THIS FILE IS GENERATED BY TFMOD-SCAFFOLD, PLEASE DO NOT MODIFY IT. +IF YOU WANT TO USE A CUSTOMIZED CONFIGURATION, PLEASE CREATE YOUR OWN AND +SET THIS FILE'S PATH TO $TFLINT_CONFIG ENVVIRONMENT VARIABLE. +*/ + +plugin "azurerm" { + enabled = true + version = "0.18.0" + source = "github.com/terraform-linters/tflint-ruleset-azurerm" +} + +rule "terraform_comment_syntax" { + enabled = true +} + +rule "terraform_deprecated_index" { + enabled = true +} + +rule "terraform_deprecated_interpolation" { + enabled = true +} + +rule "terraform_documented_outputs" { + enabled = true +} + +rule "terraform_documented_variables" { + enabled = true +} + +rule "terraform_module_pinned_source" { + enabled = true +} + +rule "terraform_module_version" { + enabled = true +} + +rule "terraform_naming_convention" { + enabled = true +} + +rule "terraform_required_providers" { + enabled = true +} + +rule "terraform_required_version" { + enabled = true +} + +rule "terraform_standard_module_structure" { + enabled = false +} + +rule "terraform_typed_variables" { + enabled = true +} + +rule "terraform_unused_declarations" { + enabled = true +} + +rule "terraform_unused_required_providers" { + enabled = true +} + +rule "terraform_workspace_remote" { + enabled = true +} diff --git a/quickstart/201-function-app/main.tf b/quickstart/201-function-app/main.tf new file mode 100644 index 00000000..5b4f05da --- /dev/null +++ b/quickstart/201-function-app/main.tf @@ -0,0 +1,47 @@ +resource "azurerm_resource_group" "default" { + name = "${var.name_prefix}-rg" + location = var.location +} + +resource "azurerm_storage_account" "default" { + name = "${var.name_prefix}sa" + resource_group_name = azurerm_resource_group.default.name + location = azurerm_resource_group.default.location + account_tier = "Standard" + account_replication_type = "LRS" + + min_tls_version = "TLS1_2" +} + +resource "azurerm_service_plan" "default" { + name = "${var.name_prefix}-sap" + location = azurerm_resource_group.default.location + resource_group_name = azurerm_resource_group.default.name + sku_name = "Y1" + os_type = "Linux" + +} +# please note: +# You may see custom (~4) is set to the app's runtime version, along with a warning says “Your app is pinned to an unsupported runtime version for ‘dotnet’. For better performance, we recommend using one of our supported versions instead: xxx.”. This is because azure function v4 runtime requires .NET6.0 but the default value is 4.0. You need to set the .netframeworkversion to v6.0 to support azure funtion v4. +# If you would like to set the function runtime version, please use functions_extension_version property, terraform will set the FUNCTIONS_EXTENSION_VERSION in app_setting block, you don't need to specify the key in app_setting block. +# If you would like to set the required number of failed requests for an instance to be deemed unhealthy and removed from the load balancer under health check feature, using health_check_eviction_time_in_min property under site_config block. Terraform will set the key WEBSITE_HEALTHCHECK_MAXPINGFAILURES +# in app_setting for you. + +resource "azurerm_linux_function_app" "test" { + name = "${var.name_prefix}-lfa" + location = azurerm_resource_group.default.location + resource_group_name = azurerm_resource_group.default.name + service_plan_id = azurerm_service_plan.default.id + storage_account_name = azurerm_storage_account.default.name + storage_account_access_key = azurerm_storage_account.default.primary_access_key + https_only = true + builtin_logging_enabled = false + functions_extension_version = "~4" + + site_config { + application_stack { + dotnet_version = "6.0" + } + } +} + diff --git a/quickstart/201-function-app/providers.tf b/quickstart/201-function-app/providers.tf new file mode 100644 index 00000000..74d8804c --- /dev/null +++ b/quickstart/201-function-app/providers.tf @@ -0,0 +1,13 @@ +terraform { + required_version = ">=1.0" + + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~>3.8" + } + } +} +provider "azurerm" { + features {} +} \ No newline at end of file diff --git a/quickstart/201-function-app/readme.html.markdown b/quickstart/201-function-app/readme.html.markdown new file mode 100644 index 00000000..afc33249 --- /dev/null +++ b/quickstart/201-function-app/readme.html.markdown @@ -0,0 +1,41 @@ +# Azure Windows/ Linux Function App. + +This template deploys an Azure Function App. + + + + + + + + + +## Resources + +| Name | Type | +|---------------------------------------------------------------------------------------------------------------------------------------|----------| +| [azurerm_linux_function_app.test](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_function_app) | resource | +| [azurerm_resource_group.default](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) | resource | +| [azurerm_service_plan.default](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/service_plan) | resource | +| [azurerm_storage_account.default](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account) | resource | +## Inputs + +| Name | Description | Type | Default | Required | +|-----------------------------------------------------------------------|---------------------------------------|----------|---------------|:--------:| +| [location](#input\_location) | Location to deploy the resource group | `string` | `"West US 2"` | no | +| [name\_prefix](#input\_name\_prefix) | Prefix of the resource name | `string` | n/a | yes | +## Providers + +| Name | Version | +|---------------------------------------------------------------|---------| +| [azurerm](#provider\_azurerm) | ~>3.8 | +## Requirements + +| Name | Version | +|---------------------------------------------------------------------------|---------| +| [terraform](#requirement\_terraform) | >=1.0 | +| [azurerm](#requirement\_azurerm) | ~>3.8 | + +## Example + +To see how to run this example, see [Create an Azure Function App using Terraform](https://docs.microsoft.com/azure/developer/terraform/create-azure-function-app). diff --git a/quickstart/201-function-app/variables.tf b/quickstart/201-function-app/variables.tf new file mode 100644 index 00000000..e4c01012 --- /dev/null +++ b/quickstart/201-function-app/variables.tf @@ -0,0 +1,10 @@ +variable "name_prefix" { + type = string + description = "Prefix of the resource name" +} + +variable "location" { + type = string + description = "Location to deploy the resource group" + default = "West US 2" +}