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

Implement State Upgrader to Set Defaults for Attributes Assigned Null During Import #313

Merged
merged 9 commits into from
Sep 8, 2022

Conversation

bendbennett
Copy link
Contributor

@bendbennett bendbennett commented Sep 6, 2022

Closes: #302

In the discussion contained in Upgrade v2.2.1 -> v3.4.0 forces replacement there were several comments indicating that a forced replacement was happening under some circumstances:

The attributes in question usually have a default value of 0 assigned (i.e., min_lower, min_upper, min_numeric and min_special) or true assigned (i.e., lower, upper, number, numeric and special) when no value for them is specified in the configuration.

However, under some circumstances, the attributes described can end up with a value of null assigned to them in the state which results in a forced update when terraform apply is run.

One of the circumstances that can give rise to the storage of null values for these attributes is using terraform import with a version of the provider that is v3.3.1 or earlier. Under these circumstances, all of the attributes mentioned, along with length are assigned a value of null in state.

This PR aims to address this issue by implementing a state upgrader which interrogates each of the aforementioned attributes and assigns it a default value if the value currently held for the attribute in state is null.

bflad and others added 4 commits September 6, 2022 17:16
…te following import with earlier versions of the provider.

For instance, using v3.3.1 to import a random password resource will result in the state file containing null values for length, lower, number, special, upper, min_lower, min_numeric, min_special, min_upper attributes.
…ld be present in state following import with earlier versions of the provider.

For instance, using v3.3.1 to import a random password resource will result in the state file containing null values for length, lower, number, special, upper, min_lower, min_numeric, min_special, min_upper attributes.
…d with state upgrader changes handling fix of bcrypt
…tting defaults for lower, number, numeric, special, upper, min_lower, min_numeric, min_special, min_upper and setting length when these attributes have been set to null
@bendbennett bendbennett marked this pull request as ready for review September 8, 2022 07:55
@bendbennett bendbennett requested a review from a team as a code owner September 8, 2022 07:55
@bendbennett
Copy link
Contributor Author

I've marked this as ready for review as the code changes should be complete.

Checks will fail until terraform-plugin-sdk v2.22.0 containing ImportStatePersist is released and this branch is updated to use that tag.

@bflad bflad added this to the v3.4.3 milestone Sep 8, 2022
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

Looks good to me 🚀

internal/provider/resource_password.go Outdated Show resolved Hide resolved
@bendbennett bendbennett merged commit 7c57c5f into main Sep 8, 2022
@bendbennett bendbennett deleted the bendbennett/handle-nulls branch September 8, 2022 14:43
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade v2.2.1 -> v3.4.0 forces replacement
2 participants