Skip to content

Commit

Permalink
feat(infra): add module tags
Browse files Browse the repository at this point in the history
  • Loading branch information
atrakic committed Sep 28, 2023
1 parent 4d18c38 commit 98ac401
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 19 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

# .tfstate files
**/infra/*.tfstate
**/infra/*.terraform.lock.hcl

**/*.tfstate.*

# Crash log files
Expand All @@ -14,4 +16,4 @@
.direnv/*
.azure
.venv
db.sqlite
db.sqlite
2 changes: 1 addition & 1 deletion infra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Use the following command to generate the .terraform.lock.hcl file to work cross

```
terraform providers lock -platform=windows_amd64 -platform=darwin_amd64 -platform=linux_amd64
```
```
2 changes: 1 addition & 1 deletion infra/main.tfvars.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"location": "${AZURE_LOCATION}",
"environment_name": "${AZURE_ENV_NAME}",
"principal_id": "${AZURE_PRINCIPAL_ID}"
}
}
36 changes: 36 additions & 0 deletions infra/modules/applicationinsights/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
terraform {
required_version = ">= 0.13.1"
required_providers {
azurerm = {
version = ">= 3.18.0"
source = "hashicorp/azurerm"
}
azurecaf = {
source = "aztfmod/azurecaf"
version = ">= 1.2.15"
}
}
}

locals {
module_tag = {
"module" = basename(abspath(path.module))
}
tags = merge(var.tags, local.module_tag)
}

resource "azurecaf_name" "applicationinsights_name" {
name = var.resource_token
resource_type = "azurerm_application_insights"
random_length = 0
clean_input = true
}

resource "azurerm_application_insights" "applicationinsights" {
name = azurecaf_name.applicationinsights_name.result
location = var.location
resource_group_name = var.rg_name
application_type = "web"
workspace_id = var.workspace_id
tags = local.tags
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ terraform {
}
}

locals {
module_tag = {
"module" = basename(abspath(path.module))
}
tags = merge(var.tags, local.module_tag)
}

resource "azurecaf_name" "applicationinsights_name" {
name = var.resource_token
resource_type = "azurerm_application_insights"
Expand All @@ -25,7 +32,7 @@ resource "azurerm_application_insights" "applicationinsights" {
resource_group_name = var.rg_name
application_type = "web"
workspace_id = var.workspace_id
tags = var.tags
tags = local.tags
}

data "azurerm_subscription" "current" {}
Expand All @@ -34,7 +41,7 @@ resource "azurerm_portal_dashboard" "board" {
name = "dash-${var.resource_token}"
resource_group_name = var.rg_name
location = var.location
tags = var.tags
tags = local.tags
dashboard_properties = <<DASH
{
"lenses": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
output "APPLICATIONINSIGHTS_CONNECTION_STRING" {
value = azurerm_application_insights.applicationinsights.connection_string
sensitive = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ variable "workspace_id" {
variable "tags" {
description = "A list of tags used for deployed services."
type = map(string)
default = {}
}

variable "resource_token" {
description = "A suffix string to centrally mitigate resource name collisions."
type = string
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ terraform {
}
}

locals {
module_tag = {
"module" = basename(abspath(path.module))
}
tags = merge(var.tags, local.module_tag)
}

resource "azurecaf_name" "plan_name" {
name = var.resource_token
resource_type = "azurerm_app_service_plan"
Expand All @@ -25,6 +32,5 @@ resource "azurerm_service_plan" "plan" {
resource_group_name = var.rg_name
os_type = var.os_type
sku_name = var.sku_name

tags = var.tags
tags = local.tags
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
output "APPSERVICE_PLAN_ID" {
value = azurerm_service_plan.plan.id
sensitive = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ variable "rg_name" {
variable "tags" {
description = "A list of tags used for deployed services."
type = map(string)
default = {}
}

variable "resource_token" {
Expand All @@ -28,4 +29,4 @@ variable "os_type" {
description = "The O/S type for the App Services to be hosted in this plan."
type = string
default = "Linux"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ terraform {
}
}

locals {
module_tag = {
"module" = basename(abspath(path.module))
}
tags = merge(var.tags, local.module_tag)
}

resource "azurecaf_name" "web_name" {
name = "${var.service_name}-${var.resource_token}"
resource_type = "azurerm_app_service"
Expand All @@ -25,7 +32,7 @@ resource "azurerm_linux_web_app" "web" {
resource_group_name = var.rg_name
service_plan_id = var.appservice_plan_id
https_only = true
tags = var.tags
tags = local.tags

site_config {
always_on = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
output "URI" {
value = "https://${azurerm_linux_web_app.web.default_hostname}"
value = "https://${azurerm_linux_web_app.web.default_hostname}"
}

output "IDENTITY_PRINCIPAL_ID" {
value = length(azurerm_linux_web_app.web.identity) == 0 ? "" : azurerm_linux_web_app.web.identity.0.principal_id
sensitive = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ variable "app_command_line" {
variable "tags" {
description = "A list of tags used for deployed services."
type = map(string)
default = {}
}

variable "resource_token" {
Expand All @@ -47,5 +48,5 @@ variable "resource_token" {
variable "python_version" {
description = "the application stack python version to set for the app service."
type = string
default = "3.8"
}
default = "3.11"
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ terraform {
}
}

locals {
module_tag = {
"module" = basename(abspath(path.module))
}
tags = merge(var.tags, local.module_tag)
}

resource "azurecaf_name" "workspace_name" {
name = var.resource_token
resource_type = "azurerm_log_analytics_workspace"
Expand All @@ -25,5 +32,6 @@ resource "azurerm_log_analytics_workspace" "workspace" {
resource_group_name = var.rg_name
sku = "PerGB2018"
retention_in_days = 30
tags = var.tags
tags = local.tags

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
output "LOGANALYTICS_WORKSPACE_ID" {
value = azurerm_log_analytics_workspace.workspace.id
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ variable "resource_token" {
variable "tags" {
description = "A list of tags used for deployed services."
type = map(string)
}
default = {}
}

0 comments on commit 98ac401

Please sign in to comment.