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

101-azure-sql-edge #392

Open
wants to merge 2 commits into
base: master
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
39 changes: 39 additions & 0 deletions quickstart/101-azure-sql-edge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Azure SQL Server and Database
This template deploys an Azure SQL Server and an Azure SQL Database.

## Terraform resource types

- [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet)
- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
- [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string)
- [azurerm_sql_server](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/sql_server)
- [azurerm_sql_database](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/sql_database)

## Variables

| Name | Description | Default value |
|-|-|-|
| `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg |
| `resource_group_location` | Location of the resource group. | eastus |
| `sql_server_name` | Name of the SQL Server resource. | "" |
| `sql_server_version` | Version of the SQL Server. | 12.0 |
| `sql_server_admin_login` | Administrator login for the SQL Server. | 4dm1n157r470r |
| `sql_server_admin_password` | Administrator login password for the SQL Server. | 4-v3ry-53cr37-p455w0rd |
| `sql_database_name` | Name of the SQL Database resource. | "" |
| `sql_database_sku_name` | SKU name for the SQL Database. | BC_Gen5_2 |
| `sql_database_sku_tier` | SKU tier for the SQL Database. | BusinessCritical |
| `sql_database_sku_capacity` | SKU capacity for the SQL Database. | 2 |
| `sql_database_max_size_gb` | Maximum size of the SQL Database in GB. | 100 |
| `sql_database_zone_redundant` | Whether the SQL Database is zone redundant. | true |
| `sql_database_read_scale` | Whether the SQL Database is read scale. | true |
| `sql_database_auto_pause_delay_in_minutes` | Auto pause delay of the SQL Database in minutes. | 60 |
| `sql_database_minimum_capacity` | Minimum capacity of the SQL Database. | 0.5 |
| `sql_database_create_mode` | Create mode of the SQL Database. | Default |
| `sql_database_collation` | Collation of the SQL Database. | SQL_Latin1_General_CP1_CI_AS |
| `sql_database_catalog_collation` | Catalog collation of the SQL Database. | SQL_Latin1_General_CP1_CI_AS |
| `sql_database_threat_detection_policy_state` | State of the threat detection policy of the SQL Database. | Enabled |
| `sql_database_threat_detection_policy_email_addresses` | Email addresses for the threat detection policy of the SQL Database. | ["[email protected]"] |
| `sql_database_threat_detection_policy_disabled_alerts` | Disabled alerts for the threat detection policy of the SQL Database. | ["Sql_Injection", "Data_Exfiltration"] |
| `sql_database_threat_detection_policy_retention_days` | Retention days for the threat detection policy of the SQL Database. | 20 |

## Example
65 changes: 65 additions & 0 deletions quickstart/101-azure-sql-edge/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
resource "random_pet" "rg_name" {
prefix = var.resource_group_name_prefix
}

resource "azurerm_resource_group" "rg" {
location = var.resource_group_location
name = random_pet.rg_name.id
}

resource "random_string" "azurerm_sql_server_name" {
length = 13
lower = true
numeric = false
special = false
upper = false
}

resource "azurerm_sql_server" "example" {
name = coalesce(var.sql_server_name, "sql-${random_string.azurerm_sql_server_name.result}")
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
version = var.sql_server_version
administrator_login = var.sql_server_admin_login
administrator_login_password = var.sql_server_admin_password
}

resource "random_string" "azurerm_sql_database_name" {
length = 13
lower = true
numeric = false
special = false
upper = false
}

resource "azurerm_sql_database" "example" {
name = coalesce(var.sql_database_name, "db-${random_string.azurerm_sql_database_name.result}")
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
server_name = azurerm_sql_server.example.name

sku {
name = var.sql_database_sku_name
tier = var.sql_database_sku_tier
capacity = var.sql_database_sku_capacity
}

max_size_gb = var.sql_database_max_size_gb
zone_redundant = var.sql_database_zone_redundant
read_scale = var.sql_database_read_scale
auto_pause_delay_in_minutes = var.sql_database_auto_pause_delay_in_minutes
minimum_capacity = var.sql_database_minimum_capacity
create_mode = var.sql_database_create_mode
collation = var.sql_database_collation
catalog_collation = var.sql_database_catalog_collation
threat_detection_policy {
state = var.sql_database_threat_detection_policy_state
email_addresses = var.sql_database_threat_detection_policy_email_addresses
disabled_alerts = var.sql_database_threat_detection_policy_disabled_alerts
retention_days = var.sql_database_threat_detection_policy_retention_days
}

lifecycle {
ignore_changes = [ app_settings ]
}
}
11 changes: 11 additions & 0 deletions quickstart/101-azure-sql-edge/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
output "resource_group_name" {
value = azurerm_resource_group.rg.name
}

output "sql_server_name" {
value = azurerm_sql_server.example.name
}

output "sql_database_name" {
value = azurerm_sql_database.example.name
}
18 changes: 18 additions & 0 deletions quickstart/101-azure-sql-edge/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
terraform {
required_version = ">=1.0"

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

provider "azurerm" {
features {}
}
131 changes: 131 additions & 0 deletions quickstart/101-azure-sql-edge/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
variable "resource_group_name_prefix" {
type = string
default = "rg"
description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription."
}

variable "resource_group_location" {
type = string
default = "eastus"
description = "Location of the resource group."
}

variable "sql_server_name" {
type = string
description = "The name of the SQL Server resource. The value will be randomly generated if blank."
default = ""
}

variable "sql_server_version" {
type = string
default = "12.0"
description = "Version of the SQL Server."
}

variable "sql_server_admin_login" {
type = string
default = "4dm1n157r470r"
description = "Administrator login for the SQL Server."
}

variable "sql_server_admin_password" {
type = string
default = "4-v3ry-53cr37-p455w0rd"
description = "Administrator login password for the SQL Server."
}

variable "sql_database_name" {
type = string
description = "The name of the SQL Database resource. The value will be randomly generated if blank."
default = ""
}

variable "sql_database_sku_name" {
type = string
default = "BC_Gen5_2"
description = "SKU name for the SQL Database."
}

variable "sql_database_sku_tier" {
type = string
default = "BusinessCritical"
description = "SKU tier for the SQL Database."
}

variable "sql_database_sku_capacity" {
type = number
default = 2
description = "SKU capacity for the SQL Database."
}

variable "sql_database_max_size_gb" {
type = number
default = 100
description = "Maximum size of the SQL Database in GB."
}

variable "sql_database_zone_redundant" {
type = bool
default = true
description = "Whether the SQL Database is zone redundant."
}

variable "sql_database_read_scale" {
type = bool
default = true
description = "Whether the SQL Database is read scale."
}

variable "sql_database_auto_pause_delay_in_minutes" {
type = number
default = 60
description = "Auto pause delay of the SQL Database in minutes."
}

variable "sql_database_minimum_capacity" {
type = number
default = 0.5
description = "Minimum capacity of the SQL Database."
}

variable "sql_database_create_mode" {
type = string
default = "Default"
description = "Create mode of the SQL Database."
}

variable "sql_database_collation" {
type = string
default = "SQL_Latin1_General_CP1_CI_AS"
description = "Collation of the SQL Database."
}

variable "sql_database_catalog_collation" {
type = string
default = "SQL_Latin1_General_CP1_CI_AS"
description = "Catalog collation of the SQL Database."
}

variable "sql_database_threat_detection_policy_state" {
type = string
default = "Enabled"
description = "State of the threat detection policy of the SQL Database."
}

variable "sql_database_threat_detection_policy_email_addresses" {
type = list(string)
default = ["[email protected]"]
description = "Email addresses for the threat detection policy of the SQL Database."
}

variable "sql_database_threat_detection_policy_disabled_alerts" {
type = list(string)
default = ["Sql_Injection", "Data_Exfiltration"]
description = "Disabled alerts for the threat detection policy of the SQL Database."
}

variable "sql_database_threat_detection_policy_retention_days" {
type = number
default = 20
description = "Retention days for the threat detection policy of the SQL Database."
}
Loading