Skip to content

Conversation

@bloewes
Copy link

@bloewes bloewes commented Jul 1, 2025

The azapi_resource_action resource will force re-creation if the type field changes. This means that simply updating the api-version (for example, from 2022-05-01 to 2023-01-01) can cause the resource to be destroyed and recreated, which is problematic—especially if when = "destroy" is set. The resource should still be sufficiently re-created if any of the other marked arguments change.

@matt-FFFFFF
Copy link
Member

matt-FFFFFF commented Jul 10, 2025

As an alternative here you can use terraform's removed block then you can add your new configuration...

Changing the action type would usually mean the action should be re-created, your change would mean that a caller could change the action to a totally different API call. Even with only an API version change there could be a different effect.

Instead...

# remove old resource from state and forget it (no destroy)
removed {
  from = azapi_resource_action.foo
  lifecycle {
    destroy = false
  }
}

# add new resource
resource "azapi_resource_action" "bar" {
  # new config
}

@bloewes
Copy link
Author

bloewes commented Jul 10, 2025

For the case when="destroy": since the action hasn’t happened yet, this change makes sense and shouldn’t have any side effects. Is it possible to make the re-creation of the resource’s type conditional on the value of when?

Otherwise, with many resources and resource instances that we use and frequent API changes, this approach doesn’t seem effective for my our case. I prefer to continue using ignore_changes = [type] in that case.

@matt-FFFFFF
Copy link
Member

matt-FFFFFF commented Jul 10, 2025

shouldn’t have any side effects

The change you are proposing will most definately have side effects as it stands.

Considering only the when = "destroy" use case... Perhaps it is possible to automate the forget operation. E.g. don't run the resource's .Delete() method.

@ms-henglu
Copy link
Member

I think it makes sense that the plan modifier allows api-version upgrade without replacing the resource. I'll open another PR to support it and it could be included in the next release.

@ms-henglu
Copy link
Member

Hi @bloewes , I just realized that even the action resource is not recreated, it'll still trigger one http request if when != destroy, is it okay for your case?

@bloewes
Copy link
Author

bloewes commented Jul 24, 2025

@ms-henglu For my case, I only care about when = destory, because those would make a DELETE api call which is then not recoverable. But if the case when = destory does not trigger any call, I'm fine.

@ms-henglu ms-henglu added this to the v2.7.0 milestone Aug 15, 2025
@ms-henglu ms-henglu modified the milestones: v2.7.0, v2.8.0 Oct 15, 2025
@ms-henglu
Copy link
Member

I'll close this PR in favor of #1035, hope you don't mind. Let me know if you have any questions. Thanks for the PR again!

@ms-henglu ms-henglu closed this Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants