I am using terraform to provision the infrastructure for my project in Azure.
Part of the infrastructure is a container registry to store the docker images that will be used by kubernates. Since at the moment everything is provisioned using terraform I am trying to build and push the images too. I found the kreuzwerker/docker
provider that maybe can do the job.
For the moment I have this code:
provider "docker" {
registry_auth {
address = azurerm_container_registry.example.login_server
username = azurerm_container_registry.example.admin_username
password = azurerm_container_registry.example.admin_password
}
}
resource "docker_registry_image" "example" {
name = "example"
keep_remotely = false
build {
context = path.cwd
dockerfile = "Dockerfile"
}
}
It seems like the image has been build but when it comes to push it to the registry I get this error:
╷
│ Error: resourceDockerRegistryImageCreate: Unable to get authConfig for registry: no auth config found for registry registry-1.docker.io in auth configs: map[string]types.AuthConfig{"***.azurecr.io":types.AuthConfig{Username:"***", Password:"***", Auth:"", Email:"", ServerAddress:"https://***.azurecr.io", IdentityToken:"", RegistryToken:""}}
│
│ with docker_registry_image.backend,
│ on docker.tf line 1, in resource "docker_registry_image" "backend":
│ 1: resource "docker_registry_image" "backend" {
│
╵
I think it's trying to push to registry-1.docker.io
but that's not the correct registry. So I tried
provider "docker" {
host = azurerm_container_registry.example.login_server
registry_auth {
address = azurerm_container_registry.example.login_server
username = azurerm_container_registry.example.admin_username
password = azurerm_container_registry.example.admin_password
}
}
But then I get this error:
╷
│ Error: Error initializing Docker client: unable to parse docker host `***.azurecr.io`
│
│ with provider["registry.terraform.io/kreuzwerker/docker"],
│ on provider.tf line 8, in provider "docker":
│ 8: provider "docker" {
│
╵
How can I use this provider to push the image to the correct ACR?