Skip to content

Commit

Permalink
Replace azurerm vm with azurerm_linux
Browse files Browse the repository at this point in the history
  • Loading branch information
BillAnastasiadis committed Sep 26, 2023
1 parent c35d280 commit e7712cb
Show file tree
Hide file tree
Showing 14 changed files with 326 additions and 266 deletions.
61 changes: 61 additions & 0 deletions terraform/azure/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 44 additions & 42 deletions terraform/azure/modules/drbd_node/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -171,58 +171,60 @@ module "os_image_reference" {
os_image_srv_uri = var.drbd_image_uri != ""
}

resource "azurerm_virtual_machine" "drbd" {
count = var.drbd_count
name = "${var.name}${format("%02d", count.index + 1)}"
location = var.az_region
resource_group_name = var.resource_group_name
network_interface_ids = [element(azurerm_network_interface.drbd.*.id, count.index)]
availability_set_id = azurerm_availability_set.drbd-availability-set[0].id
vm_size = var.vm_size
delete_os_disk_on_termination = true
delete_data_disks_on_termination = true

storage_os_disk {
name = "disk-${var.name}${format("%02d", count.index + 1)}-Os"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Premium_LRS"
}
resource "azurerm_managed_disk" "drbd_data_disk" {
count = var.drbd_count
name = "disk-${var.name}${format("%02d", count.index + 1)}-Data01"
location = var.az_region
resource_group_name = var.resource_group_name
storage_account_type = "Standard_LRS"
create_option = "Empty"
disk_size_gb = 10
}

storage_image_reference {
id = var.drbd_image_uri != "" ? join(",", azurerm_image.drbd-image.*.id) : ""
publisher = var.drbd_image_uri != "" ? "" : module.os_image_reference.publisher
offer = var.drbd_image_uri != "" ? "" : module.os_image_reference.offer
sku = var.drbd_image_uri != "" ? "" : module.os_image_reference.sku
version = var.drbd_image_uri != "" ? "" : module.os_image_reference.version
}
resource "azurerm_virtual_machine_data_disk_attachment" "drbd_data_disk_attachment" {
count = var.drbd_count
managed_disk_id = element(azurerm_managed_disk.drbd_data_disk.*.id, count.index)
virtual_machine_id = element(azurerm_linux_virtual_machine.drbd.*.id, count.index)
lun = 0
caching = "ReadWrite"
}

storage_data_disk {
name = "disk-${var.name}${format("%02d", count.index + 1)}-Data01"
caching = "ReadWrite"
create_option = "Empty"
disk_size_gb = "10"
lun = "0"
managed_disk_type = "Standard_LRS"
resource "azurerm_linux_virtual_machine" "drbd" {
count = var.drbd_count
name = "${var.name}${format("%02d", count.index + 1)}"
location = var.az_region
resource_group_name = var.resource_group_name
network_interface_ids = [element(azurerm_network_interface.drbd.*.id, count.index)]
availability_set_id = azurerm_availability_set.drbd-availability-set[0].id
size = var.vm_size

admin_username = var.common_variables["authorized_user"]
admin_ssh_key {
username = var.common_variables["authorized_user"]
public_key = var.common_variables["public_key"]
}
disable_password_authentication = true

os_profile {
computer_name = "${local.hostname}${format("%02d", count.index + 1)}"
admin_username = var.common_variables["authorized_user"]
os_disk {
name = "disk-${var.name}${format("%02d", count.index + 1)}-Os"
caching = "ReadWrite"
storage_account_type = "Premium_LRS" # This replaces managed_disk_type
}

os_profile_linux_config {
disable_password_authentication = true

ssh_keys {
path = "/home/${var.common_variables["authorized_user"]}/.ssh/authorized_keys"
key_data = var.common_variables["public_key"]
dynamic "source_image_reference" {
for_each = var.drbd_image_uri != "" ? [] : [1]
content {
publisher = module.os_image_reference.publisher
offer = module.os_image_reference.offer
sku = module.os_image_reference.sku
version = module.os_image_reference.version
}
}

source_image_id = var.drbd_image_uri != "" ? join(",", azurerm_image.drbd-image.*.id) : null

boot_diagnostics {
enabled = "true"
storage_uri = var.storage_account
storage_account_uri = var.storage_account
}

tags = {
Expand Down
10 changes: 5 additions & 5 deletions terraform/azure/modules/drbd_node/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
data "azurerm_public_ip" "drbd" {
count = var.drbd_count
name = element(azurerm_public_ip.drbd.*.name, count.index)
resource_group_name = element(azurerm_virtual_machine.drbd.*.resource_group_name, count.index)
resource_group_name = element(azurerm_linux_virtual_machine.drbd.*.resource_group_name, count.index)
# depends_on is included to avoid the issue with `resource_group was not found`. Find an example in: https://github.com/terraform-providers/terraform-provider-azurerm/issues/8476
depends_on = [azurerm_virtual_machine.drbd]
depends_on = [azurerm_linux_virtual_machine.drbd]
}

data "azurerm_network_interface" "drbd" {
count = var.drbd_count
name = element(azurerm_network_interface.drbd.*.name, count.index)
resource_group_name = element(azurerm_virtual_machine.drbd.*.resource_group_name, count.index)
resource_group_name = element(azurerm_linux_virtual_machine.drbd.*.resource_group_name, count.index)
# depends_on is included to avoid the issue with `resource_group was not found`. Find an example in: https://github.com/terraform-providers/terraform-provider-azurerm/issues/8476
depends_on = [azurerm_virtual_machine.drbd]
depends_on = [azurerm_linux_virtual_machine.drbd]
}

output "drbd_ip" {
Expand All @@ -23,7 +23,7 @@ output "drbd_public_ip" {
}

output "drbd_name" {
value = azurerm_virtual_machine.drbd.*.name
value = azurerm_linux_virtual_machine.drbd.*.name
}

output "drbd_public_name" {
Expand Down
90 changes: 44 additions & 46 deletions terraform/azure/modules/hana_node/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -364,62 +364,60 @@ locals {
disks_writeaccelerator = [for writeaccelerator in split(",", var.hana_data_disks_configuration["writeaccelerator"]) : tobool(trimspace(writeaccelerator))]
}

resource "azurerm_virtual_machine" "hana" {
count = var.hana_count
name = "${var.name}${format("%02d", count.index + 1)}"
location = var.az_region
resource_group_name = var.resource_group_name
network_interface_ids = [element(azurerm_network_interface.hana.*.id, count.index)]
availability_set_id = var.common_variables["hana"]["ha_enabled"] ? azurerm_availability_set.hana-availability-set[0].id : null
vm_size = var.vm_size
delete_os_disk_on_termination = true
delete_data_disks_on_termination = true

storage_os_disk {
name = "disk-${var.name}${format("%02d", count.index + 1)}-Os"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Premium_LRS"
}
resource "azurerm_managed_disk" "hana_data_disk" {
count = var.hana_count * local.disks_number
name = "disk-${var.name}${format("%02d", floor(count.index / local.disks_number) + 1)}-Data${format("%02d", count.index % local.disks_number + 1)}"
location = var.az_region
resource_group_name = var.resource_group_name
storage_account_type = element(local.disks_type, count.index % local.disks_number)
create_option = "Empty"
disk_size_gb = element(local.disks_size, count.index % local.disks_number)
}

storage_image_reference {
id = var.sles4sap_uri != "" ? join(",", azurerm_image.sles4sap.*.id) : ""
publisher = var.sles4sap_uri != "" ? "" : module.os_image_reference.publisher
offer = var.sles4sap_uri != "" ? "" : module.os_image_reference.offer
sku = var.sles4sap_uri != "" ? "" : module.os_image_reference.sku
version = var.sles4sap_uri != "" ? "" : module.os_image_reference.version
resource "azurerm_virtual_machine_data_disk_attachment" "hana_data_disk_attachment" {
count = var.hana_count * local.disks_number
managed_disk_id = azurerm_managed_disk.hana_data_disk[count.index].id
virtual_machine_id = azurerm_linux_virtual_machine.hana[floor(count.index / local.disks_number)].id
lun = count.index % local.disks_number
caching = element(local.disks_caching, count.index % local.disks_number)
}

resource "azurerm_linux_virtual_machine" "hana" {
count = var.hana_count
name = "${var.name}${format("%02d", count.index + 1)}"
location = var.az_region
resource_group_name = var.resource_group_name
network_interface_ids = [element(azurerm_network_interface.hana.*.id, count.index)]
availability_set_id = var.common_variables["hana"]["ha_enabled"] ? azurerm_availability_set.hana-availability-set[0].id : null
size = var.vm_size

admin_username = var.common_variables["authorized_user"]
admin_ssh_key {
username = var.common_variables["authorized_user"]
public_key = var.common_variables["public_key"]
}
disable_password_authentication = true

dynamic "storage_data_disk" {
for_each = [for v in range(local.disks_number) : { index = v }]
dynamic "source_image_reference" {
for_each = var.sles4sap_uri != "" ? [] : [1]
content {
name = "disk-${var.name}${format("%02d", count.index + 1)}-Data${format("%02d", storage_data_disk.value.index + 1)}"
managed_disk_type = element(local.disks_type, storage_data_disk.value.index)
create_option = "Empty"
lun = storage_data_disk.value.index
disk_size_gb = element(local.disks_size, storage_data_disk.value.index)
caching = element(local.disks_caching, storage_data_disk.value.index)
write_accelerator_enabled = element(local.disks_writeaccelerator, storage_data_disk.value.index)
publisher = module.os_image_reference.publisher
offer = module.os_image_reference.offer
sku = module.os_image_reference.sku
version = module.os_image_reference.version
}
}

os_profile {
computer_name = "${local.hostname}${format("%02d", count.index + 1)}"
admin_username = var.common_variables["authorized_user"]
}
source_image_id = var.sles4sap_uri != "" ? join(",", azurerm_image.sles4sap.*.id) : null

os_profile_linux_config {
disable_password_authentication = true

ssh_keys {
path = "/home/${var.common_variables["authorized_user"]}/.ssh/authorized_keys"
key_data = var.common_variables["public_key"]
}
os_disk {
name = "disk-${var.name}${format("%02d", count.index + 1)}-Os"
caching = "ReadWrite"
storage_account_type = "Premium_LRS"
}

boot_diagnostics {
enabled = "true"
storage_uri = var.storage_account
storage_account_uri = var.storage_account
}

tags = {
Expand Down Expand Up @@ -449,4 +447,4 @@ module "hana_majority_maker" {
tenant_id = var.tenant_id
fence_agent_app_id = var.fence_agent_app_id
fence_agent_client_secret = var.fence_agent_client_secret
}
}
10 changes: 5 additions & 5 deletions terraform/azure/modules/hana_node/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
data "azurerm_public_ip" "hana" {
count = var.hana_count
name = element(azurerm_public_ip.hana.*.name, count.index)
resource_group_name = element(azurerm_virtual_machine.hana.*.resource_group_name, count.index)
resource_group_name = element(azurerm_linux_virtual_machine.hana.*.resource_group_name, count.index)
# depends_on is included to avoid the issue with `resource_group was not found`. Find an example in: https://github.com/terraform-providers/terraform-provider-azurerm/issues/8476
depends_on = [azurerm_virtual_machine.hana]
depends_on = [azurerm_linux_virtual_machine.hana]
}

data "azurerm_network_interface" "hana" {
count = var.hana_count
name = element(azurerm_network_interface.hana.*.name, count.index)
resource_group_name = element(azurerm_virtual_machine.hana.*.resource_group_name, count.index)
resource_group_name = element(azurerm_linux_virtual_machine.hana.*.resource_group_name, count.index)
# depends_on is included to avoid the issue with `resource_group was not found`. Find an example in: https://github.com/terraform-providers/terraform-provider-azurerm/issues/8476
depends_on = [azurerm_virtual_machine.hana]
depends_on = [azurerm_linux_virtual_machine.hana]
}

output "hana_ip" {
Expand All @@ -23,7 +23,7 @@ output "hana_public_ip" {
}

output "hana_name" {
value = azurerm_virtual_machine.hana.*.name
value = azurerm_linux_virtual_machine.hana.*.name
}

output "hana_public_name" {
Expand Down
Loading

0 comments on commit e7712cb

Please sign in to comment.