Skip to content

Commit

Permalink
Streamlined Azure resource naming (#54)
Browse files Browse the repository at this point in the history
* Streamlined Azure resource naming

* Fixed code formatting

* Fixed storage account regex
  • Loading branch information
shibayan authored Jun 21, 2023
1 parent 4529fa0 commit 5ee841a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 60 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ module "keyvault_acmebot" {
source = "shibayan/keyvault-acmebot/azurerm"
version = "~> 2.0"
function_app_name = "func-acmebot-module"
app_service_plan_name = "plan-acmebot-module"
storage_account_name = "stacmebotmodule"
app_insights_name = "appi-acmebot-module"
workspace_name = "log-acmebot-module"
app_base_name = "acmebot-module"
resource_group_name = azurerm_resource_group.default.name
location = azurerm_resource_group.default.location
mail_address = "YOUR-EMAIL-ADDRESS"
Expand Down
28 changes: 16 additions & 12 deletions example/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
provider "azurerm" {
features {}
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}

terraform {
Expand Down Expand Up @@ -42,18 +46,22 @@ resource "azuread_application_password" "default" {
rotate_when_changed = {
rotation = time_rotating.default.id
}

lifecycle {
create_before_destroy = true
}
}

data "azurerm_client_config" "current" {
}

resource "azurerm_resource_group" "default" {
name = "rg-acmebot-module"
name = "rg-acmebot"
location = "westus2"
}

resource "azurerm_key_vault" "default" {
name = "kv-acmebot-module-${random_string.random.result}"
name = "kv-acmebot-${random_string.random.result}"
resource_group_name = azurerm_resource_group.default.name
location = azurerm_resource_group.default.location

Expand All @@ -73,15 +81,11 @@ module "keyvault_acmebot" {
source = "shibayan/keyvault-acmebot/azurerm"
version = "~> 2.0"

function_app_name = "func-acmebot-module-${random_string.random.result}"
app_service_plan_name = "plan-acmebot-module-${random_string.random.result}"
storage_account_name = "stacmebotmodule${random_string.random.result}"
app_insights_name = "appi-acmebot-module-${random_string.random.result}"
workspace_name = "log-acmebot-module-${random_string.random.result}"
resource_group_name = azurerm_resource_group.default.name
location = azurerm_resource_group.default.location
mail_address = "YOUR-EMAIL-ADDRESS"
vault_uri = azurerm_key_vault.default.vault_uri
app_base_name = "acmebot-${random_string.random.result}"
resource_group_name = azurerm_resource_group.default.name
location = azurerm_resource_group.default.location
mail_address = "YOUR-EMAIL-ADDRESS"
vault_uri = azurerm_key_vault.default.vault_uri

azure_dns = {
subscription_id = data.azurerm_client_config.current.subscription_id
Expand Down
12 changes: 6 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "azurerm_storage_account" "storage" {
name = var.storage_account_name
name = "st${replace(lower(var.app_base_name), "/[^a-z0-9]/", "")}"
resource_group_name = var.resource_group_name
location = var.location
tags = var.additional_tags
Expand All @@ -19,7 +19,7 @@ resource "azurerm_storage_account" "storage" {
}

resource "azurerm_service_plan" "serverfarm" {
name = var.app_service_plan_name
name = "plan-${var.app_base_name}"
resource_group_name = var.resource_group_name
location = var.location
tags = var.additional_tags
Expand All @@ -35,7 +35,7 @@ resource "azurerm_service_plan" "serverfarm" {
}

resource "azurerm_log_analytics_workspace" "workspace" {
name = var.workspace_name
name = "log-${var.app_base_name}"
resource_group_name = var.resource_group_name
location = var.location
tags = var.additional_tags
Expand All @@ -51,7 +51,7 @@ resource "azurerm_log_analytics_workspace" "workspace" {
}

resource "azurerm_application_insights" "insights" {
name = var.app_insights_name
name = "appi-${var.app_base_name}"
resource_group_name = var.resource_group_name
location = var.location
tags = var.additional_tags
Expand All @@ -67,7 +67,7 @@ resource "azurerm_application_insights" "insights" {
}

resource "azurerm_windows_function_app" "function" {
name = var.function_app_name
name = "func-${var.app_base_name}"
resource_group_name = var.resource_group_name
location = var.location
tags = var.additional_tags
Expand All @@ -81,7 +81,7 @@ resource "azurerm_windows_function_app" "function" {
app_settings = merge({
"WEBSITE_RUN_FROM_PACKAGE" = "https://stacmebotprod.blob.core.windows.net/keyvault-acmebot/v4/latest.zip"
"WEBSITE_TIME_ZONE" = var.time_zone
}, local.acmebot_app_settings, local.auth_app_settings, var.app_settings)
}, local.acmebot_app_settings, local.auth_app_settings, var.additional_app_settings)

dynamic "sticky_settings" {
for_each = toset(length(local.auth_app_settings) != 0 ? [1] : [])
Expand Down
55 changes: 18 additions & 37 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,37 +1,16 @@
variable "function_app_name" {
variable "app_base_name" {
type = string
description = "The name of the Function App to create."
description = "The name of the App base to create."
}

variable "allowed_ip_addresses" {
type = list(string)
description = "A list of allowed ip addresses that can access the Acmebot UI."
default = []
}

variable "app_service_plan_name" {
type = string
description = "The name of the App Service Plan to create."
}

variable "storage_account_name" {
type = string
description = "The name of the Storage Account to create."
}

variable "app_insights_name" {
type = string
description = "The name of the Application Insights to create."
}

variable "workspace_name" {
variable "resource_group_name" {
type = string
description = "The name of the Log Analytics Workspace to create."
description = "Resource group name to be added."
}

variable "resource_group_name" {
variable "location" {
type = string
description = "Resource group name to be added."
description = "Azure region to create resources."
}

variable "auth_settings" {
Expand All @@ -47,9 +26,15 @@ variable "auth_settings" {
default = null
}

variable "app_settings" {
description = "Additional settings to set for the function app"
variable "allowed_ip_addresses" {
type = list(string)
description = "A list of allowed ip addresses that can access the Acmebot UI."
default = []
}

variable "additional_app_settings" {
type = map(string)
description = "Additional settings to set for the function app"
default = {}
}

Expand All @@ -59,11 +44,13 @@ variable "additional_tags" {
default = {}
}

variable "location" {
variable "time_zone" {
type = string
description = "Azure region to create resources."
description = "The name of time zone as the basis for automatic update timing."
default = "UTC"
}

# Acmebot Configuration
variable "vault_uri" {
type = string
description = "URL of the Key Vault to store the issued certificate."
Expand All @@ -86,12 +73,6 @@ variable "environment" {
default = "AzureCloud"
}

variable "time_zone" {
type = string
description = "The name of time zone as the basis for automatic update timing."
default = "UTC"
}

variable "webhook_url" {
type = string
description = "The webhook where notifications will be sent."
Expand Down

0 comments on commit 5ee841a

Please sign in to comment.