diff --git a/quickstart/101-app-service-backup/README.md b/quickstart/101-app-service-backup/README.md new file mode 100644 index 00000000..7be08270 --- /dev/null +++ b/quickstart/101-app-service-backup/README.md @@ -0,0 +1,22 @@ +# Azure Windows Web App with Backup + +This template deploys an Azure Windows Web App with a backup configured. + +## 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_storage_container](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_container) +- [azurerm_service_plan](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/service_plan) +- [azurerm_windows_web_app](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/windows_web_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 | + +## Example \ No newline at end of file diff --git a/quickstart/101-app-service-backup/main.tf b/quickstart/101-app-service-backup/main.tf new file mode 100644 index 00000000..6bb1575e --- /dev/null +++ b/quickstart/101-app-service-backup/main.tf @@ -0,0 +1,119 @@ +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" "storage_account_name" { + length = 8 + lower = true + numeric = false + special = false + upper = false +} + +resource "azurerm_storage_account" "example" { + name = random_string.storage_account_name.result + resource_group_name = azurerm_resource_group.rg.name + location = azurerm_resource_group.rg.location + account_tier = "Standard" + account_replication_type = "LRS" +} + +resource "random_string" "storage_container_name" { + length = 8 + lower = true + numeric = false + special = false + upper = false +} + +resource "azurerm_storage_container" "example" { + name = random_string.storage_container_name.result + storage_account_name = azurerm_storage_account.example.name + container_access_type = "private" +} + +resource "random_string" "service_plan_name" { + length = 8 + lower = true + numeric = false + special = false + upper = false +} + +resource "azurerm_service_plan" "example" { + name = random_string.service_plan_name.result + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + os_type = "Windows" + sku_name = "S1" +} + +data "azurerm_storage_account_sas" "example" { + connection_string = azurerm_storage_account.example.primary_connection_string + https_only = true + + resource_types { + service = false + container = false + object = true + } + + services { + blob = true + queue = false + table = false + file = false + } + + start = "2024-01-01" + expiry = "2024-12-31" + + permissions { + read = false + write = true + delete = false + list = false + add = false + create = false + update = false + process = false + tag = false + filter = false + } +} + +resource "random_string" "windows_web_app_name" { + length = 8 + lower = true + numeric = false + special = false + upper = false +} + +resource "azurerm_windows_web_app" "example" { + name = random_string.windows_web_app_name.result + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + service_plan_id = azurerm_service_plan.example.id + + backup { + name = "Example" + storage_account_url = "https://${azurerm_storage_account.example.name}.blob.core.windows.net/${azurerm_storage_container.example.name}${data.azurerm_storage_account_sas.example.sas}&sr=b" + schedule { + frequency_interval = 30 + frequency_unit = "Day" + } + } + + site_config { + application_stack { + dotnet_version = "v6.0" + current_stack = "dotnet" + } + } +} \ No newline at end of file diff --git a/quickstart/101-app-service-backup/outputs.tf b/quickstart/101-app-service-backup/outputs.tf new file mode 100644 index 00000000..44ba3e90 --- /dev/null +++ b/quickstart/101-app-service-backup/outputs.tf @@ -0,0 +1,27 @@ +output "resource_group_name" { + value = azurerm_resource_group.rg.name +} + +output "storage_account_name" { + value = azurerm_storage_account.example.name +} + +output "storage_container_name" { + value = azurerm_storage_container.example.name +} + +output "service_plan_name" { + value = azurerm_service_plan.example.name +} + +output "windows_web_app_name" { + value = azurerm_windows_web_app.example.name +} + +output "windows_web_app_default_hostname" { + value = azurerm_windows_web_app.example.default_hostname +} + +output "windows_web_app_default_site_hostname" { + value = azurerm_windows_web_app.example.default_site_hostname +} \ No newline at end of file diff --git a/quickstart/101-app-service-backup/providers.tf b/quickstart/101-app-service-backup/providers.tf new file mode 100644 index 00000000..058b6871 --- /dev/null +++ b/quickstart/101-app-service-backup/providers.tf @@ -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 {} +} \ No newline at end of file diff --git a/quickstart/101-app-service-backup/variables.tf b/quickstart/101-app-service-backup/variables.tf new file mode 100644 index 00000000..e71c1446 --- /dev/null +++ b/quickstart/101-app-service-backup/variables.tf @@ -0,0 +1,11 @@ +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." +} \ No newline at end of file