简体   繁体   English

如何使用资源在 Azure 上创建容器注册表?

[英]How do I create a Container Registry on Azure with a resource?

My terraform script is giving error like below;我的 terraform 脚本出现如下错误;

Error: Error creating Container Registry "containerRegistry1" (Resource Group "aks-cluster"): containerregistry.RegistriesClient#Create: Failure sending request: StatusCode=0 -- Original Error: autorest/azure: Service returned an error. Status=<nil> Code="AlreadyInUse" Message="The registry DNS name containerregistry1.azurecr.io is already in use. You can check if the name is already claimed using following API: https://docs.microsoft.com/en-us/rest/api/containerregistry/registries/checknameavailability"

on terra.tf line 106, in resource "azurerm_container_registry" "acr": 106: resource "azurerm_container_registry" "acr" {在 terra.tf 第 106 行,在资源“azurerm_container_registry”“acr”中:106:资源“azurerm_container_registry”“acr”{

Whole script is below;整个脚本如下; I'm beginner at Terraform and tried different combinations but didn't worked.我是 Terraform 的初学者并尝试了不同的组合但没有奏效。 Not sure what can be the problem, is it possible to help?不知道可能是什么问题,是否可以提供帮助?

   variable "prefix" {
  default = "tfvmex"
}

provider "azurerm" {
  version = "=1.28.0"
}

resource "azurerm_resource_group" "rg" {
  name     = "aks-cluster"
  location = "West Europe"
}

resource "azurerm_virtual_network" "network" {
  name                = "aks-vnet"
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name
  address_space       = ["10.1.0.0/16"]
}

resource "azurerm_subnet" "subnet" {
  name                      = "aks-subnet"
  resource_group_name       = azurerm_resource_group.rg.name
  address_prefix            = "10.1.1.0/24"
  virtual_network_name      = azurerm_virtual_network.network.name
}

resource "azurerm_kubernetes_cluster" "cluster" {
  name       = "aks"
  location   = azurerm_resource_group.rg.location
  dns_prefix = "aks"

  resource_group_name = azurerm_resource_group.rg.name
  kubernetes_version  = "1.17.3"

  agent_pool_profile {
    name           = "aks"
    count          = 1
    vm_size        = "Standard_D2s_v3"
    os_type        = "Linux"
    vnet_subnet_id = azurerm_subnet.subnet.id
  }

  service_principal {
    client_id     = "dxxxx"
    client_secret = "xxxx"
  }

  network_profile {
    network_plugin = "azure"
  }
}


resource "azurerm_network_interface" "rg" {
  name                = "${var.prefix}-nic"
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name

  ip_configuration {
    name                          = "testconfiguration1"
    subnet_id                     = azurerm_subnet.subnet.id
    private_ip_address_allocation = "Dynamic"
  }
}


resource "azurerm_virtual_machine" "rg" {
  name                  = "${var.prefix}-vm"
  location              = azurerm_resource_group.rg.location
  resource_group_name   = azurerm_resource_group.rg.name
  network_interface_ids = [azurerm_network_interface.rg.id]
  vm_size               = "Standard_DS1_v2"

  # Uncomment this line to delete the OS disk automatically when deleting the VM
  # delete_os_disk_on_termination = true

  # Uncomment this line to delete the data disks automatically when deleting the VM
  # delete_data_disks_on_termination = true

  storage_image_reference {
    publisher = "Canonical"
    offer     = "UbuntuServer"
    sku       = "16.04-LTS"
    version   = "latest"
  }
  storage_os_disk {
    name              = "myosdisk1"
    caching           = "ReadWrite"
    create_option     = "FromImage"
    managed_disk_type = "Standard_LRS"
  }
  os_profile {
    computer_name  = "hostname"
    admin_username = "testadmin"
    admin_password = "testtest"
  }
  os_profile_linux_config {
    disable_password_authentication = false
  }
  tags = {
    environment = "staging"
  }
}

resource "azurerm_container_registry" "acr" {
  name                     = "containerRegistry1"
  resource_group_name      = azurerm_resource_group.rg.name
  location                 = azurerm_resource_group.rg.location
  sku                      = "Premium"
  admin_enabled            = false
  georeplication_locations = ["West Europe"]
}


resource "azurerm_network_security_group" "example" {
  name                = "acceptanceTestSecurityGroup1"
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name

  security_rule {
    name                       = "test123"
    priority                   = 100
    direction                  = "Outbound"
    access                     = "Allow"
    protocol                   = "Tcp"
    source_port_range          = "*"
    destination_port_range     = "*"
    source_address_prefix      = "*"
    destination_address_prefix = "*"
  }

  tags = {
    environment = "Test"
  }
}

Thanks!谢谢!

How do I create a Container Registry on Azure with a resource?如何使用资源在 Azure 上创建容器注册表?

From your error message, it appears like you are using a non-unique ACR name in the below pasted terraform resource declaration:从您的错误消息中,您似乎在下面粘贴的 terraform 资源声明中使用了非唯一的ACR名称:

resource "azurerm_container_registry" "acr" {
**name                     = "containerRegistry1"**
resource_group_name      = azurerm_resource_group.rg.name
location                 = azurerm_resource_group.rg.location
sku                      = "Premium"
admin_enabled            = false
georeplication_locations = ["West Europe"]
}

Azure CLI has az acr check-name to ensure that ACR name is globally unique. Azure CLI 具有az acr check-name以确保ACR名称是全局唯一的。

I think your issue is because your acr name is already globally taken.我认为您的问题是因为您的 acr 名称已经在全球范围内使用。 Not within your subscription, but GLOBALLY.不在您的订阅范围内,而是在全球范围内。

This is because ACR need a url to be accessed, and the url needs to be unique.这是因为 ACR 需要一个 url 才能被访问,并且 url 需要是唯一的。 That means some other Azure account has taken that name.这意味着其他一些 Azure 帐户已使用该名称。

Error: Error creating Container Registry "containerRegistry1" (Resource Group "aks-cluster"): containerregistry.RegistriesClient#Create: Failure sending request: StatusCode=0 -- Original Error: autorest/azure: Service returned an error. Status=<nil> Code="AlreadyInUse" Message="The registry DNS name containerregistry1.azurecr.io is already in use. You can check if the name is already claimed using following API: https://docs.microsoft.com/en-us/rest/api/containerregistry/registries/checknameavailability"

containerregistry1.azurecr.io >>>> this url needs to be globally unique. containerregistry1.azurecr.io >>>> 这个 url 需要是全局唯一的。

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

相关问题 Azure:如何找到容器注册表的所有者或资源 ID? - Azure: How can I find the owner or resource ID of a container registry? Azure - 如何使用 Container Registry 将 Docker 执行到容器中? - Azure - how do I Docker exec into container with a Container Registry? 如何从 Azure 容器注册表中的映像创建 Dockerfile? - How can I create a Dockerfile FROM an Image in Azure Container Registry? 如何使用 yaml 模板创建 azure 容器注册表? - How to create azure container registry with yaml template? 如何将内容信任策略分配给容器注册表资源 azure powershell - How to assign content trust policy to container registry resource azure powershell 如何使用私有 Azure Container Registry 创建一个 Azure APP Service? - How to create a Azure APP Service with a private Azure Container Registry? 创建 Azure 容器注册表任务时,如何在文件夹中引用 Dockerfile? - How do I reference a Dockerfile in a folder when creating an Azure Container Registry Task? 如何为容器注册表 Azure 创建只读访问密钥 - How to create a read only access key for Container Registry Azure 如何在虚拟网络中创建Azure容器注册表? - How to create Azure Container Registry inside the Virtual Network? 如何通过Azure Resource Manager模板创建Azure Blob容器/表 - How can I create an Azure Blob Container/Table by Azure Resource Manager template
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM