Skip to content

Commit 3290d60

Browse files
committed
Remove links to source code and make examples generic in migrating - attributes & blocks - validators predefined (#418)
1 parent 01fb2c8 commit 3290d60

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed

website/docs/plugin/framework/migrating/attributes-blocks/validators-predefined.mdx

+32-34
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ description: >-
1010
-> **Note:** The Plugin Framework is in beta.
1111

1212
Attribute validators ensure that attributes do or do not contain specific values. You can use predefined validators for
13-
many use cases, or implement custom validators. Refer to [Schemas - Validators](/plugin/framework/schemas#validators) in
13+
many use cases, or implement custom validators. Refer to [Schemas - Validators](/plugin/framework/handling-data/schemas#validators) in
1414
the Framework documentation for details. Refer to the
1515
[Attributes - Custom Validators](/plugin/framework/migrating/attributes-blocks/validators-custom) page in this guide to learn how to
1616
implement custom validators.
@@ -85,42 +85,40 @@ your requirements.
8585
8686
## Example
8787
88-
The following examples show how to migrate portions of the [tls](https://github.com/hashicorp/terraform-provider-tls)
89-
provider.
90-
91-
For a complete example, clone the
92-
`terraform-provider-tls` repository and compare the `provider.go` file in
93-
[v3.4.0](https://github.com/hashicorp/terraform-provider-tls/blob/v3.4.0/internal/provider/provider.go)
94-
with [v4.0.1](https://github.com/hashicorp/terraform-provider-tls/blob/v4.0.1/internal/provider/provider.go).
95-
9688
### SDKv2
9789
98-
The following example from the `provider.go` file shows the implementation of the `ConflictsWith` field on the
99-
provider's `proxy` block's `url` attribute. This validator checks that the provider does not use the `url` attribute
100-
when the proxy's url is set through the environment. The example also uses the `RequiredWith` field to ensure that the
101-
`password` attribute is configured when `username` is, and vice-versa.
90+
The following example shows the implementation of the `ConflictsWith` field on the
91+
provider's `example_block` block's `example_attribute_one` attribute.
92+
This validator checks that the provider does not use the `example_attribute_one` attribute
93+
when the `example_attribute_four` is being used. The example also uses the `RequiredWith` field to ensure that the
94+
`example_attribute_two` attribute is configured when `example_attribute_one` is, and that the
95+
`example_attribute_three` attribute is configured when `example_attribute_two` is.
10296
10397
```go
10498
func New() (*schema.Provider, error) {
10599
return &schema.Provider{
106100
Schema: map[string]*schema.Schema{
107-
"proxy": {
101+
"example_block": {
108102
Elem: &schema.Resource{
109103
Schema: map[string]*schema.Schema{
110-
"url": {
111-
ConflictsWith: []string{"proxy.0.from_env"},
104+
"example_attribute_one": {
105+
ConflictsWith: []string{"example_block.0.example_attribute_four"},
112106
/* ... */
113107
},
114-
"username": {
115-
RequiredWith: []string{"proxy.0.url"},
108+
"example_attribute_two": {
109+
RequiredWith: []string{"example_block.0.example_attribute_one"},
116110
/* ... */
117111
},
118-
"password": {
119-
RequiredWith: []string{"proxy.0.username"},
112+
"example_attribute_three": {
113+
RequiredWith: []string{"example_block.0.example_attribute_two"},
120114
/* ... */
121115
},
122-
"from_env": {
123-
ConflictsWith: []string{"proxy.0.url", "proxy.0.username", "proxy.0.password"},
116+
"example_attribute_four": {
117+
ConflictsWith: []string{
118+
"example_block.0.example_attribute_one",
119+
"example_block.0.example_attribute_two",
120+
"example_block.0.example_attribute_three",
121+
},
124122
/* ... */
125123
},
126124
},
@@ -136,39 +134,39 @@ func New() (*schema.Provider, error) {
136134
The following shows the same section of provider code after the migration.
137135
138136
This code implements the `ConflictsWith` and `AlsoRequires` validators with the Framework. The validators are configured
139-
via the `Validators` field of the provider's `proxy` block's attribute schema.
137+
via the `Validators` field of the provider's `example_block` block's attribute schema.
140138
141139
```go
142140
func (p *TlsProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) {
143141
resp.Schema = schema.Schema{
144142
Blocks: map[string]schema.Block{
145-
"proxy": schema.ListNestedBlock{
143+
"example_block": schema.ListNestedBlock{
146144
NestedObject: schema.NestedBlockObject{
147145
Attributes: map[string]schema.Attribute{
148-
"url": schema.StringAttribute{
146+
"example_attribute_one": schema.StringAttribute{
149147
Validators: []validator.String{
150-
stringvalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("from_env")),
148+
stringvalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("example_attribute_four")),
151149
},
152150
/* ... */
153151
},
154-
"username": schema.StringAttribute{
152+
"example_attribute_two": schema.StringAttribute{
155153
Validators: []validator.String{
156-
stringvalidator.AlsoRequires(path.MatchRelative().AtParent().AtName("url")),
154+
stringvalidator.AlsoRequires(path.MatchRelative().AtParent().AtName("example_attribute_one")),
157155
},
158156
/* ... */
159157
},
160-
"password": schema.StringAttribute{
158+
"example_attribute_three": schema.StringAttribute{
161159
Validators: []validator.String{
162-
stringvalidator.AlsoRequires(path.MatchRelative().AtParent().AtName("username")),
160+
stringvalidator.AlsoRequires(path.MatchRelative().AtParent().AtName("example_attribute_two")),
163161
},
164162
/* ... */
165163
},
166-
"from_env": schema.BoolAttribute{
164+
"example_attribute_four": schema.BoolAttribute{
167165
Validators: []validator.Bool{
168166
boolvalidator.ConflictsWith(
169-
path.MatchRelative().AtParent().AtName("url"),
170-
path.MatchRelative().AtParent().AtName("username"),
171-
path.MatchRelative().AtParent().AtName("password"),
167+
path.MatchRelative().AtParent().AtName("example_attribute_one"),
168+
path.MatchRelative().AtParent().AtName("example_attribute_two"),
169+
path.MatchRelative().AtParent().AtName("example_attribute_three"),
172170
),
173171
},
174172
/* ... */

0 commit comments

Comments
 (0)