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

Deprecating number in favour of numeric #258

Merged
merged 34 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b1d820b
Deprecating number in favour of numeric
bendbennett May 24, 2022
15c6e3b
Switching to using a state upgrader for deprecation of number attribute
bendbennett May 24, 2022
71b3e9d
Using HasChange to detect whether attribute value has been altered
bendbennett May 24, 2022
bccd2c7
Using CustomizeDiff to keep number and numeric in-sync
bendbennett May 25, 2022
b35d514
Examine raw config to determine whether number and numeric have been set
bendbennett May 25, 2022
194e8bd
Extend CustomizeDiff to set number and numeric to true when both are …
bendbennett May 25, 2022
33f8878
Renaming misspelled test file
bendbennett May 25, 2022
dc2b121
Adding test for state upgrade v1
bendbennett May 25, 2022
af7fa64
Adding test for updating number and numeric
bendbennett May 25, 2022
28ed88c
Adding CustomizeDiff and tests for state upgrade and customize diff
bendbennett May 25, 2022
318fc7c
Fix import state func tests
bendbennett May 25, 2022
3cc6aaa
DRY-up func for adding number to state during resource state upgrade …
bendbennett May 25, 2022
8530696
DRY-up funcs for customize diff
bendbennett May 25, 2022
333d4d4
Removing unnecessary func args for state upgrader
bendbennett May 26, 2022
bc50035
Updating docs to deprecate number and add numeric
bendbennett May 26, 2022
dd28e5b
Rewording error messages
bendbennett May 26, 2022
5edfc96
Adding docs to provide context to the usage of customize diff funcs
bendbennett May 26, 2022
d65b4d3
Updating CHANGELOG.md
bendbennett May 26, 2022
8d66210
Setting the CHANGELOG as unreleased
bendbennett May 26, 2022
f45ca85
Temporarily using sdk/v2 sha to use ExternalProviders in TestStep
bendbennett May 27, 2022
2f596d5
Adding test to verify state upgrades by using ExternalProviders withi…
bendbennett May 27, 2022
102133a
Bumping SDK version to use ExternalProviders in TestStep fix and addi…
bendbennett May 27, 2022
80f5843
Adding test cases to verify random password state upgrade behaviour f…
bendbennett May 30, 2022
121e1d2
Consolidating V0 to V2 state upgrade tests
bendbennett May 30, 2022
10efe17
Update unit tests for state upgraders
bendbennett May 30, 2022
6095a62
Consolidate testing of state upgraders
bendbennett May 30, 2022
fd6f3de
Adding testing of state upgrade from v1 to v2 for random string
bendbennett May 30, 2022
fccb472
Using v2.17.0 of terraform-plugin-sdk/v2 for ExternalProviders in Tes…
bendbennett May 31, 2022
59eb920
Remove redundant checks for TestCheckResourceAttrSet
bendbennett Jun 3, 2022
0e0d7c5
Remove shouldError bool from tests
bendbennett Jun 3, 2022
7a1c9be
Refactoring customize diff funcs
bendbennett Jun 3, 2022
40442ed
Updating dependencies
bendbennett Jun 3, 2022
f4bb2c3
Adding terraform 1.2.* to testing matrix
bendbennett Jun 3, 2022
3e61cf7
Refactoring to remove usage of resource name in errors
bendbennett Jun 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jobs:
- '0.15.*'
- '1.0.*'
- '1.1.*'
- '1.2.*'
steps:

- name: Setup Go
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 3.3.0 (Unreleased)

ENHANCEMENTS:

* resource/random_password: `number` is now deprecated and `numeric` has been added to align attribute naming. `number` will be removed in the next major release ([#258](https://github.com/hashicorp/terraform-provider-random/pull/258)).
* resource/random_string: `number` is now deprecated and `numeric` has been added to align attribute naming. `number` will be removed in the next major release ([#258](https://github.com/hashicorp/terraform-provider-random/pull/258)).

Comment on lines +1 to +7
Copy link
Contributor

Choose a reason for hiding this comment

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

👩‍🍳 💋

## 3.2.0 (May 18, 2022)

NEW FEATURES:
Expand Down
3 changes: 2 additions & 1 deletion docs/resources/password.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ resource "aws_db_instance" "example" {
- `min_numeric` (Number) Minimum number of numeric characters in the result. Default value is `0`.
- `min_special` (Number) Minimum number of special characters in the result. Default value is `0`.
- `min_upper` (Number) Minimum number of uppercase alphabet characters in the result. Default value is `0`.
- `number` (Boolean) Include numeric characters in the result. Default value is `true`.
- `number` (Boolean, Deprecated) Include numeric characters in the result. Default value is `true`. **NOTE**: This is deprecated, use `numeric` instead.
- `numeric` (Boolean) Include numeric characters in the result. Default value is `true`.
- `override_special` (String) Supply your own list of special characters to use for string generation. This overrides the default character list in the special argument. The `special` argument must still be set to true for any overwritten characters to be used in generation.
- `special` (Boolean) Include special characters in the result. These are `!@#$%&*()-_=+[]{}<>:?`. Default value is `true`.
- `upper` (Boolean) Include uppercase alphabet characters in the result. Default value is `true`.
Expand Down
3 changes: 2 additions & 1 deletion docs/resources/string.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ resource "random_string" "random" {
- `min_numeric` (Number) Minimum number of numeric characters in the result. Default value is `0`.
- `min_special` (Number) Minimum number of special characters in the result. Default value is `0`.
- `min_upper` (Number) Minimum number of uppercase alphabet characters in the result. Default value is `0`.
- `number` (Boolean) Include numeric characters in the result. Default value is `true`.
- `number` (Boolean, Deprecated) Include numeric characters in the result. Default value is `true`. **NOTE**: This is deprecated, use `numeric` instead.
- `numeric` (Boolean) Include numeric characters in the result. Default value is `true`.
- `override_special` (String) Supply your own list of special characters to use for string generation. This overrides the default character list in the special argument. The `special` argument must still be set to true for any overwritten characters to be used in generation.
- `special` (Boolean) Include special characters in the result. These are `!@#$%&*()-_=+[]{}<>:?`. Default value is `true`.
- `upper` (Boolean) Include uppercase alphabet characters in the result. Default value is `true`.
Expand Down
29 changes: 26 additions & 3 deletions internal/provider/resource_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@ import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"golang.org/x/crypto/bcrypt"
)

// resourcePassword and resourceString both use the same set of CustomizeDiffFunc(s) in order to handle the deprecation
// of the `number` attribute and the simultaneous addition of the `numeric` attribute. planDefaultIfAllNull handles
// ensuring that both `number` and `numeric` default to `true` when they are both absent from config.
// planSyncIfChange handles keeping number and numeric in-sync when either one has been changed.
func resourcePassword() *schema.Resource {
customizeDiffFuncs := planDefaultIfAllNull(true, "number", "numeric")
customizeDiffFuncs = append(customizeDiffFuncs, planSyncIfChange("number", "numeric"))
customizeDiffFuncs = append(customizeDiffFuncs, planSyncIfChange("numeric", "number"))

return &schema.Resource{
Description: "Identical to [random_string](string.html) with the exception that the result is " +
"treated as sensitive and, thus, _not_ displayed in console output. Read more about sensitive " +
Expand All @@ -19,18 +28,26 @@ func resourcePassword() *schema.Resource {
CreateContext: createPassword,
ReadContext: readNil,
DeleteContext: RemoveResourceFromState,
Schema: passwordSchemaV1(),
Schema: passwordSchemaV2(),
Importer: &schema.ResourceImporter{
StateContext: importPasswordFunc,
},
SchemaVersion: 1,
SchemaVersion: 2,
StateUpgraders: []schema.StateUpgrader{
{
Version: 0,
Type: resourcePasswordV0().CoreConfigSchema().ImpliedType(),
Upgrade: resourcePasswordStateUpgradeV0,
},
{
Version: 1,
Type: resourcePasswordV1().CoreConfigSchema().ImpliedType(),
Upgrade: resourcePasswordStringStateUpgradeV1,
},
},
CustomizeDiff: customdiff.All(
customizeDiffFuncs...,
),
}
}

Expand Down Expand Up @@ -74,6 +91,12 @@ func importPasswordFunc(ctx context.Context, d *schema.ResourceData, meta interf
return []*schema.ResourceData{d}, nil
}

func resourcePasswordV1() *schema.Resource {
return &schema.Resource{
Schema: passwordSchemaV1(),
}
}

func resourcePasswordV0() *schema.Resource {
return &schema.Resource{
Schema: passwordSchemaV0(),
Expand All @@ -87,7 +110,7 @@ func resourcePasswordStateUpgradeV0(_ context.Context, rawState map[string]inter

result, ok := rawState["result"].(string)
if !ok {
return nil, fmt.Errorf("resource password state upgrade failed, result could not be asserted as string: %T", rawState["result"])
return nil, fmt.Errorf("resource password state upgrade failed, result is not a string: %T", rawState["result"])
}

hash, err := generateHash(result)
Expand Down
Loading