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

allow ignore_changes to reference any map key #26421

Merged
merged 2 commits into from
Oct 5, 2020

Conversation

jbardin
Copy link
Member

@jbardin jbardin commented Sep 29, 2020

This change will allow specifying a map["key"] path in ignore_changes that may not exist in the config or the prior value. This allows users to prevent a single map element from changing to or from being unset.

This didn't work previously because the transformation always started off with the configuration, and would never encounter a key if it was not present in the configuration. We also couldn't retain the absence of a value, since the lookup wouldn't find the key in the prior value.

The following configuration will now prevent the "unwanted" value from showing up in the plan if it is not originally present in the prior state.

resource "test_resource" "a" {
  map = {
    wanted = "value"
    unwanted = "added after initial apply"
  }
  lifecycle = {
    ignore_changes = [map["unwanted"]]
  }
}

The following example will now prevent the "wanted" value from being removed if it exists the the prior state, but is removed from the configuration

resource "test_resource" "a" {
  map = {
    // wanted = "removed after initial apply"
  }
  lifecycle = {
    ignore_changes = [map["wanted"]]
  }
}

While these examples use map literals for clarity, this feature would normally be used when the map is derived from another source, and not manipulated directly in the resource configuration. This also allows users in some cases to work around misbehaving legacy providers that have altered the state in conflict with the configuration.

@codecov
Copy link

codecov bot commented Sep 29, 2020

Codecov Report

Merging #26421 into master will increase coverage by 0.01%.
The diff coverage is 86.79%.

Impacted Files Coverage Δ
terraform/eval_diff.go 70.45% <86.79%> (+1.70%) ⬆️
dag/marshal.go 53.42% <0.00%> (-1.37%) ⬇️
terraform/evaluate.go 50.11% <0.00%> (-0.46%) ⬇️

@apparentlymart
Copy link
Contributor

I unfortunately don't have enough time left today for a deep review of this, but just wanted to quickly note that this changes the documented behavior of ignore_changes and so we'll need to do some documentation updates along with this behavior change.

@jbardin
Copy link
Member Author

jbardin commented Sep 30, 2020

Thank you, I forgot we documented that caveat of the implementation. I'll add the doc changes to his PR too.

Copy link
Contributor

@mildwonkey mildwonkey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 the real-world use case for this makes lots of sense to me!

There are situations when a user may want to keep or exclude a map key
using `ignore_changes` which may not be listed directly in the
configuration. This didn't work previously because the transformation
always started off with the configuration, and would never encounter a
key if it was only present in the prior value.
We can remove the caveat about changing map elements.

Add a little more text about the intended use case for ignore_changes,
as the common case of fixing erroneous provider behavior should not be
the primary motivation for the maintenance of this feature.
@jbardin
Copy link
Member Author

jbardin commented Oct 1, 2020

Just rebased in some comment changes which I thought I would help with review.

@jbardin jbardin merged commit ee564a5 into master Oct 5, 2020
@jbardin jbardin deleted the jbardin/ignore-changes-map branch October 5, 2020 16:06
@ghost
Copy link

ghost commented Nov 5, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked as resolved and limited conversation to collaborators Nov 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants