Skip to content

Commit d67df7e

Browse files
committed
azure: use MSI for native fencing (not user/pw needed)
1 parent f2a6477 commit d67df7e

File tree

17 files changed

+64
-174
lines changed

17 files changed

+64
-174
lines changed

azure/main.tf

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,6 @@ module "drbd_node" {
171171
iscsi_srv_ip = join("", module.iscsi_server.iscsisrv_ip)
172172
nfs_mounting_point = var.drbd_nfs_mounting_point
173173
nfs_export_name = var.netweaver_sid
174-
# only used by azure fence agent (native fencing)
175-
subscription_id = data.azurerm_subscription.current.subscription_id
176-
tenant_id = data.azurerm_subscription.current.tenant_id
177-
fence_agent_app_id = var.fence_agent_app_id
178-
fence_agent_client_secret = var.fence_agent_client_secret
179174
}
180175

181176
module "netweaver_node" {
@@ -215,11 +210,6 @@ module "netweaver_node" {
215210
anf_pool_name = local.anf_pool_name
216211
anf_pool_service_level = var.anf_pool_service_level
217212
netweaver_anf_quota_sapmnt = var.netweaver_anf_quota_sapmnt
218-
# only used by azure fence agent (native fencing)
219-
subscription_id = data.azurerm_subscription.current.subscription_id
220-
tenant_id = data.azurerm_subscription.current.tenant_id
221-
fence_agent_app_id = var.fence_agent_app_id
222-
fence_agent_client_secret = var.fence_agent_client_secret
223213
}
224214

225215
module "hana_node" {
@@ -254,11 +244,6 @@ module "hana_node" {
254244
hana_scale_out_anf_quota_log = var.hana_scale_out_anf_quota_log
255245
hana_scale_out_anf_quota_backup = var.hana_scale_out_anf_quota_backup
256246
hana_scale_out_anf_quota_shared = var.hana_scale_out_anf_quota_shared
257-
# only used by azure fence agent (native fencing)
258-
subscription_id = data.azurerm_subscription.current.subscription_id
259-
tenant_id = data.azurerm_subscription.current.tenant_id
260-
fence_agent_app_id = var.fence_agent_app_id
261-
fence_agent_client_secret = var.fence_agent_client_secret
262247
# passed to majority_maker module
263248
majority_maker_vm_size = var.hana_majority_maker_vm_size
264249
majority_maker_ip = local.hana_majority_maker_ip

azure/modules/drbd_node/salt_provisioner.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ partitions:
3737
1:
3838
start: 0%
3939
end: 100%
40-
subscription_id: ${var.subscription_id}
41-
tenant_id: ${var.tenant_id}
42-
resource_group_name: ${var.resource_group_name}
43-
fence_agent_app_id: ${var.fence_agent_app_id}
44-
fence_agent_client_secret: ${var.fence_agent_client_secret}
4540
EOF
4641
destination = "/tmp/grains"
4742
}

azure/modules/drbd_node/variables.tf

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,3 @@ variable "nfs_export_name" {
8686
type = string
8787
}
8888

89-
variable "subscription_id" {
90-
description = "ID of the azure subscription."
91-
type = string
92-
}
93-
94-
variable "tenant_id" {
95-
description = "ID of the azure tenant."
96-
type = string
97-
}
98-
99-
variable "fence_agent_app_id" {
100-
description = "ID of the azure service principal / application that is used for native fencing."
101-
type = string
102-
}
103-
104-
variable "fence_agent_client_secret" {
105-
description = "Secret for the azure service principal / application that is used for native fencing."
106-
type = string
107-
}

azure/modules/hana_node/main.tf

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,26 @@ locals {
2020
]) : toset([])
2121

2222
hana_lb_rules_ports_secondary = local.create_active_active_infra == 1 ? local.hana_lb_rules_ports : toset([])
23+
2324
hostname = var.common_variables["deployment_name_in_hostname"] ? format("%s-%s", var.common_variables["deployment_name"], var.name) : var.name
25+
hostnames_hana = [ for h in range(var.hana_count) : format("%s%02d", local.hostname, h + 1) ]
26+
hostname_mm = format("%s%s", local.hostname, "mm")
27+
hostnames = local.create_scale_out == 1 ? concat(local.hostnames_hana, [local.hostname_mm]) : local.hostnames_hana
28+
29+
principal_ids = concat(azurerm_virtual_machine.hana.*.identity.0.principal_id, [module.hana_majority_maker.fence_principal_id])
30+
fence_scopes = flatten([
31+
for c in range(var.hana_count + local.create_scale_out) : [
32+
for n in local.hostnames : {
33+
count = c
34+
node = element(local.hostnames, c)
35+
principal = element(local.principal_ids, c)
36+
scope = format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachines/%s", data.azurerm_subscription.current.subscription_id, var.resource_group_name, n)
37+
}
38+
]
39+
])
40+
}
41+
42+
data "azurerm_subscription" "current" {
2443
}
2544

2645
resource "azurerm_availability_set" "hana-availability-set" {
@@ -401,7 +420,7 @@ resource "azurerm_virtual_machine" "hana" {
401420
}
402421

403422
os_profile {
404-
computer_name = "${local.hostname}${format("%02d", count.index + 1)}"
423+
computer_name = element(local.hostnames_hana, count.index)
405424
admin_username = var.common_variables["authorized_user"]
406425
}
407426

@@ -419,15 +438,48 @@ resource "azurerm_virtual_machine" "hana" {
419438
storage_uri = var.storage_account
420439
}
421440

441+
identity {
442+
type = "SystemAssigned"
443+
}
444+
422445
tags = {
423446
workspace = var.common_variables["deployment_name"]
424447
}
425448
}
426449

450+
resource "azurerm_role_definition" "fence" {
451+
count = var.common_variables["hana"]["ha_enabled"] && var.common_variables["hana"]["fencing_mechanism"] == "native" ? 1 : 0
452+
name = "role-fence-${local.hostname}"
453+
# It is recommended to use the first entry of the assignable_scopes.
454+
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_definition#scope
455+
scope = format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachines/%s%02d", data.azurerm_subscription.current.subscription_id, var.resource_group_name, local.hostname, count.index + 1)
456+
457+
permissions {
458+
actions = [
459+
"Microsoft.Compute/*/read",
460+
"Microsoft.Compute/virtualMachines/powerOff/action",
461+
"Microsoft.Compute/virtualMachines/restart/action",
462+
"Microsoft.Compute/virtualMachines/start/action"
463+
]
464+
not_actions = []
465+
}
466+
467+
assignable_scopes = [
468+
for h in local.hostnames : format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachines/%s", data.azurerm_subscription.current.subscription_id, var.resource_group_name, h)
469+
]
470+
}
471+
472+
resource "azurerm_role_assignment" "host" {
473+
for_each = { for r in local.fence_scopes : "${r.node}_${r.scope}" => r if var.common_variables["hana"]["ha_enabled"] && var.common_variables["hana"]["fencing_mechanism"] == "native" }
474+
scope = each.value.scope
475+
role_definition_id = element(azurerm_role_definition.fence.*.role_definition_resource_id, 0)
476+
principal_id = each.value.principal
477+
}
478+
427479
module "hana_majority_maker" {
428480
source = "../majority_maker_node"
429481
node_count = local.create_scale_out
430-
name = var.name
482+
name = local.hostname
431483
common_variables = var.common_variables
432484
bastion_host = var.bastion_host
433485
az_region = var.az_region
@@ -446,11 +498,6 @@ module "hana_majority_maker" {
446498
cluster_ssh_key = var.cluster_ssh_key
447499
os_image = var.os_image
448500
iscsi_srv_ip = var.iscsi_srv_ip
449-
# only used by azure fence agent (native fencing)
450-
subscription_id = var.subscription_id
451-
tenant_id = var.tenant_id
452-
fence_agent_app_id = var.fence_agent_app_id
453-
fence_agent_client_secret = var.fence_agent_client_secret
454501
}
455502

456503
module "hana_on_destroy" {

azure/modules/hana_node/salt_provisioner.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ sbd_lun_index: 0
3232
iscsi_srv_ip: ${var.iscsi_srv_ip}
3333
cluster_ssh_pub: ${var.cluster_ssh_pub}
3434
cluster_ssh_key: ${var.cluster_ssh_key}
35-
subscription_id: ${var.subscription_id}
36-
tenant_id: ${var.tenant_id}
37-
resource_group_name: ${var.resource_group_name}
38-
fence_agent_app_id: ${var.fence_agent_app_id}
39-
fence_agent_client_secret: ${var.fence_agent_client_secret}
4035
anf_mount_ip:
4136
data: [ ${local.shared_storage_anf == 1 ? join(", ", azurerm_netapp_volume.hana-netapp-volume-data.*.mount_ip_addresses.0) : ""} ]
4237
log: [ ${local.shared_storage_anf == 1 ? join(", ", azurerm_netapp_volume.hana-netapp-volume-log.*.mount_ip_addresses.0) : ""} ]

azure/modules/hana_node/variables.tf

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -123,26 +123,6 @@ variable "hana_data_disks_configuration" {
123123
EOF
124124
}
125125

126-
variable "subscription_id" {
127-
description = "ID of the azure subscription."
128-
type = string
129-
}
130-
131-
variable "tenant_id" {
132-
description = "ID of the azure tenant."
133-
type = string
134-
}
135-
136-
variable "fence_agent_app_id" {
137-
description = "ID of the azure service principal / application that is used for native fencing."
138-
type = string
139-
}
140-
141-
variable "fence_agent_client_secret" {
142-
description = "Secret for the azure service principal / application that is used for native fencing."
143-
type = string
144-
}
145-
146126
variable "anf_account_name" {
147127
description = "Name of ANF Accounts"
148128
type = string

azure/modules/majority_maker_node/main.tf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ locals {
33
provisioning_address = local.bastion_enabled ? data.azurerm_network_interface.majority_maker.*.private_ip_address : data.azurerm_public_ip.majority_maker.*.ip_address
44
}
55

6-
76
# majority maker network configuration
87

98
resource "azurerm_network_interface" "majority_maker" {
@@ -66,7 +65,7 @@ module "os_image_reference" {
6665

6766
resource "azurerm_virtual_machine" "majority_maker" {
6867
count = var.node_count
69-
name = "vm${var.name}mm"
68+
name = "${var.name}mm"
7069
location = var.az_region
7170
resource_group_name = var.resource_group_name
7271
network_interface_ids = [element(azurerm_network_interface.majority_maker.*.id, count.index)]
@@ -90,7 +89,7 @@ resource "azurerm_virtual_machine" "majority_maker" {
9089
}
9190

9291
os_profile {
93-
computer_name = "vm${var.name}mm"
92+
computer_name = "${var.name}mm"
9493
admin_username = var.common_variables["authorized_user"]
9594
}
9695

@@ -108,6 +107,10 @@ resource "azurerm_virtual_machine" "majority_maker" {
108107
storage_uri = var.storage_account
109108
}
110109

110+
identity {
111+
type = "SystemAssigned"
112+
}
113+
111114
tags = {
112115
workspace = var.common_variables["deployment_name"]
113116
}

azure/modules/majority_maker_node/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ output "cluster_nodes_name" {
2929
output "cluster_nodes_public_name" {
3030
value = [data.azurerm_public_ip.majority_maker.*.fqdn]
3131
}
32+
33+
output "fence_principal_id" {
34+
value = var.common_variables["hana"]["fencing_mechanism"] == "native" ? azurerm_virtual_machine.majority_maker.0.identity.0.principal_id : null
35+
}

azure/modules/majority_maker_node/salt_provisioner.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ sbd_lun_index: 0
3131
iscsi_srv_ip: ${var.iscsi_srv_ip}
3232
cluster_ssh_pub: ${var.cluster_ssh_pub}
3333
cluster_ssh_key: ${var.cluster_ssh_key}
34-
subscription_id: ${var.subscription_id}
35-
tenant_id: ${var.tenant_id}
36-
resource_group_name: ${var.resource_group_name}
37-
fence_agent_app_id: ${var.fence_agent_app_id}
38-
fence_agent_client_secret: ${var.fence_agent_client_secret}
3934
node_count: ${var.hana_count + var.node_count}
4035
majority_maker_node: vm${var.name}mm
4136
majority_maker_ip: ${var.majority_maker_ip}

azure/modules/majority_maker_node/variables.tf

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,3 @@ variable "cluster_ssh_key" {
9090
description = "path for the private key needed by the cluster"
9191
type = string
9292
}
93-
94-
variable "subscription_id" {
95-
description = "ID of the azure subscription."
96-
type = string
97-
}
98-
99-
variable "tenant_id" {
100-
description = "ID of the azure tenant."
101-
type = string
102-
}
103-
104-
variable "fence_agent_app_id" {
105-
description = "ID of the azure service principal / application that is used for native fencing."
106-
type = string
107-
}
108-
109-
variable "fence_agent_client_secret" {
110-
description = "Secret for the azure service principal / application that is used for native fencing."
111-
type = string
112-
}

azure/modules/netweaver_node/salt_provisioner.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ iscsi_srv_ip: ${var.iscsi_srv_ip}
3636
storage_account_name: ${var.storage_account_name}
3737
storage_account_key: ${var.storage_account_key}
3838
storage_account_path: ${var.storage_account_path}
39-
subscription_id: ${var.subscription_id}
40-
tenant_id: ${var.tenant_id}
41-
resource_group_name: ${var.resource_group_name}
42-
fence_agent_app_id: ${var.fence_agent_app_id}
43-
fence_agent_client_secret: ${var.fence_agent_client_secret}
4439
anf_mount_ip:
4540
sapmnt: [ ${local.shared_storage_anf == 1 ? join(", ", azurerm_netapp_volume.netweaver-netapp-volume-sapmnt.*.mount_ip_addresses.0) : ""} ]
4641
EOF

azure/modules/netweaver_node/variables.tf

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -149,26 +149,6 @@ variable "cluster_ssh_key" {
149149
type = string
150150
}
151151

152-
variable "subscription_id" {
153-
description = "ID of the azure subscription."
154-
type = string
155-
}
156-
157-
variable "tenant_id" {
158-
description = "ID of the azure tenant."
159-
type = string
160-
}
161-
162-
variable "fence_agent_app_id" {
163-
description = "ID of the azure service principal / application that is used for native fencing."
164-
type = string
165-
}
166-
167-
variable "fence_agent_client_secret" {
168-
description = "Secret for the azure service principal / application that is used for native fencing."
169-
type = string
170-
}
171-
172152
variable "anf_account_name" {
173153
description = "Name of ANF Accounts"
174154
type = string

azure/terraform.tfvars.example

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,6 @@ cluster_ssh_key = "salt://sshkeys/cluster.id_rsa"
132132
# true or false (default)
133133
#hwcct = false
134134

135-
# Variables used with native fencing (azure fence agent)
136-
# Make sure to check out the documentation:
137-
# https://docs.microsoft.com/en-us/azure/virtual-machines/workloads/sap/high-availability-guide-suse-pacemaker#create-azure-fence-agent-stonith-device
138-
# The fencing mechanism has to be defined on a per cluster basis.
139-
# fence_agent_app_id = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" # login
140-
# fence_agent_client_secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # password
141-
142135
##########################
143136
# Bastion (jumpbox) machine variables
144137
##########################

azure/variables.tf

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,19 +1001,6 @@ variable "pre_deployment" {
10011001
default = false
10021002
}
10031003

1004-
# native fencing
1005-
variable "fence_agent_app_id" {
1006-
description = "ID of the azure service principal / application that is used for native fencing."
1007-
type = string
1008-
default = ""
1009-
}
1010-
1011-
variable "fence_agent_client_secret" {
1012-
description = "Secret for the azure service principal / application that is used for native fencing."
1013-
type = string
1014-
default = ""
1015-
}
1016-
10171004
# ANF shared storage
10181005
variable "anf_account_name" {
10191006
description = "Name of ANF Accounts"

pillar_examples/automatic/drbd/cluster.sls

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,3 @@ cluster:
6464
virtual_ip_mask: 24
6565
{% endif %}
6666
native_fencing: {{ grains['fencing_mechanism'] == 'native' }}
67-
{% if grains['fencing_mechanism'] == 'native' %}
68-
{% if grains['provider'] == 'azure' %}
69-
# only used by azure fence agent (native fencing)
70-
azure_subscription_id: {{ grains['subscription_id'] }}
71-
azure_resource_group_name: {{ grains['resource_group_name'] }}
72-
azure_tenant_id: {{ grains['tenant_id'] }}
73-
azure_fence_agent_app_id: {{ grains['fence_agent_app_id'] }}
74-
azure_fence_agent_client_secret: {{ grains['fence_agent_client_secret'] }}
75-
{% endif %}
76-
{% endif %}

pillar_examples/automatic/hana/cluster.sls

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,6 @@ cluster:
112112
virtual_ip_secondary: {{ grains['hana_cluster_vip_secondary'] }}
113113
{% endif %}
114114
native_fencing: {{ grains['fencing_mechanism'] == 'native' }}
115-
{% if grains['fencing_mechanism'] == 'native' %}
116-
{% if grains['provider'] == 'azure' %}
117-
# only used by azure fence agent (native fencing)
118-
azure_subscription_id: {{ grains['subscription_id'] }}
119-
azure_resource_group_name: {{ grains['resource_group_name'] }}
120-
azure_tenant_id: {{ grains['tenant_id'] }}
121-
azure_fence_agent_app_id: {{ grains['fence_agent_app_id'] }}
122-
azure_fence_agent_client_secret: {{ grains['fence_agent_client_secret'] }}
123-
{% endif %}
124-
{% endif %}
125115
{% if grains['scenario_type'] == 'cost-optimized' %}
126116
prefer_takeover: false
127117
{% else %}

0 commit comments

Comments
 (0)