使用 Terraform 的 Azure 容器注册表权限

标签 azure continuous-integration terraform

使用 terraform 设置 azurerm_container_registry,我想知道如何更改某些用户的权限(例如 ReadOnly),或者创建一个 access_key 可以从我的 CI-Pipeline 使用,但根本不需要用户。

最佳答案

此 Terraform 配置创建 ACR 注册表和 Azure 服务主体, 并授予 SP 贡献者 对 ACR 注册表的访问权限。这可以更新为阅读器

更多信息可以在服务主体的 ACR 身份验证 here 上找到。 .

resource "azurerm_resource_group" "acr-rg" {
  name     = "acr-rg-007"
  location = "West US"
}

resource "azurerm_container_registry" "acr" {
  name                = "acr00722"
  resource_group_name = "${azurerm_resource_group.acr-rg.name}"
  location            = "${azurerm_resource_group.acr-rg.location}"
  sku                 = "standard"
}

resource "azurerm_azuread_application" "acr-app" {
  name = "acr-app"
}

resource "azurerm_azuread_service_principal" "acr-sp" {
  application_id = "${azurerm_azuread_application.acr-app.application_id}"
}

resource "azurerm_azuread_service_principal_password" "acr-sp-pass" {
  service_principal_id = "${azurerm_azuread_service_principal.acr-sp.id}"
  value                = "Password12"
  end_date             = "2020-01-01T01:02:03Z"
}

resource "azurerm_role_assignment" "acr-assignment" {
  scope                = "${azurerm_container_registry.acr.id}"
  role_definition_name = "Contributor"
  principal_id         = "${azurerm_azuread_service_principal_password.acr-sp-pass.service_principal_id}"
}

output "docker" {
  value = "docker login ${azurerm_container_registry.acr.login_server} -u ${azurerm_azuread_service_principal.acr-sp.application_id} -p ${azurerm_azuread_service_principal_password.acr-sp-pass.value}"
}

关于使用 Terraform 的 Azure 容器注册表权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51783221/

相关文章:

azure - 当指定分支的拉取请求完成时触发下一个管道阶段

azure - 如何在 terraform 中使列表参数可选

terraform - 为 local-exec 设置 Terraform 默认解释器

amazon-web-services - 参数 CacheSubnetGroupName 必须提供且不能为空

Azure 导入/导出工具 dataset.csv 和多个 session 文件夹

mysql - 连接 Spotfire Azure MySQL 数据库

azure - 使用 CLI 列出所有 Azure 订阅中的所有虚拟机

Azure Cosmos db Gremlin elementMap()

c++ - Gitlab CI 运行程序

continuous-integration - CI 管道中的 Kotlin 代码覆盖率