Terraform vm deployment using shared galery issue

Viewed 60

I'm implementing a Terraform template, that deploys an Azure VM, based on a custom image that resides on another tenant. I've provided permissions to an AppRegistration, and validated that using Az CLI I can deploy a VMSS referring to that same shared image.

However, if I use Terraform to deploy the VM, I get this error:

Error: compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=403 -- Original Error: Code="LinkedAuthorizationFailed" Message="The client has permission to perform action 'Microsoft.Compute/galleries/images/versions/read' on scope '/subscriptions//resourceGroups/RG-Images/providers/Microsoft.Compute/virtualMachines/VM1', however the current tenant '' is not authorized to access linked subscription '***'."

Terraform is using the AppRegistration that was created. however, it fails with that error

I've followed this how-to, successfully, that usees Az cli. https://learn.microsoft.com/en-us/azure/virtual-machine-scale-sets/share-images-across-tenants

I understand by the error message, that the user has the permissions, but the issue is between the 2 tenants, is that it? What else can I do to fix this?

1 Answers

Initially please check with the RBAC permissions on the two tenants like Virtual machine contributor or Network Contributor role .

enter image description here

  • This issue with cross tenant may be even fixed in terraform azurerm provider version 1.34.0 or later

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

And you can make use of auxiliary_tenant_ids = ["<tenant2 Id>"] to mention both the tenants while using shared image gallery .See shared image gallery /terraform/github.com by @rajaie-algorithmia

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
}

References:

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