From d895942b2511bd83e4e2b8cb3e878c740391ceff Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Wed, 7 Feb 2024 04:44:15 -0800 Subject: [PATCH 1/3] User Story 208753 --- quickstart/101-app-service-backup/README.md | 22 ++++ quickstart/101-app-service-backup/main.tf | 119 ++++++++++++++++++ quickstart/101-app-service-backup/outputs.tf | 27 ++++ .../101-app-service-backup/providers.tf | 18 +++ .../101-app-service-backup/variables.tf | 11 ++ 5 files changed, 197 insertions(+) create mode 100644 quickstart/101-app-service-backup/README.md create mode 100644 quickstart/101-app-service-backup/main.tf create mode 100644 quickstart/101-app-service-backup/outputs.tf create mode 100644 quickstart/101-app-service-backup/providers.tf create mode 100644 quickstart/101-app-service-backup/variables.tf 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 From 4c73d9da3b988966bbddaab3d6cd7647ee056647 Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Wed, 7 Feb 2024 05:00:39 -0800 Subject: [PATCH 2/3] Removed incorrect output --- quickstart/101-app-service-backup/outputs.tf | 4 ---- 1 file changed, 4 deletions(-) diff --git a/quickstart/101-app-service-backup/outputs.tf b/quickstart/101-app-service-backup/outputs.tf index 44ba3e90..e4cbe491 100644 --- a/quickstart/101-app-service-backup/outputs.tf +++ b/quickstart/101-app-service-backup/outputs.tf @@ -21,7 +21,3 @@ output "windows_web_app_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 From ffa4aa614b560056a74a5db4a9007399f27792bc Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Mon, 10 Jun 2024 10:41:46 -0700 Subject: [PATCH 3/3] Changed per review --- quickstart/101-app-service-backup/main.tf | 6 ++++-- quickstart/101-app-service-backup/variables.tf | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/quickstart/101-app-service-backup/main.tf b/quickstart/101-app-service-backup/main.tf index 6bb1575e..874e50af 100644 --- a/quickstart/101-app-service-backup/main.tf +++ b/quickstart/101-app-service-backup/main.tf @@ -70,8 +70,10 @@ data "azurerm_storage_account_sas" "example" { file = false } - start = "2024-01-01" - expiry = "2024-12-31" + # Please change the start_date variable (in variables.tf) to the appropriate + # value for your environment. + start = formatdate(var.start_date, timestamp()) + expiry = formatdate(var.start_date, timeadd(timestamp(), "8765h")) permissions { read = false diff --git a/quickstart/101-app-service-backup/variables.tf b/quickstart/101-app-service-backup/variables.tf index e71c1446..5320e399 100644 --- a/quickstart/101-app-service-backup/variables.tf +++ b/quickstart/101-app-service-backup/variables.tf @@ -8,4 +8,11 @@ variable "resource_group_location" { type = string default = "eastus" description = "Location of the resource group." +} + + +variable "start_date" { + type = string + default = "2024-06-01" + description = "Start date." } \ No newline at end of file