Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.6.4 |
| <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) | 3.94.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | 3.94.0 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [azurerm_mssql_database.main](https://registry.terraform.io/providers/hashicorp/azurerm/3.94.0/docs/resources/mssql_database) | resource |
| [azurerm_client_config.current](https://registry.terraform.io/providers/hashicorp/azurerm/3.94.0/docs/data-sources/client_config) | data source |
| [azurerm_resource_group.main](https://registry.terraform.io/providers/hashicorp/azurerm/3.94.0/docs/data-sources/resource_group) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_databases"></a> [databases](#input\_databases) | Map of objects to configure MSSQL Database | <pre>map(object({<br> collation = optional(string, "SQL_Latin1_General_CP1_CI_AS")<br> sku = optional(string, "GP_S_Gen5_1")<br> max_size_gb = optional(string, "20")<br> min_capacity = optional(string, "0.5")<br> auto_pause_delay_in_minutes = optional(number, 60)<br> create_mode = optional(string, "Default")<br> creation_source_database_id = optional(string, null)<br> storage_account_type = optional(string, "ZRS")<br> }))</pre> | `{}` | no |
| <a name="input_default_retention_days"></a> [default\_retention\_days](#input\_default\_retention\_days) | Point In Time Restore configuration. Value has to be between 1 and 35. | `number` | `3` | no |
| <a name="input_default_tags"></a> [default\_tags](#input\_default\_tags) | A mapping of tags to assign to the resource. | `map(any)` | <pre>{<br> "ManagedByTerraform": "True"<br>}</pre> | no |
| <a name="input_resource_group_location"></a> [resource\_group\_location](#input\_resource\_group\_location) | Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. | `string` | `"West Europe"` | no |
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | The name of the resource group in which to create the Azure MSSQL and database component. Changing this forces a new resource to be created. | `string` | n/a | yes |
| <a name="input_server_id"></a> [server\_id](#input\_server\_id) | The id of the MS SQL Server on which to create the database. Changing this forces a new resource to be created. | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_sql_database_id"></a> [sql\_database\_id](#output\_sql\_database\_id) | The ID of the MS SQL Database. |
| <a name="output_sql_database_max_size"></a> [sql\_database\_max\_size](#output\_sql\_database\_max\_size) | The max size of the database in gigabytes. |
| <a name="output_sql_database_names"></a> [sql\_database\_names](#output\_sql\_database\_names) | The name of the MS SQL Database. |
| <a name="output_sql_server_id"></a> [sql\_server\_id](#output\_sql\_server\_id) | The ID of the MS SQL server |
| <a name="output_storage_account_type"></a> [storage\_account\_type](#output\_storage\_account\_type) | Storage account type used to store backups for this database |
<!-- END_TF_DOCS -->
9 changes: 9 additions & 0 deletions backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.94.0"
}
}
required_version = ">= 1.6.4"
}
39 changes: 39 additions & 0 deletions examples/mssql-database/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
provider "azurerm" {
features {}
}

data "azurerm_mssql_server" "main" {
name = "dev-63963882ddd-eus-sql"
resource_group_name = "dev-test-weu-rg"
}

module "mssql_database" {
source = "Think-Cube/mssql-database/azure"
version = "1.0.0"
resource_group_name = "dev-test-weu-rg"
environment = "dev"
region = "weu"
resource_group_location = "West Europe"
server_id = data.azurerm_mssql_server.main.id
databases = {
database1 = {
server_id = coalesce(var.server_id, data.azurerm_mssql_server.main.id)
collation = "SQL_Latin1_General_CP1_CI_AS"
sku = "GP_S_Gen5_1"
max_size_gb = "20"
min_capacity = "0.5"
auto_pause_delay_in_minutes = 60
create_mode = "Default"
creation_source_database_id = null
storage_account_type = "ZRS"
}
}
default_tags = {
Administrator = "John Doe"
Department = "IT"
CostCentre = "CC123"
ContactPerson = "Jane Smith"
ManagedByTerraform = "True"
}
depends_on = [ data.azurerm_mssql_server.main ]
}
5 changes: 5 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
data "azurerm_client_config" "current" {}

data "azurerm_resource_group" "main" {
name = var.resource_group_name
}
25 changes: 25 additions & 0 deletions mssql_database.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
resource "azurerm_mssql_database" "main" {
for_each = var.databases

name = each.key
server_id = var.server_id
collation = each.value.collation
sku_name = each.value.sku
max_size_gb = each.value.max_size_gb
min_capacity = each.value.min_capacity
auto_pause_delay_in_minutes = each.value.auto_pause_delay_in_minutes
create_mode = each.value.create_mode
creation_source_database_id = each.value.creation_source_database_id
storage_account_type = each.value.storage_account_type == "ZRS" ? "Zone" : "Geo"
tags = var.default_tags

short_term_retention_policy {
retention_days = lookup(each.value, "retention_days", var.default_retention_days)
}

lifecycle {
ignore_changes = [
sku_name,
]
}
}
29 changes: 29 additions & 0 deletions output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
output "sql_database_id" {
value = { for k, v in azurerm_mssql_database.main : k => v.id }
description = "The ID of the MS SQL Database."
sensitive = false
}

output "sql_server_id" {
value = { for k, v in azurerm_mssql_database.main : k => v.server_id }
description = "The ID of the MS SQL server"
sensitive = false
}

output "sql_database_names" {
value = { for k, v in azurerm_mssql_database.main : k => v.name }
description = "The name of the MS SQL Database."
sensitive = false
}

output "sql_database_max_size" {
value = { for k, v in azurerm_mssql_database.main : k => v.max_size_gb }
description = "The max size of the database in gigabytes."
sensitive = false
}

output "storage_account_type" {
value = { for k, v in azurerm_mssql_database.main : k => v.storage_account_type }
description = "Storage account type used to store backups for this database"
sensitive = false
}
48 changes: 48 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
###########################
# Common vars
###########################
variable "default_tags" {
description = "A mapping of tags to assign to the resource."
type = map(any)
default = {
"ManagedByTerraform" = "True"
}
}
###########################
# Resource groups vars
###########################
variable "resource_group_location" {
description = "Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created."
default = "West Europe"
type = string
}
variable "resource_group_name" {
description = "The name of the resource group in which to create the Azure MSSQL and database component. Changing this forces a new resource to be created."
type = string
}
###########################
# MSSQL database groups vars
###########################
variable "databases" {
type = map(object({
collation = optional(string, "SQL_Latin1_General_CP1_CI_AS")
sku = optional(string, "GP_S_Gen5_1")
max_size_gb = optional(string, "20")
min_capacity = optional(string, "0.5")
auto_pause_delay_in_minutes = optional(number, 60)
create_mode = optional(string, "Default")
creation_source_database_id = optional(string, null)
storage_account_type = optional(string, "ZRS")
}))
description = "Map of objects to configure MSSQL Database"
default = {}
}
variable "default_retention_days" {
type = number
description = "Point In Time Restore configuration. Value has to be between 1 and 35."
default = 3
}
variable "server_id" {
type = string
description = "The id of the MS SQL Server on which to create the database. Changing this forces a new resource to be created."
}
Loading