简体   繁体   English

通过 Terraform 中 azure 应用服务的角色分配访问 azure 容器注册表 (ACR)

[英]Access azure container registry (ACR) by role assignment for azure app service in Terraform

I have a azure app service that is provisioned by Terraform.我有一个由 Terraform 提供的 azure 应用服务。 The app service fires up the docker image from Azure ACR there fore it need to access the ACR.应用服务从 Azure ACR 启动 docker 映像,因此它需要访问 ACR。 I'm currently using the password and login name method in my Terraform configuration.我目前在 Terraform 配置中使用密码和登录名方法。 How can I make the azure app service to access the ACR by service principle role assignment in Terraform?如何通过 Terraform 中的服务主体角色分配使 azure 应用服务访问 ACR?

resource "azurerm_app_service" "tf_app_service" {
  name                = var.application_name
  location            = azurerm_resource_group.tf_resource_group.location
  resource_group_name = azurerm_resource_group.tf_resource_group.name
  app_service_plan_id = azurerm_app_service_plan.tf_service_plan.id

  site_config {
    always_on        = true
    linux_fx_version = "DOCKER|${var.acr_name}.azurecr.io/${var.img_repo_name}:${var.tag}"
  }

  // How to use role assignment?
  app_settings = {
    DOCKER_REGISTRY_SERVER_URL          = // need to avoid docker URL
    WEBSITES_ENABLE_APP_SERVICE_STORAGE = "false"
    DOCKER_REGISTRY_SERVER_USERNAME     = // need to avoid user name
    DOCKER_REGISTRY_SERVER_PASSWORD     = // need to avoid PW
  }

  identity {
    type = "SystemAssigned"
  }

  tags = {
    environment = var.environment
    DeployedBy  = "terraform"
  }
}

The steps to use a Service Principle to access ACR are lined out here . 此处列出了使用服务原则访问 ACR 的步骤。

So to do the same in Terraform, you need to first create a new service principle .所以要在 Terraform 中做同样的事情,你需要首先创建一个新的服务原则 Then assign a password to it.然后为其分配密码 Afterwards you should be able to use those two to fill the app settings of your app service.之后您应该可以使用这两个来填充您的应用服务的应用设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure 角色分配 - AKS 到 ACR - Terraform - Azure Role Assignment - AKS to ACR - Terraform Azure容器注册表(ACR)SKU - Azure Container Registry (ACR) SKUs 使用 Terraform 在 Azure 中分配角色 - Role Assignment in Azure with Terraform 如何从 Azure 容器应用服务使用 Azure ACR 进行身份验证 - How to authenticate with Azure ACR from Azure container app service 如何配置 Azure 应用服务以从具有 terraform 的 ACR 中提取图像? - How to configure an Azure app service to pull images from an ACR with terraform? Powershell + Azure 应用服务 + Azure 容器注册表 - Powershell + Azure App Service + Azure Container Registry 无法在 Azure 云中为子网和 ACR 注册表创建具有角色分配写入的 AKS - Not able to create AKS with role assignment write for subnet and ACR registry in Azure Cloud Azure Web 服务环境变量不适用于 Azure 容器注册表 (ACR) 映像 - Azure Web Service env-variables not working with Azure Container Registry (ACR) image 无需订阅所有者即可将 Azure Kubernetes 服务 (AKS) 附加到 Azure 容器注册表 (ACR) - Attach Azure Kubernetes Service (AKS) to Azure Container Registry (ACR) without being Subscription Owner 使用 ACR 访问权限配置 azure 应用服务实例的正确方法是什么? - What is the correct way to provision an azure app service instance with ACR access?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM