@@ -203,14 +203,6 @@ creates data source types that you define, which satisfy the `datasource.DataSou
203
203
204
204
### Example
205
205
206
- The following examples show how to migrate portions of the [ tls] ( https://github.com/hashicorp/terraform-provider-tls )
207
- provider.
208
-
209
- For a complete example, clone the
210
- ` terraform-provider-tls ` repository and compare ` provider.go ` in
211
- [ v3.4.0] ( https://github.com/hashicorp/terraform-provider-tls/blob/v3.4.0/internal/provider/provider.go )
212
- with the file [ after the migration] ( https://github.com/hashicorp/terraform-provider-tls/blob/4dafb105818e45a88532f917e7b170ee2a9bb092/internal/provider/provider.go ) .
213
-
214
206
#### SDKv2
215
207
216
208
The following example shows how to set up a provider schema, configuration, resources, and data sources using SDKv2.
@@ -219,17 +211,17 @@ The following example shows how to set up a provider schema, configuration, reso
219
211
func New () (*schema .Provider , error ) {
220
212
return &schema.Provider {
221
213
Schema: map [string ]*schema.Schema {
222
- " proxy " : {
214
+ " attribute " : {
223
215
/* ... */
224
216
},
225
217
},
226
218
ConfigureContextFunc: configureProvider,
227
219
ResourcesMap: map [string ]*schema.Resource {
228
- " tls_private_key " : resourcePrivateKey (),
220
+ " exampleResource " : exampleResource (),
229
221
/* ... */
230
222
},
231
223
DataSourcesMap: map [string ]*schema.Resource {
232
- " tls_public_key " : dataSourcePublicKey (),
224
+ " exampleDataSource " : exampleDataSource (),
233
225
/* ... */
234
226
},
235
227
}, nil
@@ -241,41 +233,41 @@ func New() (*schema.Provider, error) {
241
233
The following shows the same section of provider code after the migration.
242
234
243
235
``` go
244
- var _ provider.Provider = (*TlsProvider )(nil )
236
+ var _ provider.Provider = (*exampleProvider )(nil )
245
237
246
238
func New () provider .Provider {
247
- return &TlsProvider {}
239
+ return &exampleProvider {}
248
240
}
249
241
250
- func (p *TlsProvider ) Resources (_ context .Context ) []func () resource.Resource {
242
+ func (p *exampleProvider ) Resources (_ context .Context ) []func () resource.Resource {
251
243
return []func () resource.Resource {
252
244
func () resource.Resource {
253
- return &privateKeyResource {}
245
+ return &exampleResource {}
254
246
},
255
247
/* ... */
256
248
}
257
249
}
258
250
259
- func (p *TlsProvider ) DataSources (_ context .Context ) []func () datasource.DataSource {
251
+ func (p *exampleProvider ) DataSources (_ context .Context ) []func () datasource.DataSource {
260
252
return []func () datasource.DataSource {
261
253
func () datasource.DataSource {
262
- return &publicKeyDataSource {},
254
+ return &exampleDataSource {},
263
255
},
264
256
/* ... */
265
257
}
266
258
}
267
259
268
- func (p *TlsProvider ) Schema (_ context .Context , _ provider .SchemaRequest , resp *provider .SchemaResponse ) {
260
+ func (p *exampleProvider ) Schema (_ context .Context , _ provider .SchemaRequest , resp *provider .SchemaResponse ) {
269
261
resp.Schema = schema.Schema {
270
262
Attributes: map [string ]schema.Attribute {
271
- " proxy " : schema.SingleNestedBlock {
263
+ " attribute " : schema.SingleNestedBlock {
272
264
/* ... */
273
265
},
274
266
},
275
267
}
276
268
}
277
269
278
- func (p *TlsProvider ) Configure (ctx context .Context , req provider .ConfigureRequest , res *provider .ConfigureResponse ) {
270
+ func (p *exampleProvider ) Configure (ctx context .Context , req provider .ConfigureRequest , res *provider .ConfigureResponse ) {
279
271
/* ... */
280
272
}
281
273
```
@@ -332,38 +324,28 @@ Framework `schema.Schema` is a struct that includes attributes and blocks.
332
324
333
325
### Example
334
326
335
- The following examples show how to migrate portions of the [tls](https://github.com/hashicorp/terraform-provider-tls)
336
- provider.
337
-
338
- For a complete example, clone the
339
- ` terraform-provider-tls` repository and compare ` provider.go ` in
340
- [v3.4.0](https://github.com/hashicorp/terraform-provider-tls/blob/v3.4.0/internal/provider/provider.go)
341
- with the file [after the migration](https://github.com/hashicorp/terraform-provider-tls/blob/4dafb105818e45a88532f917e7b170ee2a9bb092/internal/provider/provider.go).
342
-
343
- This example also shows how to use a nested block and a nested attribute for the SDKv2 and Framework examples,
327
+ This example shows how to use a nested block and a nested attribute for the SDKv2 and Framework examples,
344
328
respectively. Refer to the
345
329
[Blocks with Computed Fields](/plugin/framework/migrating/attributes-blocks/blocks-computed) page in this guide for more
346
330
details.
347
331
348
332
#### SDKv2
349
333
350
- The following example from the ` provider. go ` file shows the configuration of the ` url ` attribute for the provider's` proxy ` configuration block.
334
+ The following example shows the configuration of the ` example_attribute ` attribute for the provider's ` example_block ` configuration block.
351
335
352
336
` ` ` go
353
337
Schema: map [string ]*schema.Schema {
354
- " proxy " : {
338
+ " example_block " : {
355
339
Type: schema.TypeList ,
356
340
Optional: true ,
357
341
MaxItems: 1 ,
358
342
Elem: &schema.Resource {
359
343
Schema: map [string ]*schema.Schema {
360
- " url " : {
344
+ " example_attribute " : {
361
345
Type: schema.TypeString ,
362
346
Optional: true ,
363
347
ValidateDiagFunc: validation.ToDiagFunc (validation.IsURLWithScheme (SupportedProxySchemesStr ())),
364
- ConflictsWith: []string {" proxy.0.from_env" },
365
- Description: " URL used to connect to the Proxy. " +
366
- fmt.Sprintf (" Accepted schemes are: `%s `. " , strings.Join (SupportedProxySchemesStr (), " `, `" )),
348
+ ConflictsWith: []string {" example_block.0.another_attribute" },
367
349
},
368
350
/* ... */
369
351
` ` `
@@ -372,22 +354,19 @@ Schema: map[string]*schema.Schema{
372
354
373
355
The following shows the same section of provider code after the migration.
374
356
375
- This code implements the ` url ` attribute for the ` proxy ` block with the Framework.
357
+ This code implements the ` example_attribute ` attribute for the ` example_Block ` block with the Framework.
376
358
377
359
` ` ` go
378
- func (p *TlsProvider ) Schema (_ context.Context , _ provider.SchemaRequest , resp *provider.SchemaResponse ) {
360
+ func (p *exampleProvider ) Schema (_ context.Context , _ provider.SchemaRequest , resp *provider.SchemaResponse ) {
379
361
resp.Schema = schema.Schema {
380
362
Attributes: map [string ]schema.Attribute {
381
- " proxy " : schema.SingleNestedBlock {
363
+ " example_block " : schema.SingleNestedBlock {
382
364
Optional: true ,
383
365
Attributes: map [string ]schema.Attribute {
384
- " url " : schema.StringAttribute {
366
+ " example_attribute " : schema.StringAttribute {
385
367
Optional: true ,
386
368
Validators: []validator.String {
387
369
attribute_validator.UrlWithScheme (supportedProxySchemesStr ()...),
388
- stringvalidator.ConflictsWith (path.MatchRelative ().AtParent ().AtName (" from_env " )),
370
+ stringvalidator.ConflictsWith (path.MatchRelative ().AtParent ().AtName (" another_attribute " )),
389
371
},
390
- MarkdownDescription: " URL used to connect to the Proxy. " +
391
- fmt.Sprintf (" Accepted schemes are: `%s `. " , strings.Join (supportedProxySchemesStr (), " `, `" )),
392
- },
393
372
` ` `
0 commit comments