Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User Story 335474 - 101-azure-functions #386

Merged
merged 10 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions quickstart/101-azure-functions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Azure Functions 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_service_plan](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/service_plan)
- [azurerm_function_app](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/function_app)

## 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 |
| `sa_account_tier` | The tier of the storage account. Possible values are Standard and Premium. | "Standard" |
| `sa_account_replication_type` | The replication type of the storage account. Possible values are LRS, GRS, RAGRS, and ZRS. | "LRS" |
| `sa_name` | The name of the storage account. | Randomly generated |
| `asp_name` | The name of the App Service Plan. | Randomly generated |
| `asp_sku_tier` | The SKU tier of the App Service Plan. Possible values are Free, Shared, Basic, Standard, Premium, PremiumV2, and PremiumV3. | "Standard" |
| `fa_name` | The name of the Function App." | Randomly generated |

## Example
44 changes: 44 additions & 0 deletions quickstart/101-azure-functions/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
resource "random_pet" "rg_name" {
prefix = var.resource_group_name_prefix
}

resource "azurerm_resource_group" "rg" {
location = var.resource_group_location
name = coalesce(var.resource_group_name, random_pet.rg_name.id)
}

resource "random_string" "name" {
length = 13
lower = true
numeric = false
special = false
upper = false
}

resource "azurerm_storage_account" "example" {
name = coalesce(var.sa_name, "sa${random_string.name.result}")
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
account_tier = var.sa_account_tier
account_replication_type = var.sa_account_replication_type
}

resource "azurerm_app_service_plan" "example" {
name = coalesce(var.asp_name, "sp${random_string.name.result}")
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name

sku {
tier = var.asp_sku_tier
size = "P0v3"
}
}

resource "azurerm_function_app" "example" {
name = coalesce(var.fa_name, "fa${random_string.name.result}")
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
app_service_plan_id = azurerm_app_service_plan.example.id
storage_account_name = azurerm_storage_account.example.name
storage_account_access_key = azurerm_storage_account.example.primary_access_key
}
51 changes: 51 additions & 0 deletions quickstart/101-azure-functions/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
output "resource_group_name" {
value = azurerm_resource_group.rg.name
}

output "sa_name" {
value = azurerm_storage_account.example.name
}

output "asp_name" {
value = azurerm_app_service_plan.example.name
}

output "fa_name" {
value = azurerm_function_app.example.name
}

output "sa_primary_access_key" {
value = azurerm_storage_account.example.primary_access_key
sensitive = true
}

output "sa_primary_connection_string" {
value = azurerm_storage_account.example.primary_connection_string
sensitive = true
}

output "sa_secondary_access_key" {
value = azurerm_storage_account.example.secondary_access_key
sensitive = true
}

output "sa_secondary_connection_string" {
value = azurerm_storage_account.example.secondary_connection_string
sensitive = true
}

output "asp_id" {
value = azurerm_app_service_plan.example.id
}

output "fa_id" {
value = azurerm_function_app.example.id
}

output "fa_default_hostname" {
value = azurerm_function_app.example.default_hostname
}

output "fa_outbound_ip_addresses" {
value = azurerm_function_app.example.outbound_ip_addresses
}
18 changes: 18 additions & 0 deletions quickstart/101-azure-functions/providers.tf
Original file line number Diff line number Diff line change
@@ -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 {}
}
53 changes: 53 additions & 0 deletions quickstart/101-azure-functions/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
variable "resource_group_name" {
type = string
default = ""
description = "The name of the Azure resource group. If blank, a random name will be generated."
}

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 = "westeurope"
description = "Location of the resource group."
}

variable "sa_account_tier" {
description = "The tier of the storage account. Possible values are Standard and Premium."
type = string
default = "Premium"
}

variable "sa_account_replication_type" {
description = "The replication type of the storage account. Possible values are LRS, GRS, RAGRS, and ZRS."
type = string
default = "LRS"
}

variable "sa_name" {
description = "The name of the storage account. If blank, a random name will be generated."
type = string
default = ""
}

variable "asp_name" {
description = "The name of the App Service Plan. If blank, a random name will be generated."
type = string
default = ""
}

variable "asp_sku_tier" {
description = "The SKU tier of the App Service Plan. Possible values are Free, Shared, Basic, Standard, Premium, PremiumV2, and PremiumV3."
type = string
default = "Premium0V3"
}

variable "fa_name" {
description = "The name of the Function App. If blank, a random name will be generated."
type = string
default = ""
}
Loading