C
Coder.com•4mo ago
Zoker

Cant' build terraform images anymore

Hi there, Since the update to the terraform docker provider 3.5.0 I got this error:
Error: the --chmod option requires BuildKit. Refer to https://docs.docker.com/go/buildkit/ to learn how to build images with BuildKit enabled
Error: the --chmod option requires BuildKit. Refer to https://docs.docker.com/go/buildkit/ to learn how to build images with BuildKit enabled
I then added a builderx part to my terraform file:
resource "docker_buildx_builder" "buildkit" {
name = "terraform-builder"
driver = "docker-container"
use = true
bootstrap = true
}

resource "docker_image" "main" {
depends_on = [docker_buildx_builder.buildkit]
name = "coder-${data.coder_workspace.me.id}"
build {
context = "."
builder = docker_buildx_builder.buildkit.name
build_args = {
USER = local.username
}
no_cache = true
}
triggers = {
docker_sha1 = sha1(filesha1("./Dockerfile"))
terraform_sha1 = sha1(filesha1("./Base.tf"))
rebuild_sha1 = sha1(data.coder_parameter.force_rebuild.value)
assets_sha1 = sha1(join("", [for f in fileset(path.module, "./assets/*") : filesha1(f)]))
}
}
resource "docker_buildx_builder" "buildkit" {
name = "terraform-builder"
driver = "docker-container"
use = true
bootstrap = true
}

resource "docker_image" "main" {
depends_on = [docker_buildx_builder.buildkit]
name = "coder-${data.coder_workspace.me.id}"
build {
context = "."
builder = docker_buildx_builder.buildkit.name
build_args = {
USER = local.username
}
no_cache = true
}
triggers = {
docker_sha1 = sha1(filesha1("./Dockerfile"))
terraform_sha1 = sha1(filesha1("./Base.tf"))
rebuild_sha1 = sha1(data.coder_parameter.force_rebuild.value)
assets_sha1 = sha1(join("", [for f in fileset(path.module, "./assets/*") : filesha1(f)]))
}
}
The second part of this post is in the comments
Solution:
Ok update: It seems I was able to fix this issue with these commands: ``` coder state pull <workspace> terraform.tfstate coder state push <workspace> terraform.tfstate...
Jump to solution
8 Replies
Codercord
Codercord•4mo ago
Codercord
Codercord•4mo ago
<#1382351596553502770>
Category
Help needed
Product
Coder (v2)
Platform
Linux
Logs
Please post any relevant logs/error messages.
Zoker
ZokerOP•4mo ago
I then got this error when building two workspaces after each other using the same template:
Error: failed to create Buildx builder: existing instance for "terraform-builder" but no append mode, specify the node name to make changes for existing instances
on Base.tf line 143, in resource "docker_buildx_builder" "buildkit":
143: resource "docker_buildx_builder" "buildkit" {
Error: failed to create Buildx builder: existing instance for "terraform-builder" but no append mode, specify the node name to make changes for existing instances
on Base.tf line 143, in resource "docker_buildx_builder" "buildkit":
143: resource "docker_buildx_builder" "buildkit" {
Then I added the append option:
resource "docker_buildx_builder" "buildkit" {
name = "terraform-builder"
driver = "docker-container"
use = true
bootstrap = true
append = true
}

resource "docker_image" "main" {
depends_on = [docker_buildx_builder.buildkit]
name = "coder-${data.coder_workspace.me.id}"
build {
context = "."
builder = docker_buildx_builder.buildkit.name
build_args = {
USER = local.username
}
no_cache = true
}
triggers = {
docker_sha1 = sha1(filesha1("./Dockerfile"))
terraform_sha1 = sha1(filesha1("./Base.tf"))
rebuild_sha1 = sha1(data.coder_parameter.force_rebuild.value)
assets_sha1 = sha1(join("", [for f in fileset(path.module, "./assets/*") : filesha1(f)]))
}
}
resource "docker_buildx_builder" "buildkit" {
name = "terraform-builder"
driver = "docker-container"
use = true
bootstrap = true
append = true
}

resource "docker_image" "main" {
depends_on = [docker_buildx_builder.buildkit]
name = "coder-${data.coder_workspace.me.id}"
build {
context = "."
builder = docker_buildx_builder.buildkit.name
build_args = {
USER = local.username
}
no_cache = true
}
triggers = {
docker_sha1 = sha1(filesha1("./Dockerfile"))
terraform_sha1 = sha1(filesha1("./Base.tf"))
rebuild_sha1 = sha1(data.coder_parameter.force_rebuild.value)
assets_sha1 = sha1(join("", [for f in fileset(path.module, "./assets/*") : filesha1(f)]))
}
}
Then I got this error:
Error: failed to create Buildx builder: invalid duplicate endpoint unix:///var/run/docker.sock
on Base.tf line 143, in resource "docker_buildx_builder" "buildkit":
143: resource "docker_buildx_builder" "buildkit" {
Error: failed to create Buildx builder: invalid duplicate endpoint unix:///var/run/docker.sock
on Base.tf line 143, in resource "docker_buildx_builder" "buildkit":
143: resource "docker_buildx_builder" "buildkit" {
I can't seem to fix this issue on my own anymore. I also have one workspace, which gives me this error:
Error: no builder "coder-builder" found
Error: no builder "coder-builder" found
no matter what I change in the terraform file. There is no coder-builder anymore, I removed that a long time ago. Can anyone help me resolve this so I hopefully have a working coder instance again? Thanks!
matifali
matifali•4mo ago
Could you try pinning the docker provider to 3.4 and remove builder resource? I will try to reproduce this and see how it behaves.
Zoker
ZokerOP•4mo ago
Sorry for the late response, for some reason I did not get any notification. It seems that the builder issue itself is fixed in the latest docker provider version: https://github.com/kreuzwerker/terraform-provider-docker/releases/tag/v3.6.2 And when I create a new workspace based on that image it works. But when I update a existing workspace, I still get the Error: no builder "coder-builder" found error. As metnioned, this builder name is not used anywhere anymore. Is there some kind of cache or something? Can I fix this somehow? Thanks! It seems to affect workspaces, where at some point in time, they were updated to a version of the image which contained this builder. When I update a workspace, which did not use this version at all, it works fine. So to me this seems like some sort of cache
Solution
Zoker
Zoker•4mo ago
Ok update: It seems I was able to fix this issue with these commands:
coder state pull <workspace> terraform.tfstate
coder state push <workspace> terraform.tfstate
coder state pull <workspace> terraform.tfstate
coder state push <workspace> terraform.tfstate
And in between edit the tfstate file to remove the coder-builder references 🎉
Zoker
ZokerOP•4mo ago
@Atif Thanks for you help offering! Really appriciate it
Codercord
Codercord•4mo ago
@Phorcys closed the thread.

Did you find this page helpful?