From 8aa98d5569f7d90aa521a8fb3562b98ce2b0f8c5 Mon Sep 17 00:00:00 2001 From: lonegunmanb Date: Tue, 14 Mar 2023 07:23:47 +0800 Subject: [PATCH] Fix 101-storage-static-website (#188) * fix 101-storage-static-website --------- Co-authored-by: zjhe --- quickstart/101-storage-static-website/main.tf | 17 +++++++++++------ .../101-storage-static-website/providers.tf | 15 +++++++++++++++ .../storage_account.tf | 8 ++++---- .../101-storage-static-website/variables.tf | 6 +++++- 4 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 quickstart/101-storage-static-website/providers.tf diff --git a/quickstart/101-storage-static-website/main.tf b/quickstart/101-storage-static-website/main.tf index 08f2559d..b216af2d 100644 --- a/quickstart/101-storage-static-website/main.tf +++ b/quickstart/101-storage-static-website/main.tf @@ -1,13 +1,18 @@ -provider "azurerm" { - version = "=1.36.0" +resource "azurerm_resource_group" "default" { + name = "${local.name}-${var.environment}-rg" + location = var.location } -resource "azurerm_resource_group" "default" { - name = "${var.name}-${var.environment}-rg" - location = "westus" +resource "random_string" "name" { + count = var.name == null ? 1 : 0 + + length = 8 + upper = false + special = false } locals { - storage_account_name = "${var.dns_prefix}${var.name}${substr(var.environment, 0, 2)}" + name = try(random_string.name[0].result, var.name) + storage_account_name = "${var.dns_prefix}${local.name}${substr(var.environment, 0, 2)}" } diff --git a/quickstart/101-storage-static-website/providers.tf b/quickstart/101-storage-static-website/providers.tf new file mode 100644 index 00000000..796e2147 --- /dev/null +++ b/quickstart/101-storage-static-website/providers.tf @@ -0,0 +1,15 @@ +terraform { + required_providers { + azurerm = { + version = "~> 3.0" + } + random = { + source = "hashicorp/random" + version = "3.4.3" + } + } +} + +provider "azurerm" { + features {} +} \ No newline at end of file diff --git a/quickstart/101-storage-static-website/storage_account.tf b/quickstart/101-storage-static-website/storage_account.tf index 84feae01..642deb40 100644 --- a/quickstart/101-storage-static-website/storage_account.tf +++ b/quickstart/101-storage-static-website/storage_account.tf @@ -1,14 +1,14 @@ - resource "azurerm_storage_account" "default" { name = local.storage_account_name resource_group_name = azurerm_resource_group.default.name - location = "westus2" + location = azurerm_resource_group.default.location account_kind = "StorageV2" account_tier = "Standard" account_replication_type = "LRS" enable_https_traffic_only = true - provisioner "local-exec" { - command = "az storage blob service-properties update --account-name ${azurerm_storage_account.default.name} --static-website --index-document index.html --404-document 404.html" + static_website { + index_document = "index.html" + error_404_document = "404.html" } } \ No newline at end of file diff --git a/quickstart/101-storage-static-website/variables.tf b/quickstart/101-storage-static-website/variables.tf index cb6f0ac0..012ade66 100644 --- a/quickstart/101-storage-static-website/variables.tf +++ b/quickstart/101-storage-static-website/variables.tf @@ -1,15 +1,19 @@ variable "environment" { + type = string default = "dev" } variable "name" { - default = "demo-tfquickstart" + type = string + default = null } variable "location" { + type = string default = "West US 2" } variable "dns_prefix" { + type = string default = "tfq" } \ No newline at end of file