SAP 部署自動化架構 會針對 Azure 資源命名使用標準命名慣例。
Terraform 模組 sap_namegenerator 會定義自動化架構部署的所有資源名稱。 模組位於 /deploy/terraform/terraform-units/modules/sap_namegenerator/ 存放庫中。 架構也支援使用 參數檔案,為某些資源提供您自己的名稱。
資源的命名會使用下列格式:
資源前置詞 + resource_group_prefix + 分隔符 + 資源名稱 + 資源後綴。
如果這些功能不夠,您也可以藉由提供包含資源名稱的自定義 JSON 檔案,或修改自動化所使用的命名模組,來使用自定義命名邏輯。
使用 JSON 檔案提供名稱覆寫
您可以使用 tfvars 參數,在 name_override_file 參數檔案中指定一個自定義命名的 JSON 檔案。
JSON 檔案具有不同資源類型的區段。
部署類型如下:
- DEPLOYER(控制平面)
- SDU (SAP 系統基礎結構)
- WORKLOAD_ZONE (工作負載區域)
可用性設定組名稱
可用性設定組的名稱定義於結構中 availabilityset_names 。 下列範例會列出部署的可用性設定組名稱。
"availabilityset_names" : {
"app": "app-avset",
"db" : "db-avset",
"scs": "scs-avset",
"web": "web-avset"
}
金鑰保存庫名稱
金鑰保存庫的名稱定義於 結構中 keyvault_names 。 下列範例會列出西歐環境中部署的 DEV 金鑰保存庫名稱。
"keyvault_names": {
"DEPLOYER": {
"private_access": "DEVWEEUprvtABC",
"user_access": "DEVWEEUuserABC"
},
"SDU": {
"private_access": "DEVWEEUSAP01X00pABC",
"user_access": "DEVWEEUSAP01X00uABC"
},
"WORKLOAD_ZONE": {
"private_access": "DEVWEEUSAP01prvtABC",
"user_access": "DEVWEEUSAP01userABC"
}
}
金鑰保存庫名稱在整個 Azure 中必須是唯一的。 SAP 部署自動化架構會在金鑰保存庫名稱的結尾附加三個隨機字元(ABC),以減少名稱衝突的可能性。
private_access 名稱目前未使用。
儲存體帳戶名稱
記憶體帳戶的名稱定義在結構中 storageaccount_names 。 下列範例列出在西歐 DEV 環境中部署的儲存體帳戶名稱。
"storageaccount_names": {
"DEPLOYER": "devweeudiagabc",
"LIBRARY": {
"library_storageaccount_name": "devweeusaplibabc",
"terraformstate_storageaccount_name": "devweeutfstateabc"
},
"SDU": "devweeusap01diagabc",
"WORKLOAD_ZONE": {
"landscape_shared_transport_storage_account_name": "devweeusap01sharedabc",
"landscape_storageaccount_name": "devweeusap01diagabc",
"witness_storageaccount_name": "devweeusap01witnessabc"
}
}
金鑰保存庫名稱在整個 Azure 中必須是唯一的。 SAP 部署自動化架構會在金鑰保存庫名稱的結尾附加三個隨機字元(abc),以減少名稱衝突的可能性。
虛擬機器名稱
虛擬機的名稱定義於結構中 virtualmachine_names 。 您可以同時提供電腦和虛擬機名稱。
下列範例會列出西歐環境中部署的 DEV 虛擬機名稱。 部署具有資料庫伺服器、兩部應用程式伺服器、中央服務伺服器和 Web 發送器。
"virtualmachine_names": {
"ANCHOR_COMPUTERNAME": [],
"ANCHOR_SECONDARY_DNSNAME": [],
"ANCHOR_VMNAME": [],
"ANYDB_COMPUTERNAME": [
"x00db00l0abc"
],
"ANYDB_SECONDARY_DNSNAME": [
"x00dhdb00l0abc",
"x00dhdb00l1abc"
],
"ANYDB_VMNAME": [
"x00db00l0abc"
],
"APP_COMPUTERNAME": [
"x00app00labc",
"x00app01labc"
],
"APP_SECONDARY_DNSNAME": [
"x00app00labc",
"x00app01labc"
],
"APP_VMNAME": [
"x00app00labc",
"x00app01labc"
],
"DEPLOYER": [
"devweeudeploy00"
],
"HANA_COMPUTERNAME": [
"x00dhdb00l0af"
],
"HANA_SECONDARY_DNSNAME": [
"x00dhdb00l0abc"
],
"HANA_VMNAME": [
"x00dhdb00l0abc"
],
"ISCSI_COMPUTERNAME": [
"devsap01weeuiscsi00"
],
"OBSERVER_COMPUTERNAME": [
"x00observer00labc"
],
"OBSERVER_VMNAME": [
"x00observer00labc"
],
"SCS_COMPUTERNAME": [
"x00scs00labc"
],
"SCS_SECONDARY_DNSNAME": [
"x00scs00labc"
],
"SCS_VMNAME": [
"x00scs00labc"
],
"WEB_COMPUTERNAME": [
"x00web00labc"
],
"WEB_SECONDARY_DNSNAME": [
"x00web00labc"
],
"WEB_VMNAME": [
"x00web00labc"
]
}
設定自定義命名模組
模組內有多個檔案可供命名資源:
- 虛擬機和計算機名稱定義於 (
vm.tf)。 - 資源群組命名定義於 (
resourcegroup.tf)。 - 金鑰保存庫定義於 (
keyvault.tf)。 - 資源後綴定義於 (
variables_local.tf)。
不同的資源名稱會以 Terraform 程式代碼中的前置詞來識別:
- SAP 部署程式部署會使用具有前置詞
deployer_的資源名稱。 - SAP 連結庫部署會使用具有前置詞
library的資源名稱。 - SAP 橫向部署會使用具有前置詞
vnet_的資源名稱。 - SAP 系統部署會使用具有前置詞
sdu_的資源名稱。
計算名稱會在數據字典中傳回,而數據字典是由所有 Terraform 模組使用。
使用自定義名稱
在參數檔案中 tfvars 提供參數,即可變更某些資源名稱。
| 資源 | 參數 | 註釋 |
|---|---|---|
Prefix |
custom_prefix |
作為資源群組中所有資源的名稱前綴使用 |
Resource group |
resourcegroup_name |
|
admin subnet name |
admin_subnet_name |
|
admin nsg name |
admin_subnet_nsg_name |
|
db subnet name |
db_subnet_name |
|
db nsg name |
db_subnet_nsg_name |
|
app subnet name |
app_subnet_name |
|
app nsg name |
app_subnet_nsg_name |
|
web subnet name |
web_subnet_name |
|
web nsg name |
web_subnet_nsg_name |
|
admin nsg name |
admin_subnet_nsg_name |
變更命名模組
若要準備 Terraform 環境以進行自定義命名,您必須先建立自定義命名模組。 最簡單的方式是複製現有的模組,並在複製的模組中進行必要的變更。
- 在 Terraform 環境中建立根層級資料夾。 例如
Azure_SAP_Automated_Deployment。 - 移至新的根層級資料夾。
- 複製 自動化架構存放庫。 此步驟會建立新的資料夾
sap-automation。 - 在名為
Contoso_naming的根層級資料夾內建立資料夾。 - 移至
sap-automation資料夾。 - 請查看 Git 中的適當分支。
- 移至
\deploy\terraform\terraform-units\modules資料夾中的sap-automation。 - 將資料夾
sap_namegenerator複製到Contoso_naming資料夾。
從根 terraform 資料夾呼叫命名模組:
module "sap_namegenerator" {
source = "../../terraform-units/modules/sap_namegenerator"
environment = local.infrastructure.environment
location = local.infrastructure.region
codename = lower(try(local.infrastructure.codename, ""))
random_id = module.common_infrastructure.random_id
sap_vnet_name = local.vnet_logical_name
sap_sid = local.sap_sid
db_sid = local.db_sid
app_ostype = try(local.application.os.os_type, "LINUX")
anchor_ostype = upper(try(local.anchor_vms.os.os_type, "LINUX"))
db_ostype = try(local.databases[0].os.os_type, "LINUX")
db_server_count = var.database_server_count
app_server_count = try(local.application.application_server_count, 0)
web_server_count = try(local.application.webdispatcher_count, 0)
scs_server_count = local.application.scs_high_availability ? 2 * local.application.scs_server_count : local.application.scs_server_count
app_zones = local.app_zones
scs_zones = local.scs_zones
web_zones = local.web_zones
db_zones = local.db_zones
resource_offset = try(var.options.resource_offset, 0)
custom_prefix = var.custom_prefix
}
接下來,您必須將其他 Terraform 模組檔案指向您的自定義命名模組。 這些模組檔案包括:
deploy\terraform\run\sap_system\module.tfdeploy\terraform\bootstrap\sap_deployer\module.tfdeploy\terraform\bootstrap\sap_library\module.tfdeploy\terraform\run\sap_library\module.tfdeploy\terraform\run\sap_deployer\module.tf
針對每個檔案,將模組 sap_namegenerator 的來源變更為指向新命名模組的位置。 例如:
module "sap_namegenerator" { source = "../../terraform-units/modules/sap_namegenerator" 變成 module "sap_namegenerator" { source = "../../../../Contoso_naming"。
變更資源群組命名邏輯
若要變更資源群組的命名邏輯,請移至您的自訂命名模組資料夾(例如 )。 Workspaces\Contoso_naming 然後,編輯 檔案 resourcegroup.tf。 使用您自己的命名邏輯修改下列程序代碼。
locals {
// Resource group naming
sdu_name = length(var.codename) > 0 ? (
upper(format("%s-%s-%s_%s-%s", local.env_verified, local.location_short, local.sap_vnet_verified, var.codename, var.sap_sid))) : (
upper(format("%s-%s-%s-%s", local.env_verified, local.location_short, local.sap_vnet_verified, var.sap_sid))
)
deployer_name = upper(format("%s-%s-%s", local.deployer_env_verified, local.deployer_location_short, local.dep_vnet_verified))
landscape_name = upper(format("%s-%s-%s", local.landscape_env_verified, local.location_short, local.sap_vnet_verified))
library_name = upper(format("%s-%s", local.library_env_verified, local.location_short))
// Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. The name must be unique.
deployer_storageaccount_name = substr(replace(lower(format("%s%s%sdiag%s", local.deployer_env_verified, local.deployer_location_short, local.dep_vnet_verified, local.random_id_verified)), "/[^a-z0-9]/", ""), 0, var.azlimits.stgaccnt)
landscape_storageaccount_name = substr(replace(lower(format("%s%s%sdiag%s", local.landscape_env_verified, local.location_short, local.sap_vnet_verified, local.random_id_verified)), "/[^a-z0-9]/", ""), 0, var.azlimits.stgaccnt)
library_storageaccount_name = substr(replace(lower(format("%s%ssaplib%s", local.library_env_verified, local.location_short, local.random_id_verified)), "/[^a-z0-9]/", ""), 0, var.azlimits.stgaccnt)
sdu_storageaccount_name = substr(replace(lower(format("%s%s%sdiag%s", local.env_verified, local.location_short, local.sap_vnet_verified, local.random_id_verified)), "/[^a-z0-9]/", ""), 0, var.azlimits.stgaccnt)
terraformstate_storageaccount_name = substr(replace(lower(format("%s%stfstate%s", local.library_env_verified, local.location_short, local.random_id_verified)), "/[^a-z0-9]/", ""), 0, var.azlimits.stgaccnt)
}
變更資源後綴
若要變更您的資源後綴,請移至您的自定義命名模組資料夾(例如 , Workspaces\Contoso_naming)。 然後,編輯 檔案 variables_local.tf。 請修改以下地圖,使用您自己的資源後綴。
備註
只變更地圖 值。 請勿更改 Terraform 代碼所使用的映射 鍵。
例如,如果您想要重新命名系統管理員網路介面元件,請將 變更 "admin-nic" = "-admin-nic" 為 "admin-nic" = "yourNICname"。
variable resource_suffixes {
type = map(string)
description = "Extension of resource name"
default = {
"admin_nic" = "-admin-nic"
"admin_subnet" = "admin-subnet"
"admin_subnet_nsg" = "adminSubnet-nsg"
"app_alb" = "app-alb"
"app_avset" = "app-avset"
"app_subnet" = "app-subnet"
"app_subnet_nsg" = "appSubnet-nsg"
"db_alb" = "db-alb"
"db_alb_bepool" = "dbAlb-bePool"
"db_alb_feip" = "dbAlb-feip"
"db_alb_hp" = "dbAlb-hp"
"db_alb_rule" = "dbAlb-rule_"
"db_avset" = "db-avset"
"db_nic" = "-db-nic"
"db_subnet" = "db-subnet"
"db_subnet_nsg" = "dbSubnet-nsg"
"deployer_rg" = "-INFRASTRUCTURE"
"deployer_state" = "_DEPLOYER.terraform.tfstate"
"deployer_subnet" = "_deployment-subnet"
"deployer_subnet_nsg" = "_deployment-nsg"
"iscsi_subnet" = "iscsi-subnet"
"iscsi_subnet_nsg" = "iscsiSubnet-nsg"
"library_rg" = "-SAP_LIBRARY"
"library_state" = "_SAP-LIBRARY.terraform.tfstate"
"kv" = ""
"msi" = "-msi"
"nic" = "-nic"
"osdisk" = "-OsDisk"
"pip" = "-pip"
"ppg" = "-ppg"
"sapbits" = "sapbits"
"storage_nic" = "-storage-nic"
"storage_subnet" = "_storage-subnet"
"storage_subnet_nsg" = "_storageSubnet-nsg"
"scs_alb" = "scs-alb"
"scs_alb_bepool" = "scsAlb-bePool"
"scs_alb_feip" = "scsAlb-feip"
"scs_alb_hp" = "scsAlb-hp"
"scs_alb_rule" = "scsAlb-rule_"
"scs_avset" = "scs-avset"
"scs_ers_feip" = "scsErs-feip"
"scs_ers_hp" = "scsErs-hp"
"scs_ers_rule" = "scsErs-rule_"
"scs_scs_rule" = "scsScs-rule_"
"sdu_rg" = ""
"tfstate" = "tfstate"
"vm" = ""
"vnet" = "-vnet"
"vnet_rg" = "-INFRASTRUCTURE"
"web_alb" = "web-alb"
"web_alb_bepool" = "webAlb-bePool"
"web_alb_feip" = "webAlb-feip"
"web_alb_hp" = "webAlb-hp"
"web_alb_inrule" = "webAlb-inRule"
"web_avset" = "web-avset"
"web_subnet" = "web-subnet"
"web_subnet_nsg" = "webSubnet-nsg"
}
}