parent
6f269e7869
commit
327a771a19
@ -3,20 +3,20 @@
|
|||||||
|
|
||||||
# Create resource group
|
# Create resource group
|
||||||
resource "azurerm_resource_group" "example" {
|
resource "azurerm_resource_group" "example" {
|
||||||
name = var.azurerm_resource_group_name
|
name = "${random_pet.prefix.id}-rg"
|
||||||
location = var.location
|
location = var.location
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create security group
|
# Create security group
|
||||||
resource "azurerm_network_security_group" "example" {
|
resource "azurerm_network_security_group" "example" {
|
||||||
name = var.azurerm_network_security_group_name
|
name = "${random_pet.prefix.id}-nsg"
|
||||||
location = azurerm_resource_group.example.location
|
location = azurerm_resource_group.example.location
|
||||||
resource_group_name = azurerm_resource_group.example.name
|
resource_group_name = azurerm_resource_group.example.name
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create a virtual network
|
# Create a virtual network
|
||||||
resource "azurerm_virtual_network" "example" {
|
resource "azurerm_virtual_network" "example" {
|
||||||
name = var.azurerm_virtual_network_name
|
name = "${random_pet.prefix.id}-vnet"
|
||||||
resource_group_name = azurerm_resource_group.example.name
|
resource_group_name = azurerm_resource_group.example.name
|
||||||
address_space = ["10.0.0.0/24"]
|
address_space = ["10.0.0.0/24"]
|
||||||
location = azurerm_resource_group.example.location
|
location = azurerm_resource_group.example.location
|
||||||
@ -24,7 +24,7 @@ resource "azurerm_virtual_network" "example" {
|
|||||||
|
|
||||||
# Create a subnet
|
# Create a subnet
|
||||||
resource "azurerm_subnet" "example" {
|
resource "azurerm_subnet" "example" {
|
||||||
name = var.azurerm_subnet_name
|
name = "${random_pet.prefix.id}-subnet"
|
||||||
resource_group_name = azurerm_resource_group.example.name
|
resource_group_name = azurerm_resource_group.example.name
|
||||||
virtual_network_name = azurerm_virtual_network.example.name
|
virtual_network_name = azurerm_virtual_network.example.name
|
||||||
address_prefixes = ["10.0.0.0/27"]
|
address_prefixes = ["10.0.0.0/27"]
|
||||||
@ -51,7 +51,7 @@ resource "azurerm_subnet_network_security_group_association" "example" {
|
|||||||
|
|
||||||
# Create a route table
|
# Create a route table
|
||||||
resource "azurerm_route_table" "example" {
|
resource "azurerm_route_table" "example" {
|
||||||
name = "routetable-mi-terraform"
|
name = "${random_pet.prefix.id}-rt"
|
||||||
location = azurerm_resource_group.example.location
|
location = azurerm_resource_group.example.location
|
||||||
resource_group_name = azurerm_resource_group.example.name
|
resource_group_name = azurerm_resource_group.example.name
|
||||||
disable_bgp_route_propagation = false
|
disable_bgp_route_propagation = false
|
||||||
@ -64,15 +64,29 @@ resource "azurerm_subnet_route_table_association" "example" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Create managed instance
|
# Create managed instance
|
||||||
resource "azurerm_mssql_managed_instance" "example" {
|
resource "azurerm_mssql_managed_instance" "main" {
|
||||||
name = var.database_name
|
name = "${random_pet.prefix.id}-mssql"
|
||||||
resource_group_name = azurerm_resource_group.example.name
|
resource_group_name = azurerm_resource_group.example.name
|
||||||
location = azurerm_resource_group.example.location
|
location = azurerm_resource_group.example.location
|
||||||
subnet_id = azurerm_subnet.example.id
|
subnet_id = azurerm_subnet.example.id
|
||||||
administrator_login = var.administrator_login
|
administrator_login = "${replace(random_pet.prefix.id, "-", "")}admin"
|
||||||
administrator_login_password = var.administrator_login_password
|
administrator_login_password = random_password.password.result
|
||||||
license_type = var.license_type
|
license_type = var.license_type
|
||||||
sku_name = var.sku_name
|
sku_name = var.sku_name
|
||||||
vcores = var.vcores
|
vcores = var.vcores
|
||||||
storage_size_in_gb = var.storage_size_in_gb
|
storage_size_in_gb = var.storage_size_in_gb
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resource "random_password" "password" {
|
||||||
|
length = 20
|
||||||
|
min_lower = 1
|
||||||
|
min_upper = 1
|
||||||
|
min_numeric = 1
|
||||||
|
min_special = 1
|
||||||
|
special = true
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "random_pet" "prefix" {
|
||||||
|
prefix = var.prefix
|
||||||
|
length = 1
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
output "admin_login" {
|
||||||
|
value = azurerm_mssql_managed_instance.main.administrator_login
|
||||||
|
}
|
||||||
|
|
||||||
|
output "admin_login_password" {
|
||||||
|
sensitive = true
|
||||||
|
value = azurerm_mssql_managed_instance.main.administrator_login_password
|
||||||
|
}
|
@ -1,8 +1,14 @@
|
|||||||
terraform {
|
terraform {
|
||||||
|
required_version = ">= 1.0"
|
||||||
|
|
||||||
required_providers {
|
required_providers {
|
||||||
azurerm = {
|
azurerm = {
|
||||||
source = "hashicorp/azurerm"
|
source = "hashicorp/azurerm"
|
||||||
version = ">=3.0.0"
|
version = ">= 3.0, < 4.0"
|
||||||
|
}
|
||||||
|
random = {
|
||||||
|
source = "hashicorp/random"
|
||||||
|
version = ">= 3.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,63 +1,33 @@
|
|||||||
variable "azurerm_resource_group_name" {
|
variable "prefix" {
|
||||||
type = string
|
type = string
|
||||||
description = "Enter the resource group name"
|
default = "mi"
|
||||||
default = "terraform-database-resource-group"
|
description = "Prefix of the resource name"
|
||||||
}
|
|
||||||
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" {
|
variable "location" {
|
||||||
type = string
|
type = string
|
||||||
description = "Enter the location where you want to deploy the resources"
|
description = "Enter the location where you want to deploy the resources"
|
||||||
default = "eastus"
|
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" {
|
variable "sku_name" {
|
||||||
type = string
|
type = string
|
||||||
description = "Enter SKU"
|
description = "Enter SKU"
|
||||||
default = "GP_Gen5"
|
default = "GP_Gen5"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "license_type" {
|
variable "license_type" {
|
||||||
type = string
|
type = string
|
||||||
description = "Enter license type"
|
description = "Enter license type"
|
||||||
default = "BasePrice"
|
default = "BasePrice"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "vcores" {
|
variable "vcores" {
|
||||||
type = number
|
type = number
|
||||||
description = "Enter number of vCores you want to deploy"
|
description = "Enter number of vCores you want to deploy"
|
||||||
default = 8
|
default = 8
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "storage_size_in_gb" {
|
variable "storage_size_in_gb" {
|
||||||
type = number
|
type = number
|
||||||
description = "Enter storage size in GB"
|
description = "Enter storage size in GB"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user