Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support reverting remote changes #216

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

michaelPotter
Copy link

Hi, @DRuggeri. This PR is to fix issue #81 - provider doesn't refresh state against the remote state.

I've updated the restapi_object resource to now attempt to revert any changes made outside of Terraform.

To support the cases where the API adds metadata out of our control, like "last_modified", you can add those paths to ignore_changes_to. For deeply nested paths, you can go "metadata.last_modified".

To get the old behavior back, set ignore_all_server_changes to true.

For example, a declaration might look like this:

resource "restapi_object" "Linguini" {
  path      = "/api/cats"
  object_id = "Linguini"

  data = jsonencode({
    name    = "Linguini"
    color   = "tabby"
    hobbies = {
      hunting = "birds"
      eating  = "plants"
    }
  })

  ignore_changes_to = [
    "name",
    "last_modified",
    "hobbies.sleeping",
  ]
}

Where the response returned by the server:

  • removes the name field
  • adds the last_modified field
  • add the hobbies.sleeping field

Let me know what you think and if you'd like any changes. I don't have a ton of experience in Go, so if anything looks wrong just let me know.

This updates the restapi_object resource so that it attempts to revert any
changes made to the remote resource outside of Terraform.

To support apis that add or remove metadata in read responses, you can
pass in a list of paths where changes should be ignored -
ignore_changes_to. Or to ignore all changes, set
ignore_all_server_changes to true
@fancybear-dev
Copy link

Nice! Will test it out in our production environment likely this week and let you know if we find any bugs/improvements.

If you want to track; hnhdev#5

We've forked, because this upstream repository is currently in hibernation as far as we can tell - or at least way to slow for our workflow.

nkvoll added a commit to nkvoll/terraform-provider-restapi that referenced this pull request Sep 6, 2023
@amvapor
Copy link

amvapor commented Oct 2, 2023

Is anything holding this Pull Request back?

@DRuggeri
Copy link
Member

DRuggeri commented Mar 1, 2024

Thanks, @michaelPotter - I love this idea and it is something I've wanted to add to the provider for some time! Detecting deltas has been a tricky topic, so I will aim to dig into the implementation soon to have a look and offer better feedback. This is exciting!!!

Also, thanks for the patience! As mentioned in the readme, we keep the provider up to date but features are ssssllllloooooowwwwww.

@DRuggeri DRuggeri added the enhancement New feature or request label Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants