Skip to content

Commit eee789a

Browse files
committed
Remove links to source code and make examples generic in migrating - data sources - overview (#418)
1 parent ae37506 commit eee789a

File tree

1 file changed

+14
-28
lines changed
  • website/docs/plugin/framework/migrating/data-sources

1 file changed

+14
-28
lines changed

website/docs/plugin/framework/migrating/data-sources/index.mdx

+14-28
Original file line numberDiff line numberDiff line change
@@ -100,39 +100,29 @@ Remember the following details when completing the migration from SDKv2 to the F
100100
101101
## Example
102102
103-
The following examples show how to migrate portions of the [http](https://github.com/hashicorp/terraform-provider-http)
104-
provider.
105-
106-
For a complete example, clone the
107-
`terraform-provider-http` repository and compare the `data_source.go` file in
108-
[v2.2.0](https://github.com/hashicorp/terraform-provider-http/blob/v2.2.0/internal/provider/data_source.go)
109-
and the `data_source_http.go` file
110-
[after the migration](https://github.com/hashicorp/terraform-provider-http/blob/8527d5b4546b54cdef246a13befc5745dbbbf740/internal/provider/data_source_http.go).
111-
112103
### SDKv2
113104
114-
The following example from the `provider.go` file shows an implementation of the `DataSourcesMap` field on the provider
105+
The following example shows an implementation of the `DataSourcesMap` field on the provider
115106
schema with SDKv2.
116107
117108
```go
118109
func New() (*schema.Provider, error) {
119110
return &schema.Provider {
120111
DataSourcesMap: map[string]*schema.Resource {
121-
"http": dataSource(),
112+
"example_datasource": exampleDataSource(),
122113
/* ... */
123114
```
124115
125-
The following example from the `data_source.go` file shows how the `ReadContext` function and `Schema` are defined for
126-
the `http` data source with SDKv2.
116+
The following example shows how the `ReadContext` function and `Schema` are defined for
117+
the `exampleResource` data source with SDKv2.
127118
128119
```go
129-
func dataSource() *schema.Resource {
120+
func exampleDataSource() *schema.Resource {
130121
return &schema.Resource{
131122
ReadContext: dataSourceRead,
132123

133124
Schema: map[string]*schema.Schema{
134-
"url": {
135-
Description: "The URL for the request. Supported schemes are `http` and `https`.",
125+
"example_attribute": {
136126
Type: schema.TypeString,
137127
Required: true,
138128
},
@@ -144,40 +134,36 @@ func dataSource() *schema.Resource {
144134
145135
### Framework
146136
147-
The following example from the `provider.go` file shows how the `http` data source is defined with the Framework after
137+
The following example shows how the `exampleDataSource` data source is defined with the Framework after
148138
the migration.
149139
150140
```go
151141
func (p *provider) DataSources(context.Context) []func() datasource.DataSource {
152142
return []func() datasource.DataSource{
153143
func() datasource.DataSource {
154-
return &httpDataSource{}
144+
return &exampleDataSource{}
155145
},
156146
}
157147
}
158148
```
159149
160-
This code from the `data_source_http.go` file defines the methods for the `http` data source with the
150+
This code defines the methods for the `exampleDataSource` data source with the
161151
Framework.
162152
163153
```go
164-
func (d *httpDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
165-
// This is unconventional in that the data source name matches the provider name.
166-
// Typically these should have the provider name, an underscore, then the type name.
167-
// e.g. http_request
168-
resp.TypeName = "http"
154+
func (d *exampleDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
155+
resp.TypeName = "example_datasource"
169156
}
170157

171-
func (d *httpDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
158+
func (d *exampleDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
172159
resp.Schema = schema.Schema{
173160
Attributes: map[string]schema.Attribute{
174-
"url": schema.StringAttribute{
175-
Description: "The URL for the request. Supported schemes are `http` and `https`.",
161+
"example_attribute": schema.StringAttribute{
176162
Required: true,
177163
},
178164
/* ... */
179165

180-
func (d *httpDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
166+
func (d *exampleDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
181167
/* ... */
182168
}
183169
```

0 commit comments

Comments
 (0)