terraform-provider-ko icon indicating copy to clipboard operation
terraform-provider-ko copied to clipboard

Cannot change build path of existing resource

Open joshrwolf opened this issue 3 years ago • 4 comments

Changing the build path of an existing resource to one that doesn't exist results in an error at plan/apply time.

An example of this occurring is when we're refactoring an invocation path:

# A
|- env/
   - main.tf         # buildpath of "${path.module}/../"
|- main.go

to

# B
|- env/
   |- new/           # buildpath of "${path.module}/../../"
      - main.tf
|- main.go

if A already exists in state and we move the invocation to B, a terraform {plan,apply} will error out with a ko build error due to a non-existent path.

the desired behavior instead is for the tf provider to simply rebuild the image with the new path.

joshrwolf avatar Oct 18 '22 00:10 joshrwolf

It's not a great answer, but ko_image resources are cheap and disposable -- can you change the name of the ko_image resource to something new, so terraform plan considers it a new resource without any preexisting state? This would also delete (no-op) the old image resource.

If that works you can rename the resource back to the old now-deleted resource name. I agree this isn't ideal though, since it requires a few manual steps.

Short of that though I'm not sure what would be better for the provider to do. It's possible there's an answer I just don't know it.

imjasonh avatar Oct 18 '22 12:10 imjasonh

We just hit this in mono because of an otherwise seemingly benign import path change in one of our samples. :(

mattmoor avatar Nov 01 '22 22:11 mattmoor

got bit by with this change, https://github.com/chainguard-dev/enforce-events/pull/9

k4leung4 avatar Nov 01 '22 22:11 k4leung4

I just hit this today

found-it avatar May 16 '24 01:05 found-it