Fix 101-storage-static-website (#188)

* fix 101-storage-static-website

---------

Co-authored-by: zjhe <hezijie@microsoft.com>
This commit is contained in:
lonegunmanb 2023-03-14 07:23:47 +08:00 committed by GitHub
parent fcd4f1d54f
commit 8aa98d5569
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 11 deletions

View File

@ -1,13 +1,18 @@
provider "azurerm" { resource "azurerm_resource_group" "default" {
version = "=1.36.0" name = "${local.name}-${var.environment}-rg"
location = var.location
} }
resource "azurerm_resource_group" "default" { resource "random_string" "name" {
name = "${var.name}-${var.environment}-rg" count = var.name == null ? 1 : 0
location = "westus"
length = 8
upper = false
special = false
} }
locals { 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)}"
} }

View File

@ -0,0 +1,15 @@
terraform {
required_providers {
azurerm = {
version = "~> 3.0"
}
random = {
source = "hashicorp/random"
version = "3.4.3"
}
}
}
provider "azurerm" {
features {}
}

View File

@ -1,14 +1,14 @@
resource "azurerm_storage_account" "default" { resource "azurerm_storage_account" "default" {
name = local.storage_account_name name = local.storage_account_name
resource_group_name = azurerm_resource_group.default.name resource_group_name = azurerm_resource_group.default.name
location = "westus2" location = azurerm_resource_group.default.location
account_kind = "StorageV2" account_kind = "StorageV2"
account_tier = "Standard" account_tier = "Standard"
account_replication_type = "LRS" account_replication_type = "LRS"
enable_https_traffic_only = true enable_https_traffic_only = true
provisioner "local-exec" { static_website {
command = "az storage blob service-properties update --account-name ${azurerm_storage_account.default.name} --static-website --index-document index.html --404-document 404.html" index_document = "index.html"
error_404_document = "404.html"
} }
} }

View File

@ -1,15 +1,19 @@
variable "environment" { variable "environment" {
type = string
default = "dev" default = "dev"
} }
variable "name" { variable "name" {
default = "demo-tfquickstart" type = string
default = null
} }
variable "location" { variable "location" {
type = string
default = "West US 2" default = "West US 2"
} }
variable "dns_prefix" { variable "dns_prefix" {
type = string
default = "tfq" default = "tfq"
} }