Skip to content

Commit 6bd1ba4

Browse files
author
Uros Randelovic
committed
- first commit
1 parent 4832632 commit 6bd1ba4

File tree

5 files changed

+221
-0
lines changed

5 files changed

+221
-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: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Create resource group
2+
resource "azurerm_resource_group" "example" {
3+
name = var.azurerm_resource_group_name
4+
location = var.location
5+
}
6+
7+
# Create security group
8+
resource "azurerm_network_security_group" "example" {
9+
name = var.azurerm_network_security_group_name
10+
location = azurerm_resource_group.example.location
11+
resource_group_name = azurerm_resource_group.example.name
12+
}
13+
14+
# Create a virtual network
15+
resource "azurerm_virtual_network" "example" {
16+
name = var.azurerm_virtual_network_name
17+
resource_group_name = azurerm_resource_group.example.name
18+
address_space = ["10.0.0.0/16"]
19+
location = azurerm_resource_group.example.location
20+
}
21+
22+
# Create a subnet
23+
resource "azurerm_subnet" "example" {
24+
name = var.azurerm_subnet_name
25+
resource_group_name = azurerm_resource_group.example.name
26+
virtual_network_name = azurerm_virtual_network.example.name
27+
address_prefixes = ["10.0.0.0/24"]
28+
29+
delegation {
30+
name = "managedinstancedelegation"
31+
32+
service_delegation {
33+
name = "Microsoft.Sql/managedInstances"
34+
actions = [
35+
"Microsoft.Network/virtualNetworks/subnets/join/action",
36+
"Microsoft.Network/virtualNetworks/subnets/prepareNetworkPolicies/action",
37+
"Microsoft.Network/virtualNetworks/subnets/unprepareNetworkPolicies/action"
38+
]
39+
}
40+
}
41+
}
42+
43+
# Associate subnet and the security group
44+
resource "azurerm_subnet_network_security_group_association" "example" {
45+
subnet_id = azurerm_subnet.example.id
46+
network_security_group_id = azurerm_network_security_group.example.id
47+
}
48+
49+
# Create a route table
50+
resource "azurerm_route_table" "example" {
51+
name = "routetable-mi-terraform"
52+
location = azurerm_resource_group.example.location
53+
resource_group_name = azurerm_resource_group.example.name
54+
disable_bgp_route_propagation = false
55+
depends_on = [
56+
azurerm_subnet.example,
57+
]
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+
# TODO set the options below either in plain text or in variables.tf
73+
# (var.xyz will prompt you to enter the value when creating the plan)
74+
administrator_login = var.administrator_login
75+
administrator_login_password = var.administrator_login_password
76+
license_type = var.license_type
77+
sku_name = var.sku_name
78+
vcores = var.vcores
79+
storage_size_in_gb = var.storage_size_in_gb
80+
81+
depends_on = [
82+
azurerm_subnet_network_security_group_association.example,
83+
azurerm_subnet_route_table_association.example,
84+
]
85+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# output "cosmosdb_account_id" {
2+
# value = azurerm_cosmosdb_account.example.id
3+
# }
4+
5+
# output "cosmosdb_sql_database_id" {
6+
# value = azurerm_cosmosdb_sql_database.example.id
7+
# }
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: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 = "eastus2euap"
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+
}
38+
39+
variable "database_name" {
40+
type = string
41+
description = "Enter database name"
42+
default = "sql-mi-terraform"
43+
}
44+
45+
variable "sku_name" {
46+
type = string
47+
description = "Enter SKU"
48+
default = "GP_Gen5"
49+
}
50+
variable "license_type" {
51+
type = string
52+
description = "Enter license type"
53+
default = "BasePrice"
54+
}
55+
variable "vcores" {
56+
type = string
57+
description = "Enter number of vCores you want to deploy"
58+
default = 8
59+
}
60+
variable "storage_size_in_gb" {
61+
type = string
62+
description = "Enter database name"
63+
default = 32
64+
}

0 commit comments

Comments
 (0)