我正在Azure Cloud中编写一个Windows VM,使用Terraform安装3个不同程序的扩展。然而,我正面临着一个我无法解决的大问题。下面的脚本,错误和我的想法。
**
data "template_file" "testing_file_part1" {
template = "${file("vm_adds_testing_part0.ps1")}"
}
data "template_file" "testing_file_part2" {
template = "${file("vm_adds_testing_part1.ps1")}"
}
data "template_file" "testing_file_part3" {
template = "${file("vm_adds_testing_part2.ps1")}"
}
...... vm.tf omitted.
# First extension
resource "azurerm_virtual_machine_extension" "extension1" {
name = "example-vm-extension1"
virtual_machine_id = azurerm_windows_virtual_machine.testing_vm.id
publisher = "Microsoft.Compute"
type = "CustomScriptExtension"
type_handler_version = "1.10"
settings = <<SETTINGS
{
"commandToExecute": "powershell -command \"[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${base64encode(data.template_file.testing_file_part1.rendered)}')) | Out-File -filepath vm_adds1.ps1\" && powershell -ExecutionPolicy Unrestricted -File vm_adds1.ps1 -username ${var.VIRTUAL_MACHINE_ADMIN_USERNAME} -password ${var.VIRTUAL_MACHINE_ADMIN_PASSWORD}"
}
SETTINGS
}
# Second extension
resource "azurerm_virtual_machine_extension" "extension2" {
name = "example-vm-extension2"
virtual_machine_id = azurerm_windows_virtual_machine.testing_vm.id
publisher = "Microsoft.Compute"
type = "CustomScriptExtension"
type_handler_version = "1.10"
settings = <<SETTINGS
{
"commandToExecute": "powershell -command \"[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${base64encode(data.template_file.testing_file_part2.rendered)}')) | Out-File -filepath vm_adds2.ps1\" && powershell -ExecutionPolicy Unrestricted -File vm_adds2.ps1 -username ${var.VIRTUAL_MACHINE_ADMIN_USERNAME} -password ${var.VIRTUAL_MACHINE_ADMIN_PASSWORD}"
}
SETTINGS
depends_on = [azurerm_virtual_machine_extension.extension1]
}
# Third extension
resource "azurerm_virtual_machine_extension" "extension3" {
name = "example-vm-extension3"
virtual_machine_id = azurerm_windows_virtual_machine.testing_vm.id
publisher = "Microsoft.Compute"
type = "CustomScriptExtension"
type_handler_version = "1.10"
settings = <<SETTINGS
{
"commandToExecute": "powershell -command \"[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${base64encode(data.template_file.testing_file_part3.rendered)}')) | Out-File -filepath vm_adds3.ps1\" && powershell -ExecutionPolicy Unrestricted -File vm_adds3.ps1 -username ${var.VIRTUAL_MACHINE_ADMIN_USERNAME} -password ${var.VIRTUAL_MACHINE_ADMIN_PASSWORD}"
}
SETTINGS
depends_on = [azurerm_virtual_machine_extension.extension2]
}
错误:
Error: compute.VirtualMachineExtensionsClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="BadRequest" Message="Multiple VMExtensions per handler not supported for OS type 'Windows'. VMExtension 'custom-script-extension-testing-part2' with handler 'Microsoft.Compute.CustomScriptExtension' already added or specified in input."
with module.vm_extension_custom_script_performance_testing_part2.azurerm_virtual_machine_extension.vm_extension[0],
问题:
有没有一种方法可以使用Terraform执行多个扩展?如果是,如何进行?
场景:
- 当我运行1个扩展时,它可以工作。
- 当我有和扩展与计数它是失败的。
- ps1脚本太大了,如果我试图把它们放在一个文件中,Terraform失败了,说Base64太大了。
我正在寻找解决这个问题的方法。
1条答案
按热度按时间vh0rcniy1#
我尝试为每个处理程序添加多个VM扩展,这不支持操作系统类型“Windows”,因此我尝试了具有类似要求的单个VM扩展。
我同意@Thomas的评论,即不可能使用多个扩展名,也可以根据链接检查阻止访问
您遇到的错误是由于Azure平台的限制,该平台不允许在单个Windows VM上使用同一类型的多个扩展。鉴于您正在为每个扩展使用
CustomScriptExtension
,Azure不允许将其中一个以上的扩展应用于VM。但是,我尝试使用合并合并为一个扩展中提到的Powershell脚本来实现基于您所要求的查询的需求。
我的地形配置:
main.tf:
variable.tf:
output.tf:
输出: