Skip to content

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

Merged
mtojek merged 14 commits into
coder:mainfrom
mtojek:bug-validation-min
Jun 1, 2023
Merged

fix: terraform-plugin-sdk zeros *int fields#123
mtojek merged 14 commits into
coder:mainfrom
mtojek:bug-validation-min

Conversation

@mtojek
Copy link
Copy Markdown
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 :) ?

Comment thread provider/parameter_test.go Outdated
_, 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
Copy Markdown
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
Comment thread provider/parameter.go
Comment thread provider/parameter.go Outdated
Comment thread provider/parameter.go Outdated
Comment thread provider/parameter_test.go
@mtojek mtojek requested a review from spikecurtis May 31, 2023 11:39
@mtojek
Copy link
Copy Markdown
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