Skip to content

Commit a19d742

Browse files
committed
Remove links to source code and make examples generic in migrating - providers - overview (#418)
1 parent 7869744 commit a19d742

File tree

2 files changed

+23
-44
lines changed

2 files changed

+23
-44
lines changed

website/docs/plugin/framework/migrating/providers/index.mdx

+22-43
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,6 @@ creates data source types that you define, which satisfy the `datasource.DataSou
203203

204204
### Example
205205

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-
214206
#### SDKv2
215207

216208
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
219211
func New() (*schema.Provider, error) {
220212
return &schema.Provider{
221213
Schema: map[string]*schema.Schema{
222-
"proxy": {
214+
"attribute": {
223215
/* ... */
224216
},
225217
},
226218
ConfigureContextFunc: configureProvider,
227219
ResourcesMap: map[string]*schema.Resource{
228-
"tls_private_key": resourcePrivateKey(),
220+
"exampleResource": exampleResource(),
229221
/* ... */
230222
},
231223
DataSourcesMap: map[string]*schema.Resource{
232-
"tls_public_key": dataSourcePublicKey(),
224+
"exampleDataSource": exampleDataSource(),
233225
/* ... */
234226
},
235227
}, nil
@@ -241,41 +233,41 @@ func New() (*schema.Provider, error) {
241233
The following shows the same section of provider code after the migration.
242234

243235
```go
244-
var _ provider.Provider = (*TlsProvider)(nil)
236+
var _ provider.Provider = (*exampleProvider)(nil)
245237

246238
func New() provider.Provider {
247-
return &TlsProvider{}
239+
return &exampleProvider{}
248240
}
249241

250-
func (p *TlsProvider) Resources(_ context.Context) []func() resource.Resource {
242+
func (p *exampleProvider) Resources(_ context.Context) []func() resource.Resource {
251243
return []func() resource.Resource{
252244
func() resource.Resource {
253-
return &privateKeyResource{}
245+
return &exampleResource{}
254246
},
255247
/* ... */
256248
}
257249
}
258250

259-
func (p *TlsProvider) DataSources(_ context.Context) []func() datasource.DataSource {
251+
func (p *exampleProvider) DataSources(_ context.Context) []func() datasource.DataSource {
260252
return []func() datasource.DataSource{
261253
func() datasource.DataSource {
262-
return &publicKeyDataSource{},
254+
return &exampleDataSource{},
263255
},
264256
/* ... */
265257
}
266258
}
267259

268-
func (p *TlsProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) {
260+
func (p *exampleProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) {
269261
resp.Schema = schema.Schema{
270262
Attributes: map[string]schema.Attribute{
271-
"proxy": schema.SingleNestedBlock{
263+
"attribute": schema.SingleNestedBlock{
272264
/* ... */
273265
},
274266
},
275267
}
276268
}
277269

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) {
279271
/* ... */
280272
}
281273
```
@@ -332,38 +324,28 @@ Framework `schema.Schema` is a struct that includes attributes and blocks.
332324
333325
### Example
334326
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,
344328
respectively. Refer to the
345329
[Blocks with Computed Fields](/plugin/framework/migrating/attributes-blocks/blocks-computed) page in this guide for more
346330
details.
347331
348332
#### SDKv2
349333
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.
351335
352336
```go
353337
Schema: map[string]*schema.Schema{
354-
"proxy": {
338+
"example_block": {
355339
Type: schema.TypeList,
356340
Optional: true,
357341
MaxItems: 1,
358342
Elem: &schema.Resource{
359343
Schema: map[string]*schema.Schema{
360-
"url": {
344+
"example_attribute": {
361345
Type: schema.TypeString,
362346
Optional: true,
363347
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"},
367349
},
368350
/* ... */
369351
```
@@ -372,22 +354,19 @@ Schema: map[string]*schema.Schema{
372354
373355
The following shows the same section of provider code after the migration.
374356
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.
376358
377359
```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) {
379361
resp.Schema = schema.Schema{
380362
Attributes: map[string]schema.Attribute{
381-
"proxy": schema.SingleNestedBlock{
363+
"example_block": schema.SingleNestedBlock{
382364
Optional: true,
383365
Attributes: map[string]schema.Attribute{
384-
"url": schema.StringAttribute{
366+
"example_attribute": schema.StringAttribute{
385367
Optional: true,
386368
Validators: []validator.String{
387369
attribute_validator.UrlWithScheme(supportedProxySchemesStr()...),
388-
stringvalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("from_env")),
370+
stringvalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("another_attribute")),
389371
},
390-
MarkdownDescription: "URL used to connect to the Proxy. " +
391-
fmt.Sprintf("Accepted schemes are: `%s`. ", strings.Join(supportedProxySchemesStr(), "`, `")),
392-
},
393372
```

website/docs/plugin/framework/migrating/testing.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ provider, which is built on SDKv2.
3737
http provider repository. The second step also uses `PlanOnly` to verify that a no-op plan is generated.
3838

3939
```go
40-
func TestDataSource_UpgradeFromVersion2_2_0(t *testing.T) {
40+
func TestDataSource_UpgradeFromVersion(t *testing.T) {
4141
/* ... */
4242
resource.Test(t, resource.TestCase{
4343
Steps: []resource.TestStep{

0 commit comments

Comments
 (0)