【问题标题】:Azure Virtual Machine Extension file URL location with Terraform使用 Terraform 的 Azure 虚拟机扩展文件 URL 位置
【发布时间】:2019-09-12 15:53:01
【问题描述】:

问题有点令人困惑,但我会解释我在做什么。我正在 Terraform 中构建一个新的 Azure VM,并在虚拟机扩展中调用一个脚本。它是一个基本的 powershell 脚本。问题是,我目前正在从一个公共 GitHub 帐户调用它。

resource "azurerm_virtual_machine_extension" "winrm" {
  name                  = "winrm"
  location              = var.location
  resource_group_name   = var.rg_name
  count                 = length(var.vm_name_suffix)
  virtual_machine_name  = azurerm_virtual_machine.vm[count.index].name
  publisher             = "Microsoft.Compute"
  type                  = "CustomScriptExtension"
  type_handler_version  = "1.9"

  settings = <<SETTINGS
  {
    "fileUris": ["https://raw.githubusercontent.com/<name>/master/winrm.ps1"], 
    "commandToExecute": "powershell.exe -ExecutionPolicy unrestricted -NoProfile -NonInteractive -File \"./winrm.ps1\""
  }
  SETTINGS
}

试图弄清楚是否有一种方法可以从更安全的地方调用它。我在 Azure DevOps 存储库中进行了此设置,但我不确定如何将任何类型的身份验证传递到设置块中。我也可以将它放在私人 GitHub 帐户上,但我需要再次提供一种对文件进行身份验证的方法。

【问题讨论】:

    标签: azure terraform azure-rm


    【解决方案1】:

    document,您可以在protectedSettings 中包含数据,Azure VM 扩展保护设置数据被加密,并且仅在目标虚拟机上解密。

    您可以将敏感数据存储在受保护的配置中,即 加密且仅在虚拟机内部解密。受保护的 当执行命令包含秘密时,配置很有用 比如密码。

    在这种情况下,建议将脚本上传到 Blob 存储,然后使用存储帐户密钥从该存储帐户调用扩展文件。

    例如:

    resource "azurerm_virtual_machine_extension" "winrm" {
    ...
    
      settings = <<SETTINGS
        {
            "fileUris": ["https://mystorageaccountname.blob.core.windows.net/postdeploystuff/winrm.ps1"]
        }
    SETTINGS
      protected_settings = <<PROTECTED_SETTINGS
        {
          "commandToExecute": "powershell -ExecutionPolicy Unrestricted -NoProfile -NonInteractive -File winrm.ps1",
          "storageAccountName": "mystorageaccountname",
          "storageAccountKey": "xxxxx"
        }
      PROTECTED_SETTINGS
    
      depends_on = ["azurerm_virtual_machine.vm[count.index].name"]
    
    
    }
    

    有关更多详细信息,您可以参考blog 关于将 Terraform 与 A​​zure VM 扩展结合使用。

    【讨论】:

    • 感谢南希的回复。我将创建一个存储帐户并试一试。
    • 工作就像一个魅力。再次感谢
    猜你喜欢
    • 2021-07-11
    • 1970-01-01
    • 1970-01-01
    • 2022-08-18
    • 2022-12-21
    • 1970-01-01
    • 2021-09-24
    • 2020-10-22
    • 1970-01-01
    相关资源
    最近更新 更多