【问题标题】:Terraform vm deployment using shared galery issue使用共享图库问题的 Terraform vm 部署
【发布时间】:2022-09-23 17:01:11
【问题描述】:

我正在实现一个 Terraform 模板,该模板基于驻留在另一个租户上的自定义映像部署 Azure VM。我已向 AppRegistration 提供了权限,并验证了使用 Az CLI 我可以部署引用同一共享映像的 VMSS。

但是,如果我使用 Terraform 部署 VM,则会收到以下错误:

错误:compute.VirtualMachinesClient#CreateOrUpdate:发送请求失败:StatusCode=403 -- 原始错误:Code=\"LinkedAuthorizationFailed\" Message=\"客户端有权执行操作\'Microsoft.Compute/galleries/images/versions/阅读\'范围\'/订阅//resourceGroups/RG-Images/providers/Microsoft.Compute/virtualMachines/VM1\', however the current tenant \'\' 无权访问链接订阅 \'***\'。\"

Terraform 正在使用已创建的 AppRegistration。但是,它因该错误而失败

我已经成功地遵循了这个使用 Az cli 的方法。 https://learn.microsoft.com/en-us/azure/virtual-machine-scale-sets/share-images-across-tenants

我从错误消息中了解到,用户具有权限,但问题出在 2 个租户之间,是吗?我还能做些什么来解决这个问题?

    标签: azure terraform terraform-provider-azure


    【解决方案1】:

    最初请与RBAC 权限在虚拟机贡献者或网络贡献者角色等两个租户上。

    • 跨租户的这个问题甚至可以在 terraform azurerm 中修复 提供程序版本 1.34.0 或更高版本

      provider "azurerm" {
       version = "~> 1.34.0"
      }
      

    你可以利用auxiliary_tenant_ids = ["<tenant2 Id>"]在使用共享图片库时提及两个租户。参见@rajaie-algorithmia 的shared image gallery /terraform/github.com

    provider "azurerm" {
    
      subscription_id = "${var.subscription_id}"
    
      client_id       = "${var.client_id}"
    
      client_secret   = "${var.client_secret}"
    
      tenant_id       = "${var.tenant_id}"
    
      auxiliary_tenant_ids = ["${var.sig_tenant_id}"]  #give the other tenant Id here
    }
    

    参考:

    1. share-images-across-tenants | microsoft docs
    2. azure portal : how-to-share-gallery-vm-images-across-azure-tenants |Ajay varma| axiom

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-10
      • 2021-05-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多