Merge pull request #111 from urosran/sql-managed-instance
- SQL Managed Instance Minimal Example
This commit is contained in:
commit
329bfd1f6e
53
quickstart/101-managed-instance/README.md
Normal file
53
quickstart/101-managed-instance/README.md
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
# SQL Managed Instance Deployment - Minimal Example
|
||||||
|
|
||||||
|
## Terraform resource types
|
||||||
|
- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
|
||||||
|
- [azurerm_network_security_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_group)
|
||||||
|
- [azurerm_virtual_network](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network)
|
||||||
|
- [azurerm_subnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet)
|
||||||
|
- [azurerm_subnet_network_security_group_association](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet_network_security_group_association)
|
||||||
|
- [azurerm_route_table](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/route_table)
|
||||||
|
- [azurerm_subnet_route_table_association](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet_route_table_association)
|
||||||
|
- [azurerm_mssql_managed_instance](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mssql_managed_instance)
|
||||||
|
|
||||||
|
|
||||||
|
## Variables
|
||||||
|
All variables and their descriptions can be found in ./variables.tf. To see all available values for each variable
|
||||||
|
please refer to the links above. E.g. when choosing managed instance's number of cores
|
||||||
|
you can find all available values [here](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mssql_managed_instance).
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```bash
|
||||||
|
>terraform plan
|
||||||
|
|
||||||
|
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following
|
||||||
|
symbols:
|
||||||
|
+ create
|
||||||
|
|
||||||
|
Terraform will perform the following actions:
|
||||||
|
|
||||||
|
# azurerm_mssql_managed_instance.example will be created
|
||||||
|
+ resource "azurerm_mssql_managed_instance" "example" {
|
||||||
|
+ administrator_login = "VeryStrongAdministrator"
|
||||||
|
+ administrator_login_password = (sensitive value)
|
||||||
|
+ collation = "SQL_Latin1_General_CP1_CI_AS"
|
||||||
|
+ fqdn = (known after apply)
|
||||||
|
+ id = (known after apply)
|
||||||
|
+ license_type = "BasePrice"
|
||||||
|
+ location = "eastus2euap"
|
||||||
|
+ maintenance_configuration_name = "SQL_Default"
|
||||||
|
+ minimum_tls_version = "1.2"
|
||||||
|
+ name = "sql-mi-terraform"
|
||||||
|
+ proxy_override = "Default"
|
||||||
|
+ public_data_endpoint_enabled = false
|
||||||
|
+ resource_group_name = "terraform-database-resource-group"
|
||||||
|
+ sku_name = "GP_Gen5"
|
||||||
|
+ storage_account_type = "GRS"
|
||||||
|
+ storage_size_in_gb = 32
|
||||||
|
+ subnet_id = "/subscriptions/e775c3cd-e8af-412b-a951-d74761b2ebdf/resourceGroups/terraform-database-resource-group/providers/Microsoft.Network/virtualNetworks/vnet-mi-terraform/subnets/subnet-mi-terraform"
|
||||||
|
+ timezone_id = "UTC"
|
||||||
|
+ vcores = 8
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
78
quickstart/101-managed-instance/main.tf
Normal file
78
quickstart/101-managed-instance/main.tf
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
# TODO set the variables below either enter them in plain text after = sign, or change them in variables.tf
|
||||||
|
# (var.xyz will take the default value from variables.tf if you don't change it)
|
||||||
|
|
||||||
|
# Create resource group
|
||||||
|
resource "azurerm_resource_group" "example" {
|
||||||
|
name = var.azurerm_resource_group_name
|
||||||
|
location = var.location
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create security group
|
||||||
|
resource "azurerm_network_security_group" "example" {
|
||||||
|
name = var.azurerm_network_security_group_name
|
||||||
|
location = azurerm_resource_group.example.location
|
||||||
|
resource_group_name = azurerm_resource_group.example.name
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create a virtual network
|
||||||
|
resource "azurerm_virtual_network" "example" {
|
||||||
|
name = var.azurerm_virtual_network_name
|
||||||
|
resource_group_name = azurerm_resource_group.example.name
|
||||||
|
address_space = ["10.0.0.0/24"]
|
||||||
|
location = azurerm_resource_group.example.location
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create a subnet
|
||||||
|
resource "azurerm_subnet" "example" {
|
||||||
|
name = var.azurerm_subnet_name
|
||||||
|
resource_group_name = azurerm_resource_group.example.name
|
||||||
|
virtual_network_name = azurerm_virtual_network.example.name
|
||||||
|
address_prefixes = ["10.0.0.0/27"]
|
||||||
|
|
||||||
|
delegation {
|
||||||
|
name = "managedinstancedelegation"
|
||||||
|
|
||||||
|
service_delegation {
|
||||||
|
name = "Microsoft.Sql/managedInstances"
|
||||||
|
actions = [
|
||||||
|
"Microsoft.Network/virtualNetworks/subnets/join/action",
|
||||||
|
"Microsoft.Network/virtualNetworks/subnets/prepareNetworkPolicies/action",
|
||||||
|
"Microsoft.Network/virtualNetworks/subnets/unprepareNetworkPolicies/action"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Associate subnet and the security group
|
||||||
|
resource "azurerm_subnet_network_security_group_association" "example" {
|
||||||
|
subnet_id = azurerm_subnet.example.id
|
||||||
|
network_security_group_id = azurerm_network_security_group.example.id
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create a route table
|
||||||
|
resource "azurerm_route_table" "example" {
|
||||||
|
name = "routetable-mi-terraform"
|
||||||
|
location = azurerm_resource_group.example.location
|
||||||
|
resource_group_name = azurerm_resource_group.example.name
|
||||||
|
disable_bgp_route_propagation = false
|
||||||
|
}
|
||||||
|
|
||||||
|
# Associate subnet and the route table
|
||||||
|
resource "azurerm_subnet_route_table_association" "example" {
|
||||||
|
subnet_id = azurerm_subnet.example.id
|
||||||
|
route_table_id = azurerm_route_table.example.id
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create managed instance
|
||||||
|
resource "azurerm_mssql_managed_instance" "example" {
|
||||||
|
name = var.database_name
|
||||||
|
resource_group_name = azurerm_resource_group.example.name
|
||||||
|
location = azurerm_resource_group.example.location
|
||||||
|
subnet_id = azurerm_subnet.example.id
|
||||||
|
administrator_login = var.administrator_login
|
||||||
|
administrator_login_password = var.administrator_login_password
|
||||||
|
license_type = var.license_type
|
||||||
|
sku_name = var.sku_name
|
||||||
|
vcores = var.vcores
|
||||||
|
storage_size_in_gb = var.storage_size_in_gb
|
||||||
|
}
|
0
quickstart/101-managed-instance/outputs.tf
Normal file
0
quickstart/101-managed-instance/outputs.tf
Normal file
12
quickstart/101-managed-instance/providers.tf
Normal file
12
quickstart/101-managed-instance/providers.tf
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
terraform {
|
||||||
|
required_providers {
|
||||||
|
azurerm = {
|
||||||
|
source = "hashicorp/azurerm"
|
||||||
|
version = ">=3.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
provider "azurerm" {
|
||||||
|
features {}
|
||||||
|
}
|
65
quickstart/101-managed-instance/variables.tf
Normal file
65
quickstart/101-managed-instance/variables.tf
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
variable "azurerm_resource_group_name" {
|
||||||
|
type = string
|
||||||
|
description = "Enter the resource group name"
|
||||||
|
default = "terraform-database-resource-group"
|
||||||
|
}
|
||||||
|
variable "azurerm_network_security_group_name" {
|
||||||
|
type = string
|
||||||
|
description = "Enter the security group name"
|
||||||
|
default = "mi-security-group-terraform"
|
||||||
|
}
|
||||||
|
variable "azurerm_virtual_network_name" {
|
||||||
|
type = string
|
||||||
|
description = "Enter the virtual network name"
|
||||||
|
default = "vnet-mi-terraform"
|
||||||
|
}
|
||||||
|
variable "azurerm_subnet_name" {
|
||||||
|
type = string
|
||||||
|
description = "Enter subnet name"
|
||||||
|
default = "subnet-mi-terraform"
|
||||||
|
}
|
||||||
|
variable "location" {
|
||||||
|
type = string
|
||||||
|
description = "Enter the location where you want to deploy the resources"
|
||||||
|
default = "eastus"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "administrator_login" {
|
||||||
|
type = string
|
||||||
|
description = "Enter Administrator name for the database"
|
||||||
|
default = "VeryStrongAdministrator"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "administrator_login_password" {
|
||||||
|
type = string
|
||||||
|
description = "Enter administrator password for the database"
|
||||||
|
default = "IamAVeryStrongP@ssw0rd123"
|
||||||
|
sensitive = true
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "database_name" {
|
||||||
|
type = string
|
||||||
|
description = "Enter database name"
|
||||||
|
default = "sql-mi-terraform"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "sku_name" {
|
||||||
|
type = string
|
||||||
|
description = "Enter SKU"
|
||||||
|
default = "GP_Gen5"
|
||||||
|
}
|
||||||
|
variable "license_type" {
|
||||||
|
type = string
|
||||||
|
description = "Enter license type"
|
||||||
|
default = "BasePrice"
|
||||||
|
}
|
||||||
|
variable "vcores" {
|
||||||
|
type = number
|
||||||
|
description = "Enter number of vCores you want to deploy"
|
||||||
|
default = 8
|
||||||
|
}
|
||||||
|
variable "storage_size_in_gb" {
|
||||||
|
type = number
|
||||||
|
description = "Enter storage size in GB"
|
||||||
|
default = 32
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user