Skip to content

Commit 5ee841a

Browse files
authored
Streamlined Azure resource naming (#54)
* Streamlined Azure resource naming * Fixed code formatting * Fixed storage account regex
1 parent 4529fa0 commit 5ee841a

File tree

4 files changed

+41
-60
lines changed

4 files changed

+41
-60
lines changed

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ module "keyvault_acmebot" {
1212
source = "shibayan/keyvault-acmebot/azurerm"
1313
version = "~> 2.0"
1414
15-
function_app_name = "func-acmebot-module"
16-
app_service_plan_name = "plan-acmebot-module"
17-
storage_account_name = "stacmebotmodule"
18-
app_insights_name = "appi-acmebot-module"
19-
workspace_name = "log-acmebot-module"
15+
app_base_name = "acmebot-module"
2016
resource_group_name = azurerm_resource_group.default.name
2117
location = azurerm_resource_group.default.location
2218
mail_address = "YOUR-EMAIL-ADDRESS"

example/main.tf

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
provider "azurerm" {
2-
features {}
2+
features {
3+
resource_group {
4+
prevent_deletion_if_contains_resources = false
5+
}
6+
}
37
}
48

59
terraform {
@@ -42,18 +46,22 @@ resource "azuread_application_password" "default" {
4246
rotate_when_changed = {
4347
rotation = time_rotating.default.id
4448
}
49+
50+
lifecycle {
51+
create_before_destroy = true
52+
}
4553
}
4654

4755
data "azurerm_client_config" "current" {
4856
}
4957

5058
resource "azurerm_resource_group" "default" {
51-
name = "rg-acmebot-module"
59+
name = "rg-acmebot"
5260
location = "westus2"
5361
}
5462

5563
resource "azurerm_key_vault" "default" {
56-
name = "kv-acmebot-module-${random_string.random.result}"
64+
name = "kv-acmebot-${random_string.random.result}"
5765
resource_group_name = azurerm_resource_group.default.name
5866
location = azurerm_resource_group.default.location
5967

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

76-
function_app_name = "func-acmebot-module-${random_string.random.result}"
77-
app_service_plan_name = "plan-acmebot-module-${random_string.random.result}"
78-
storage_account_name = "stacmebotmodule${random_string.random.result}"
79-
app_insights_name = "appi-acmebot-module-${random_string.random.result}"
80-
workspace_name = "log-acmebot-module-${random_string.random.result}"
81-
resource_group_name = azurerm_resource_group.default.name
82-
location = azurerm_resource_group.default.location
83-
mail_address = "YOUR-EMAIL-ADDRESS"
84-
vault_uri = azurerm_key_vault.default.vault_uri
84+
app_base_name = "acmebot-${random_string.random.result}"
85+
resource_group_name = azurerm_resource_group.default.name
86+
location = azurerm_resource_group.default.location
87+
mail_address = "YOUR-EMAIL-ADDRESS"
88+
vault_uri = azurerm_key_vault.default.vault_uri
8589

8690
azure_dns = {
8791
subscription_id = data.azurerm_client_config.current.subscription_id

main.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "azurerm_storage_account" "storage" {
2-
name = var.storage_account_name
2+
name = "st${replace(lower(var.app_base_name), "/[^a-z0-9]/", "")}"
33
resource_group_name = var.resource_group_name
44
location = var.location
55
tags = var.additional_tags
@@ -19,7 +19,7 @@ resource "azurerm_storage_account" "storage" {
1919
}
2020

2121
resource "azurerm_service_plan" "serverfarm" {
22-
name = var.app_service_plan_name
22+
name = "plan-${var.app_base_name}"
2323
resource_group_name = var.resource_group_name
2424
location = var.location
2525
tags = var.additional_tags
@@ -35,7 +35,7 @@ resource "azurerm_service_plan" "serverfarm" {
3535
}
3636

3737
resource "azurerm_log_analytics_workspace" "workspace" {
38-
name = var.workspace_name
38+
name = "log-${var.app_base_name}"
3939
resource_group_name = var.resource_group_name
4040
location = var.location
4141
tags = var.additional_tags
@@ -51,7 +51,7 @@ resource "azurerm_log_analytics_workspace" "workspace" {
5151
}
5252

5353
resource "azurerm_application_insights" "insights" {
54-
name = var.app_insights_name
54+
name = "appi-${var.app_base_name}"
5555
resource_group_name = var.resource_group_name
5656
location = var.location
5757
tags = var.additional_tags
@@ -67,7 +67,7 @@ resource "azurerm_application_insights" "insights" {
6767
}
6868

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

8686
dynamic "sticky_settings" {
8787
for_each = toset(length(local.auth_app_settings) != 0 ? [1] : [])

variables.tf

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,16 @@
1-
variable "function_app_name" {
1+
variable "app_base_name" {
22
type = string
3-
description = "The name of the Function App to create."
3+
description = "The name of the App base to create."
44
}
55

6-
variable "allowed_ip_addresses" {
7-
type = list(string)
8-
description = "A list of allowed ip addresses that can access the Acmebot UI."
9-
default = []
10-
}
11-
12-
variable "app_service_plan_name" {
13-
type = string
14-
description = "The name of the App Service Plan to create."
15-
}
16-
17-
variable "storage_account_name" {
18-
type = string
19-
description = "The name of the Storage Account to create."
20-
}
21-
22-
variable "app_insights_name" {
23-
type = string
24-
description = "The name of the Application Insights to create."
25-
}
26-
27-
variable "workspace_name" {
6+
variable "resource_group_name" {
287
type = string
29-
description = "The name of the Log Analytics Workspace to create."
8+
description = "Resource group name to be added."
309
}
3110

32-
variable "resource_group_name" {
11+
variable "location" {
3312
type = string
34-
description = "Resource group name to be added."
13+
description = "Azure region to create resources."
3514
}
3615

3716
variable "auth_settings" {
@@ -47,9 +26,15 @@ variable "auth_settings" {
4726
default = null
4827
}
4928

50-
variable "app_settings" {
51-
description = "Additional settings to set for the function app"
29+
variable "allowed_ip_addresses" {
30+
type = list(string)
31+
description = "A list of allowed ip addresses that can access the Acmebot UI."
32+
default = []
33+
}
34+
35+
variable "additional_app_settings" {
5236
type = map(string)
37+
description = "Additional settings to set for the function app"
5338
default = {}
5439
}
5540

@@ -59,11 +44,13 @@ variable "additional_tags" {
5944
default = {}
6045
}
6146

62-
variable "location" {
47+
variable "time_zone" {
6348
type = string
64-
description = "Azure region to create resources."
49+
description = "The name of time zone as the basis for automatic update timing."
50+
default = "UTC"
6551
}
6652

53+
# Acmebot Configuration
6754
variable "vault_uri" {
6855
type = string
6956
description = "URL of the Key Vault to store the issued certificate."
@@ -86,12 +73,6 @@ variable "environment" {
8673
default = "AzureCloud"
8774
}
8875

89-
variable "time_zone" {
90-
type = string
91-
description = "The name of time zone as the basis for automatic update timing."
92-
default = "UTC"
93-
}
94-
9576
variable "webhook_url" {
9677
type = string
9778
description = "The webhook where notifications will be sent."

0 commit comments

Comments
 (0)