Skip to content

Commit 96bc479

Browse files
authored
Merge pull request #258 from hashicorp/bendbennett/rename-number
Deprecating number in favour of numeric
2 parents d6c03c2 + 3e61cf7 commit 96bc479

File tree

11 files changed

+982
-166
lines changed

11 files changed

+982
-166
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ jobs:
6565
- '0.15.*'
6666
- '1.0.*'
6767
- '1.1.*'
68+
- '1.2.*'
6869
steps:
6970

7071
- name: Setup Go

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 3.3.0 (Unreleased)
2+
3+
ENHANCEMENTS:
4+
5+
* 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)).
6+
* 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)).
7+
18
## 3.2.0 (May 18, 2022)
29

310
NEW FEATURES:

docs/resources/password.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ resource "aws_db_instance" "example" {
4646
- `min_numeric` (Number) Minimum number of numeric characters in the result. Default value is `0`.
4747
- `min_special` (Number) Minimum number of special characters in the result. Default value is `0`.
4848
- `min_upper` (Number) Minimum number of uppercase alphabet characters in the result. Default value is `0`.
49-
- `number` (Boolean) Include numeric characters in the result. Default value is `true`.
49+
- `number` (Boolean, Deprecated) Include numeric characters in the result. Default value is `true`. **NOTE**: This is deprecated, use `numeric` instead.
50+
- `numeric` (Boolean) Include numeric characters in the result. Default value is `true`.
5051
- `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.
5152
- `special` (Boolean) Include special characters in the result. These are `!@#$%&*()-_=+[]{}<>:?`. Default value is `true`.
5253
- `upper` (Boolean) Include uppercase alphabet characters in the result. Default value is `true`.

docs/resources/string.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ resource "random_string" "random" {
4141
- `min_numeric` (Number) Minimum number of numeric characters in the result. Default value is `0`.
4242
- `min_special` (Number) Minimum number of special characters in the result. Default value is `0`.
4343
- `min_upper` (Number) Minimum number of uppercase alphabet characters in the result. Default value is `0`.
44-
- `number` (Boolean) Include numeric characters in the result. Default value is `true`.
44+
- `number` (Boolean, Deprecated) Include numeric characters in the result. Default value is `true`. **NOTE**: This is deprecated, use `numeric` instead.
45+
- `numeric` (Boolean) Include numeric characters in the result. Default value is `true`.
4546
- `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.
4647
- `special` (Boolean) Include special characters in the result. These are `!@#$%&*()-_=+[]{}<>:?`. Default value is `true`.
4748
- `upper` (Boolean) Include uppercase alphabet characters in the result. Default value is `true`.

internal/provider/resource_password.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@ import (
55
"fmt"
66

77
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
910
"golang.org/x/crypto/bcrypt"
1011
)
1112

13+
// resourcePassword and resourceString both use the same set of CustomizeDiffFunc(s) in order to handle the deprecation
14+
// of the `number` attribute and the simultaneous addition of the `numeric` attribute. planDefaultIfAllNull handles
15+
// ensuring that both `number` and `numeric` default to `true` when they are both absent from config.
16+
// planSyncIfChange handles keeping number and numeric in-sync when either one has been changed.
1217
func resourcePassword() *schema.Resource {
18+
customizeDiffFuncs := planDefaultIfAllNull(true, "number", "numeric")
19+
customizeDiffFuncs = append(customizeDiffFuncs, planSyncIfChange("number", "numeric"))
20+
customizeDiffFuncs = append(customizeDiffFuncs, planSyncIfChange("numeric", "number"))
21+
1322
return &schema.Resource{
1423
Description: "Identical to [random_string](string.html) with the exception that the result is " +
1524
"treated as sensitive and, thus, _not_ displayed in console output. Read more about sensitive " +
@@ -19,18 +28,26 @@ func resourcePassword() *schema.Resource {
1928
CreateContext: createPassword,
2029
ReadContext: readNil,
2130
DeleteContext: RemoveResourceFromState,
22-
Schema: passwordSchemaV1(),
31+
Schema: passwordSchemaV2(),
2332
Importer: &schema.ResourceImporter{
2433
StateContext: importPasswordFunc,
2534
},
26-
SchemaVersion: 1,
35+
SchemaVersion: 2,
2736
StateUpgraders: []schema.StateUpgrader{
2837
{
2938
Version: 0,
3039
Type: resourcePasswordV0().CoreConfigSchema().ImpliedType(),
3140
Upgrade: resourcePasswordStateUpgradeV0,
3241
},
42+
{
43+
Version: 1,
44+
Type: resourcePasswordV1().CoreConfigSchema().ImpliedType(),
45+
Upgrade: resourcePasswordStringStateUpgradeV1,
46+
},
3347
},
48+
CustomizeDiff: customdiff.All(
49+
customizeDiffFuncs...,
50+
),
3451
}
3552
}
3653

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

94+
func resourcePasswordV1() *schema.Resource {
95+
return &schema.Resource{
96+
Schema: passwordSchemaV1(),
97+
}
98+
}
99+
77100
func resourcePasswordV0() *schema.Resource {
78101
return &schema.Resource{
79102
Schema: passwordSchemaV0(),
@@ -87,7 +110,7 @@ func resourcePasswordStateUpgradeV0(_ context.Context, rawState map[string]inter
87110

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

93116
hash, err := generateHash(result)

0 commit comments

Comments
 (0)