Skip to content

Commit 329bfd1

Browse files
authored
Merge pull request microsoft#111 from urosran/sql-managed-instance
- SQL Managed Instance Minimal Example
2 parents f0587e9 + 25a6da8 commit 329bfd1

File tree

5 files changed

+208
-0
lines changed

5 files changed

+208
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# SQL Managed Instance Deployment - Minimal Example
2+
3+
## Terraform resource types
4+
- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
5+
- [azurerm_network_security_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_group)
6+
- [azurerm_virtual_network](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network)
7+
- [azurerm_subnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet)
8+
- [azurerm_subnet_network_security_group_association](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet_network_security_group_association)
9+
- [azurerm_route_table](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/route_table)
10+
- [azurerm_subnet_route_table_association](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet_route_table_association)
11+
- [azurerm_mssql_managed_instance](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mssql_managed_instance)
12+
13+
14+
## Variables
15+
All variables and their descriptions can be found in ./variables.tf. To see all available values for each variable
16+
please refer to the links above. E.g. when choosing managed instance's number of cores
17+
you can find all available values [here](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mssql_managed_instance).
18+
19+
## Usage
20+
21+
```bash
22+
>terraform plan
23+
24+
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following
25+
symbols:
26+
+ create
27+
28+
Terraform will perform the following actions:
29+
30+
# azurerm_mssql_managed_instance.example will be created
31+
+ resource "azurerm_mssql_managed_instance" "example" {
32+
+ administrator_login = "VeryStrongAdministrator"
33+
+ administrator_login_password = (sensitive value)
34+
+ collation = "SQL_Latin1_General_CP1_CI_AS"
35+
+ fqdn = (known after apply)
36+
+ id = (known after apply)
37+
+ license_type = "BasePrice"
38+
+ location = "eastus2euap"
39+
+ maintenance_configuration_name = "SQL_Default"
40+
+ minimum_tls_version = "1.2"
41+
+ name = "sql-mi-terraform"
42+
+ proxy_override = "Default"
43+
+ public_data_endpoint_enabled = false
44+
+ resource_group_name = "terraform-database-resource-group"
45+
+ sku_name = "GP_Gen5"
46+
+ storage_account_type = "GRS"
47+
+ storage_size_in_gb = 32
48+
+ subnet_id = "/subscriptions/e775c3cd-e8af-412b-a951-d74761b2ebdf/resourceGroups/terraform-database-resource-group/providers/Microsoft.Network/virtualNetworks/vnet-mi-terraform/subnets/subnet-mi-terraform"
49+
+ timezone_id = "UTC"
50+
+ vcores = 8
51+
}
52+
```
53+
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# TODO set the variables below either enter them in plain text after = sign, or change them in variables.tf
2+
# (var.xyz will take the default value from variables.tf if you don't change it)
3+
4+
# Create resource group
5+
resource "azurerm_resource_group" "example" {
6+
name = var.azurerm_resource_group_name
7+
location = var.location
8+
}
9+
10+
# Create security group
11+
resource "azurerm_network_security_group" "example" {
12+
name = var.azurerm_network_security_group_name
13+
location = azurerm_resource_group.example.location
14+
resource_group_name = azurerm_resource_group.example.name
15+
}
16+
17+
# Create a virtual network
18+
resource "azurerm_virtual_network" "example" {
19+
name = var.azurerm_virtual_network_name
20+
resource_group_name = azurerm_resource_group.example.name
21+
address_space = ["10.0.0.0/24"]
22+
location = azurerm_resource_group.example.location
23+
}
24+
25+
# Create a subnet
26+
resource "azurerm_subnet" "example" {
27+
name = var.azurerm_subnet_name
28+
resource_group_name = azurerm_resource_group.example.name
29+
virtual_network_name = azurerm_virtual_network.example.name
30+
address_prefixes = ["10.0.0.0/27"]
31+
32+
delegation {
33+
name = "managedinstancedelegation"
34+
35+
service_delegation {
36+
name = "Microsoft.Sql/managedInstances"
37+
actions = [
38+
"Microsoft.Network/virtualNetworks/subnets/join/action",
39+
"Microsoft.Network/virtualNetworks/subnets/prepareNetworkPolicies/action",
40+
"Microsoft.Network/virtualNetworks/subnets/unprepareNetworkPolicies/action"
41+
]
42+
}
43+
}
44+
}
45+
46+
# Associate subnet and the security group
47+
resource "azurerm_subnet_network_security_group_association" "example" {
48+
subnet_id = azurerm_subnet.example.id
49+
network_security_group_id = azurerm_network_security_group.example.id
50+
}
51+
52+
# Create a route table
53+
resource "azurerm_route_table" "example" {
54+
name = "routetable-mi-terraform"
55+
location = azurerm_resource_group.example.location
56+
resource_group_name = azurerm_resource_group.example.name
57+
disable_bgp_route_propagation = false
58+
}
59+
60+
# Associate subnet and the route table
61+
resource "azurerm_subnet_route_table_association" "example" {
62+
subnet_id = azurerm_subnet.example.id
63+
route_table_id = azurerm_route_table.example.id
64+
}
65+
66+
# Create managed instance
67+
resource "azurerm_mssql_managed_instance" "example" {
68+
name = var.database_name
69+
resource_group_name = azurerm_resource_group.example.name
70+
location = azurerm_resource_group.example.location
71+
subnet_id = azurerm_subnet.example.id
72+
administrator_login = var.administrator_login
73+
administrator_login_password = var.administrator_login_password
74+
license_type = var.license_type
75+
sku_name = var.sku_name
76+
vcores = var.vcores
77+
storage_size_in_gb = var.storage_size_in_gb
78+
}

quickstart/101-managed-instance/outputs.tf

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
terraform {
2+
required_providers {
3+
azurerm = {
4+
source = "hashicorp/azurerm"
5+
version = ">=3.0.0"
6+
}
7+
}
8+
}
9+
10+
provider "azurerm" {
11+
features {}
12+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
variable "azurerm_resource_group_name" {
2+
type = string
3+
description = "Enter the resource group name"
4+
default = "terraform-database-resource-group"
5+
}
6+
variable "azurerm_network_security_group_name" {
7+
type = string
8+
description = "Enter the security group name"
9+
default = "mi-security-group-terraform"
10+
}
11+
variable "azurerm_virtual_network_name" {
12+
type = string
13+
description = "Enter the virtual network name"
14+
default = "vnet-mi-terraform"
15+
}
16+
variable "azurerm_subnet_name" {
17+
type = string
18+
description = "Enter subnet name"
19+
default = "subnet-mi-terraform"
20+
}
21+
variable "location" {
22+
type = string
23+
description = "Enter the location where you want to deploy the resources"
24+
default = "eastus"
25+
}
26+
27+
variable "administrator_login" {
28+
type = string
29+
description = "Enter Administrator name for the database"
30+
default = "VeryStrongAdministrator"
31+
}
32+
33+
variable "administrator_login_password" {
34+
type = string
35+
description = "Enter administrator password for the database"
36+
default = "IamAVeryStrongP@ssw0rd123"
37+
sensitive = true
38+
}
39+
40+
variable "database_name" {
41+
type = string
42+
description = "Enter database name"
43+
default = "sql-mi-terraform"
44+
}
45+
46+
variable "sku_name" {
47+
type = string
48+
description = "Enter SKU"
49+
default = "GP_Gen5"
50+
}
51+
variable "license_type" {
52+
type = string
53+
description = "Enter license type"
54+
default = "BasePrice"
55+
}
56+
variable "vcores" {
57+
type = number
58+
description = "Enter number of vCores you want to deploy"
59+
default = 8
60+
}
61+
variable "storage_size_in_gb" {
62+
type = number
63+
description = "Enter storage size in GB"
64+
default = 32
65+
}

0 commit comments

Comments
 (0)