ACR清理任务使用Terraform不按预期工作。

huangapple go评论90阅读模式
英文:

ACR purge task using terraform not working as expected

问题

创建类似于下面的 ACR:

resource "azurerm_container_registry" "acr" {
  name                = var.azure_container_registry_name
  resource_group_name = var.resource_group.name
  location            = var.location
}

以及下面的清理任务:

resource "azurerm_container_registry_task" "acr_purge_task" {
  name                  = "scheduledAcrPurgeTask"
  container_registry_id = azurerm_container_registry.acr.id
  platform {
    os           = "Linux"
  }
  encoded_step {
    task_content = <<EOF
    version: v1.1.0
    steps:
      - cmd: acr purge --filter 'REPO:TEST.*' --untagged --ago 10m
        disableWorkingDirectoryOverride: true
        timeout: 3600
    EOF
    context_path = "/dev/null"
  }
  timer_trigger {
    name     = "t1"
    schedule = "*/15 * * * *"
    enabled  = true
  }
}

任务成功创建,但在运行时出现以下错误:

无法在本地找到'image 'acr:latest'
docker: 守护程序的错误响应: 对于 acr,拉取访问被拒绝,存储库不存在或可能需要 'docker login':请求的访问被拒绝。

我不确定为什么它尝试在 acr:latest 中查找映像,因为我正在维护 REPO 作为我的存储库。

英文:

Creating ACR like below

resource &quot;azurerm_container_registry&quot; &quot;acr&quot; {
  name                = var.azure_container_registry_name
  resource_group_name = var.resource_group.name
  location            = var.location
}

And purge task like below

resource &quot;azurerm_container_registry_task&quot; &quot;acr_purge_task&quot; {
  name                  = &quot;scheduledAcrPurgeTask&quot;
  container_registry_id = azurerm_container_registry.acr.id
  platform {
    os           = &quot;Linux&quot;
  }
  encoded_step {
    task_content = &lt;&lt;EOF
    version: v1.1.0
    steps:
      - cmd: acr purge --filter &#39;REPO:TEST.*&#39; --untagged --ago 10m
        disableWorkingDirectoryOverride: true
        timeout: 3600
    EOF
    context_path = &quot;/dev/null&quot;
  }
  timer_trigger {
    name     = &quot;t1&quot;
    schedule = &quot;*/15 * * * *&quot;
    enabled  = true
  }
}

The task is getting creating successfully but when ran I am getting below error

Unable to find image &#39;acr:latest&#39; locally
docker: Error response from daemon: pull access denied for acr, repository does not exist or may require &#39;docker login&#39;: denied: requested access to the resource is denied.

I am not sure why this is trying to find image in acr:latest as I am maintaining REPO as my repository.

答案1

得分: 1

我移除了行前的空格

version: v1.1.0
steps:
  - cmd: acr purge --filter &#39;REPO:TEST.*&#39; --untagged --ago 10m
    disableWorkingDirectoryOverride: true
    timeout: 3600

之前

version: v1.1.0
steps:
  - cmd: acr purge --filter &#39;REPO:TEST.*&#39; --untagged --ago 10m
    disableWorkingDirectoryOverride: true
    timeout: 3600

我不知道为什么terraform或Azure都没有提供更好的错误响应。

英文:

Silly mistake
I removed the empty spaces before lines

version: v1.1.0
steps:
  - cmd: acr purge --filter &#39;REPO:TEST.*&#39; --untagged --ago 10m
    disableWorkingDirectoryOverride: true
    timeout: 3600

earlier

    version: v1.1.0
    steps:
      - cmd: acr purge --filter &#39;REPO:TEST.*&#39; --untagged --ago 10m
        disableWorkingDirectoryOverride: true
        timeout: 3600

I don't why terraform or either the Azure didn't provide better error response.

huangapple
  • 本文由 发表于 2023年1月9日 16:04:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/75054516.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定