Skip to content

fix: terraform-plugin-sdk zeros *int fields #123

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

Merged
merged 14 commits into from
Jun 1, 2023

Conversation

mtojek
Copy link
Member

@mtojek mtojek commented May 30, 2023

Related: coder/coder#7582 (comment)

Changes:

  • add computed fields min_ok and max_ok to Validation. These fields substitute the impaired logic in terraform-plugin-sdk (can't handle *ptr).
  • replace *int with int (revert last change) as pointers don't give any benefits now.

For some reason, the Terraform state contains validation.0.min = 0. I managed to fix parameterDataSource to handle nils.

If you look at the state, it doesn't contain absent root properties of coder_parameter (like display_name), but it contains all for Validation. Why :) ?

_, foundDisplayName := state.Primary.Attributes["display_name"]
require.False(t, foundDisplayName, "display_name = "+state.Primary.Attributes["display_name"])
_, foundValidationMin := state.Primary.Attributes["validation.0.min"]
require.False(t, foundValidationMin, "validation.0.min = "+state.Primary.Attributes["validation.0.min"])
Copy link
Member Author

@mtojek mtojek May 30, 2023

Choose a reason for hiding this comment

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

@kylecarbs Maybe you have a clue what is the reason.

@mtojek mtojek force-pushed the bug-validation-min branch from 79a241d to 5f4b94b Compare May 31, 2023 08:26
@mtojek mtojek changed the title bug: validation min = 0 fix: terraform-plugin-sdk zeros *int fields May 31, 2023
@mtojek mtojek self-assigned this May 31, 2023
@mtojek mtojek requested a review from mafredri May 31, 2023 09:21
@mtojek mtojek requested a review from spikecurtis May 31, 2023 09:57
@mtojek mtojek marked this pull request as ready for review May 31, 2023 09:57
@mtojek mtojek requested a review from spikecurtis May 31, 2023 11:39
@mtojek
Copy link
Member Author

mtojek commented May 31, 2023

Thanks, @mafredri, for taking a look! I will wait for the final approval from @spikecurtis and merge it 👍

@mtojek mtojek merged commit 547f1b6 into coder:main Jun 1, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jun 1, 2023
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