diff --git a/main.tf b/main.tf index 016c0ce..3ff5f26 100644 --- a/main.tf +++ b/main.tf @@ -12,79 +12,79 @@ terraform { locals { - witnessName = "${var.witnessServerConfig.vmName}001" - vm1Name = "${var.sqlServerConfig.vmName}001" - vm2Name = "${var.sqlServerConfig.vmName}002" - backupStorageName = "sqlbck${random_string.random.result}stg" - lbSettings = { - sqlLBFE= "${var.sqlServerConfig.sqlLBName}-lbfe" - sqlLBBE= "${var.sqlServerConfig.sqlLBName}-lbbe" - sqlLBName= "${var.sqlServerConfig.sqlLBName}-lb" - } + witnessName = "${var.witnessServerConfig.vmName}001" + vm1Name = "${var.sqlServerConfig.vmName}001" + vm2Name = "${var.sqlServerConfig.vmName}002" + backupStorageName = "sqlbck${random_string.random.result}stg" + lbSettings = { + sqlLBFE = "${var.sqlServerConfig.sqlLBName}-lbfe" + sqlLBBE = "${var.sqlServerConfig.sqlLBName}-lbbe" + sqlLBName = "${var.sqlServerConfig.sqlLBName}-lb" + } - SQLAOProbe= "SQLAlwaysOnEndPointProbe" + SQLAOProbe = "SQLAlwaysOnEndPointProbe" - vmSettings= { - availabilitySets= { - sqlAvailabilitySetName= "${var.sqlServerConfig.vmName}-avs" - } - rdpPort= 3389 - } - sqlAOEPName = "${var.sqlServerConfig.vmName}-hadr" - sqlAOAGName = "${var.sqlServerConfig.vmName}-ag" - sqlAOListenerName = "${var.sqlServerConfig.vmName}-lis" - sharePath = "${var.sqlServerConfig.vmName}-fsw" - clusterName = "${var.sqlServerConfig.vmName}-cl" - sqlwNicName = "${var.witnessServerConfig.vmName}-nic" - keyVaultId = "${data.azurerm_key_vault.keyvaultsecrets.id}" + vmSettings = { + availabilitySets = { + sqlAvailabilitySetName = "${var.sqlServerConfig.vmName}-avs" + } + rdpPort = 3389 + } + sqlAOEPName = "${var.sqlServerConfig.vmName}-hadr" + sqlAOAGName = "${var.sqlServerConfig.vmName}-ag" + sqlAOListenerName = "${var.sqlServerConfig.vmName}-lis" + sharePath = "${var.sqlServerConfig.vmName}-fsw" + clusterName = "${var.sqlServerConfig.vmName}-cl" + sqlwNicName = "${var.witnessServerConfig.vmName}-nic" + keyVaultId = "${data.azurerm_key_vault.keyvaultsecrets.id}" } resource "random_string" "random" { - length = 8 + length = 8 special = false - upper = false + upper = false keepers = { - #generate new ID only when a new resource group is creted - resource_group = "${var.resource_group_name}" + #generate new ID only when a new resource group is creted + resource_group = "${var.resource_group_name}" } } #Create the diagnostic storage account resource "azurerm_storage_account" "sqldiag" { - name = "sqldiag${random_string.random.result}stg" - resource_group_name = "${var.resource_group_name}" - location = "${var.location}" - tags = "${var.tagValues}" - account_kind = "Storage" - account_tier = "${var.sqlServerConfig.storageAccountTier}" - account_replication_type = "${var.sqlServerConfig.storageAccountReplicationType}" - enable_blob_encryption = "${var.sqlServerConfig.diagBlobEncryptionEnabled}" - } + name = "sqldiag${random_string.random.result}stg" + resource_group_name = "${var.resource_group_name}" + location = "${var.location}" + tags = "${var.tagValues}" + account_kind = "Storage" + account_tier = "${var.sqlServerConfig.storageAccountTier}" + account_replication_type = "${var.sqlServerConfig.storageAccountReplicationType}" + //enable_blob_encryption = "${var.sqlServerConfig.diagBlobEncryptionEnabled}" +} #Create the storage account that will hold the SQL Backups resource "azurerm_storage_account" "sqlbackup" { - name = "${local.backupStorageName}" - location = "${var.location}" - resource_group_name = "${var.resource_group_name}" - tags = "${var.tagValues}" - account_tier = "${var.sqlServerConfig.storageAccountTier}" - account_replication_type = "${var.sqlServerConfig.storageAccountReplicationType}" - enable_blob_encryption = "${var.sqlServerConfig.sqlBackupConfig.enableEncryption}" - } + name = "${local.backupStorageName}" + location = "${var.location}" + resource_group_name = "${var.resource_group_name}" + tags = "${var.tagValues}" + account_tier = "${var.sqlServerConfig.storageAccountTier}" + account_replication_type = "${var.sqlServerConfig.storageAccountReplicationType}" + // enable_blob_encryption = "${var.sqlServerConfig.sqlBackupConfig.enableEncryption}" +} #Create the SQL Load Balencer resource "azurerm_lb" "sqlLB" { - name = local.lbSettings.sqlLBName - location = "${var.location}" - resource_group_name = "${var.resource_group_name}" - frontend_ip_configuration { - name = local.lbSettings.sqlLBFE - private_ip_address_allocation = "Static" - private_ip_address = "${var.sqlServerConfig.sqlLBIPAddress}" - subnet_id = data.azurerm_subnet.subnet.id - } - + name = local.lbSettings.sqlLBName + location = "${var.location}" + resource_group_name = "${var.resource_group_name}" + frontend_ip_configuration { + name = local.lbSettings.sqlLBFE + private_ip_address_allocation = "Static" + private_ip_address = "${var.sqlServerConfig.sqlLBIPAddress}" + subnet_id = data.azurerm_subnet.subnet.id + } + } #Create the load balencer backend pool @@ -110,34 +110,34 @@ resource "azurerm_network_interface_backend_address_pool_association" "sqlvm2BEA #Create the load balencer rules resource "azurerm_lb_rule" "sqlLBRule" { - resource_group_name = "${var.resource_group_name}" - loadbalancer_id = "${azurerm_lb.sqlLB.id}" + resource_group_name = "${var.resource_group_name}" + loadbalancer_id = "${azurerm_lb.sqlLB.id}" name = "${local.lbSettings.sqlLBName}-lbr" protocol = "Tcp" frontend_port = 1433 backend_port = 1433 frontend_ip_configuration_name = local.lbSettings.sqlLBFE - probe_id = "${azurerm_lb_probe.sqlLBProbe.id}" + probe_id = "${azurerm_lb_probe.sqlLBProbe.id}" } #Create a health probe for the load balencer resource "azurerm_lb_probe" "sqlLBProbe" { resource_group_name = "${var.resource_group_name}" loadbalancer_id = "${azurerm_lb.sqlLB.id}" - name = local.SQLAOProbe + name = local.SQLAOProbe port = 59999 protocol = "Tcp" interval_in_seconds = 5 - number_of_probes = 2 -} + number_of_probes = 2 +} #Create the primary SQL server module "sqlvm1" { source = "github.com/canada-ca-terraform-modules/terraform-azurerm-basicwindowsvm?ref=20190927.1" name = "${local.vm1Name}" - location = "${var.location}" - resource_group_name = "${var.resource_group_name}" + location = "${var.location}" + resource_group_name = "${var.resource_group_name}" admin_username = "${var.adminUsername}" admin_password = "${data.azurerm_key_vault_secret.localAdminPasswordSecret.value}" nic_subnetName = "${data.azurerm_subnet.subnet.name}" @@ -160,10 +160,10 @@ module "sqlvm2" { source = "github.com/canada-ca-terraform-modules/terraform-azurerm-basicwindowsvm?ref=20190927.1" name = "${local.vm2Name}" - location = "${var.location}" - resource_group_name = "${var.resource_group_name}" + location = "${var.location}" + resource_group_name = "${var.resource_group_name}" admin_username = "${var.adminUsername}" - admin_password = "${data.azurerm_key_vault_secret.localAdminPasswordSecret.value}" + admin_password = "${data.azurerm_key_vault_secret.localAdminPasswordSecret.value}" nic_subnetName = "${data.azurerm_subnet.subnet.name}" nic_vnetName = "${data.azurerm_virtual_network.vnet.name}" nic_resource_group_name = "${var.vnetConfig.existingVnetRG}" @@ -177,7 +177,7 @@ module "sqlvm2" { sku = "${var.sqlServerConfig.imageReference.sku}" version = "${var.sqlServerConfig.imageReference.version}" } - + } #Create the SQL Witness. Could be switched for a blob storage if desired @@ -185,10 +185,10 @@ module "sqlvmw" { source = "github.com/canada-ca-terraform-modules/terraform-azurerm-basicwindowsvm?ref=20190927.1" name = "${var.witnessServerConfig.vmName}001" - location = "${var.location}" - resource_group_name = "${var.resource_group_name}" + location = "${var.location}" + resource_group_name = "${var.resource_group_name}" admin_username = "${var.adminUsername}" - admin_password = "${data.azurerm_key_vault_secret.localAdminPasswordSecret.value}" + admin_password = "${data.azurerm_key_vault_secret.localAdminPasswordSecret.value}" nic_subnetName = "${data.azurerm_subnet.subnet.name}" nic_vnetName = "${data.azurerm_virtual_network.vnet.name}" nic_resource_group_name = "${var.vnetConfig.existingVnetRG}" @@ -207,22 +207,22 @@ module "sqlvmw" { #Create the SQL Availiability Sets for hardware and update redundancy resource "azurerm_availability_set" "sqlAS" { name = "${var.sqlServerConfig.vmName}-avs" - location = "${var.location}" + location = "${var.location}" resource_group_name = "${var.resource_group_name}" - managed = true + managed = true } #Configure the fileshare witness resource "azurerm_virtual_machine_extension" "CreateFileShareWitness" { name = "CreateFileShareWitness" - location = "${var.location}" - resource_group_name = "${var.resource_group_name}" + location = "${var.location}" + resource_group_name = "${var.resource_group_name}" virtual_machine_name = "${local.witnessName}-vm" publisher = "Microsoft.Powershell" type = "DSC" type_handler_version = "2.71" - depends_on = [module.sqlvmw, azurerm_storage_account.sqlbackup] - settings = < incremental (complete is too destructive in our case) -} \ No newline at end of file + + deployment_mode = "Incremental" # Deployment => incremental (complete is too destructive in our case) +}