Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
frasdav committed Dec 22, 2023
1 parent be376c1 commit be5a3d7
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/storage-account/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
1 change: 1 addition & 0 deletions modules/storage-account/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0
15 changes: 15 additions & 0 deletions modules/storage-account/src/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
locals {
identifier = replace(lower(var.identifier), "/[^a-z1-9]/", "")

short_locations = {
"uksouth" = "uks"
"ukwest" = "ukw"
}

tags = {
Environment = var.environment
WorkloadName = var.workload_name
WorkloadType = var.workload_type
WorkloadVersion = var.workload_version
}
}
86 changes: 86 additions & 0 deletions modules/storage-account/src/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
resource "azurerm_storage_account" "main" {
name = "sa0${var.zone}0${var.environment}0${lookup(local.short_locations, var.location)}0${local.identifier}"
resource_group_name = var.resource_group_name
location = var.location

account_tier = var.account_tier
account_replication_type = var.account_replication_type
min_tls_version = "TLS1_2"

tags = merge(var.tags, local.tags)
}

resource "azurerm_monitor_diagnostic_setting" "main" {
name = "log-analytics"

target_resource_id = azurerm_storage_account.main.id
log_analytics_workspace_id = var.log_analytics_workspace_id

metric {
category = "Capacity"
}

metric {
category = "Transaction"
}
}

resource "azurerm_monitor_diagnostic_setting" "blob" {
name = "log-analytics"

target_resource_id = "${azurerm_storage_account.main.id}/blobServices/default"
log_analytics_workspace_id = var.log_analytics_workspace_id

enabled_log {
category_group = "audit"
}

metric {
category = "Transaction"
}
}

resource "azurerm_monitor_diagnostic_setting" "queue" {
name = "log-analytics"

target_resource_id = "${azurerm_storage_account.main.id}/queueServices/default"
log_analytics_workspace_id = var.log_analytics_workspace_id

enabled_log {
category_group = "audit"
}

metric {
category = "Transaction"
}
}

resource "azurerm_monitor_diagnostic_setting" "table" {
name = "log-analytics"

target_resource_id = "${azurerm_storage_account.main.id}/tableServices/default"
log_analytics_workspace_id = var.log_analytics_workspace_id

enabled_log {
category_group = "audit"
}

metric {
category = "Transaction"
}
}

resource "azurerm_monitor_diagnostic_setting" "file" {
name = "log-analytics"

target_resource_id = "${azurerm_storage_account.main.id}/fileServices/default"
log_analytics_workspace_id = var.log_analytics_workspace_id

enabled_log {
category_group = "audit"
}

metric {
category = "Transaction"
}
}
7 changes: 7 additions & 0 deletions modules/storage-account/src/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "id" {
value = azurerm_storage_account.main.id
}

output "name" {
value = azurerm_storage_account.main.name
}
10 changes: 10 additions & 0 deletions modules/storage-account/src/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = "~> 1.5"

required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.85"
}
}
}
50 changes: 50 additions & 0 deletions modules/storage-account/src/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
variable "account_tier" {
type = string
default = "Standard"
}

variable "account_replication_type" {
type = string
default = "ZRS"
}

variable "environment" {
type = string
}

variable "identifier" {
type = string
}

variable "location" {
type = string
}

variable "log_analytics_workspace_id" {
type = string
}

variable "resource_group_name" {
type = string
}

variable "tags" {
type = map(string)
default = {}
}

variable "workload_name" {
type = string
}

variable "workload_type" {
type = string
}

variable "workload_version" {
type = string
}

variable "zone" {
type = string
}
21 changes: 21 additions & 0 deletions modules/storage-account/test/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
provider "azurerm" {
features {}
}

module "storage_account" {
source = "../src"

environment = "bar"
identifier = "baz"
location = "uksouth"
log_analytics_workspace_id = "quz"
resource_group_name = "bar"
workload_name = "foo"
workload_type = "foo/bar"
workload_version = "1.0.0"
zone = "bat"

tags = {
Foo = "Bar"
}
}
10 changes: 10 additions & 0 deletions modules/storage-account/test/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = "~> 1.5"

required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.85"
}
}
}

0 comments on commit be5a3d7

Please sign in to comment.