-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
237 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Changelog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# MS SQL Database | ||
|
||
This module creates a [MS SQL Database](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mssql_database) and associated [Diagnostic Setting](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_diagnostic_setting). | ||
|
||
## Usage | ||
|
||
```hcl | ||
module "mssql_server" { | ||
source = "https://github.com/gofrontier-com/azurerm-terraform-modules/releases/download/mssql-database/[VERSION]/module.tar.gz//src" | ||
environment = "dev" | ||
identifier = "mortgages" | ||
location = "uksouth" | ||
resource_group_name = module.resource_group.name | ||
zone = "mtg" | ||
threat_detection_policy = { | ||
retention_days = 10 | ||
email_account_admins = true | ||
security_alert_email_addresses = ["[email protected]"] | ||
storage_account_access_key = "abc123" | ||
storage_endpoint = "endpoint" | ||
} | ||
log_analytics_workspace_id = data.azurerm_log_analytics_workspace.main.id | ||
tags = { | ||
WorkloadType = "MortgagesLZ/data-platform" | ||
} | ||
} | ||
``` | ||
|
||
## Known issues | ||
|
||
_None._ | ||
|
||
## Contributing | ||
|
||
See <https://github.com/gofrontier-com/azurerm-terraform-modules/blob/main/README.rst#contributing>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
locals { | ||
identifier = replace(lower(var.identifier), "/[^a-z1-9]/", "") | ||
|
||
short_locations = { | ||
"uksouth" = "uks" | ||
"ukwest" = "ukw" | ||
} | ||
|
||
tags = { | ||
Environment = var.environment | ||
Location = var.location | ||
Zone = var.zone | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
resource "azurerm_mssql_database" "main" { | ||
name = "sdb-ct-${var.environment}-${lookup(local.short_locations, var.location)}-${local.identifier}" | ||
server_id = var.sql_server_id | ||
max_size_gb = var.max_size_gb | ||
sku_name = var.sql_database_sku | ||
collation = var.sql_database_collation | ||
|
||
min_capacity = var.serverless_min_capacity | ||
auto_pause_delay_in_minutes = var.serverless_auto_pause_delay | ||
|
||
dynamic "threat_detection_policy" { | ||
for_each = var.threat_detection_policy != null ? [{}] : [] | ||
content { | ||
state = "Enabled" | ||
retention_days = var.threat_detection_policy.retention_days | ||
email_account_admins = var.threat_detection_policy.email_account_admins | ||
email_addresses = var.threat_detection_policy.security_alert_email_addresses | ||
storage_account_access_key = var.threat_detection_policy.storage_account_access_key | ||
storage_endpoint = var.threat_detection_policy.storage_endpoint | ||
} | ||
} | ||
|
||
tags = merge(var.tags, local.tags) | ||
|
||
lifecycle { | ||
prevent_destroy = true | ||
} | ||
} | ||
|
||
resource "azurerm_monitor_diagnostic_setting" "main" { | ||
name = "log-analytics" | ||
target_resource_id = azurerm_mssql_database.main.id | ||
log_analytics_workspace_id = var.log_analytics_workspace_id | ||
log_analytics_destination_type = "AzureDiagnostics" | ||
|
||
dynamic "enabled_log" { | ||
for_each = var.log_categories | ||
|
||
content { | ||
category = enabled_log.value | ||
} | ||
} | ||
|
||
dynamic "enabled_log" { | ||
for_each = var.log_category_groups | ||
|
||
content { | ||
category_group = enabled_log.value | ||
} | ||
} | ||
|
||
dynamic "metric" { | ||
for_each = var.metric_categories | ||
|
||
content { | ||
category = metric.value | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
output "id" { | ||
value = azurerm_mssql_database.main.id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
variable "environment" { | ||
type = string | ||
} | ||
|
||
variable "identifier" { | ||
type = string | ||
} | ||
|
||
variable "location" { | ||
type = string | ||
} | ||
|
||
variable "log_analytics_workspace_id" { | ||
type = string | ||
} | ||
|
||
variable "log_categories" { | ||
type = list(string) | ||
default = [] | ||
} | ||
|
||
variable "log_category_groups" { | ||
type = list(string) | ||
default = [] | ||
} | ||
|
||
variable "max_size_gb" { | ||
type = number | ||
default = 32 | ||
} | ||
|
||
variable "metric_categories" { | ||
type = list(string) | ||
default = [] | ||
} | ||
|
||
variable "retention_days" { | ||
type = string | ||
default = "30" | ||
} | ||
|
||
variable "security_alert_email_addresses" { | ||
type = list(string) | ||
default = [] | ||
} | ||
|
||
variable "serverless_min_capacity" { | ||
type = string | ||
default = null | ||
description = "Minimum capacity for serverless SKUs. Minimum value is 0.5 (vCore)." | ||
} | ||
|
||
variable "serverless_auto_pause_delay" { | ||
type = string | ||
default = null | ||
description = "The auto-pause delay for serverless SKUs. Minimum value is 60 (minutes)." | ||
} | ||
|
||
variable "sql_database_collation" { | ||
type = string | ||
default = "SQL_LATIN1_GENERAL_CP1_CI_AS" | ||
} | ||
|
||
variable "sql_database_sku" { | ||
type = string | ||
default = "GP_Gen5_2" | ||
} | ||
|
||
variable "sql_server_id" { | ||
type = string | ||
} | ||
|
||
variable "tags" { | ||
type = map(string) | ||
default = {} | ||
} | ||
|
||
variable "threat_detection_policy" { | ||
type = object({ | ||
retention_days = number | ||
email_account_admins = bool | ||
security_alert_email_addresses = list(string) | ||
storage_account_access_key = string | ||
storage_endpoint = string | ||
}) | ||
default = null | ||
} | ||
|
||
variable "zone" { | ||
type = string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
provider "azurerm" { | ||
features {} | ||
} | ||
|
||
module "mssql-server" { | ||
source = "../src" | ||
|
||
environment = "baz" | ||
identifier = "qux" | ||
location = "uksouth" | ||
zone = "waldo" | ||
|
||
log_analytics_workspace_id = "quux" | ||
sql_server_id = "123" | ||
|
||
tags = { | ||
Foo = "Bar" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |