Skip to content

Commit 870024c

Browse files
authored
[Documentation] Update CONTRIBUTING guidelines for migrating resource to plugin framework (#5121)
## Changes <!-- Summary of your changes that are easy to understand --> Add best practices with examples for migrating resources to plugin framework. ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> N/A
1 parent 22da2ce commit 870024c

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

CONTRIBUTING.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,79 @@ resp.Schema = tfschema.ResourceStructToSchema(ctx, Resource_SdkV2{}, func(c tfsc
178178
})
179179
```
180180
181+
Make sure that migrated resources are compatible with both SDKv2 and Plugin Framework.
182+
- The schema struct should have a `types.String` ID field. Example:
183+
```go
184+
type ResourceInfoExtended struct {
185+
package_tf.ResourceInfo_SdkV2
186+
ID types.String `tfsdk:"id"` // Adding ID field to stay compatible with SDKv2
187+
}
188+
189+
```
190+
191+
- Add integration tests to verify that the resource is both SDKv2 and Plugin Framework compatible. Example:
192+
193+
#### SDKv2 Compatibility
194+
```go
195+
func TestSDKv2Compatibility(t *testing.T) {
196+
acceptance.WorkspaceLevel(t,
197+
// Step 1: Create resource using plugin framework implementation
198+
acceptance.Step{
199+
Template: `
200+
resource "databricks_some_resource" "this" {
201+
name = "abc"
202+
}
203+
`
204+
},
205+
// Step 2: Update the resource using SDKv2
206+
acceptance.Step{
207+
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
208+
"databricks": func() (tfprotov6.ProviderServer, error) {
209+
sdkv2Provider, pluginfwProvider := acceptance.ProvidersWithResourceFallbacks([]string{"databricks_some_resource"})
210+
return providers.GetProviderServer(context.Background(), providers.WithSdkV2Provider(sdkv2Provider), providers.WithPluginFrameworkProvider(pluginfwProvider))
211+
},
212+
},
213+
Template: `
214+
resource "databricks_some_resource" "this" {
215+
name = "abc"
216+
}
217+
`,
218+
},
219+
)
220+
}
221+
```
222+
223+
#### Plugin Framework Compatibility
224+
```go
225+
func TestPluginFrameworkCompatibility(t *testing.T) {
226+
acceptance.WorkspaceLevel(t,
227+
// Step 1: Create the resource using SDKv2
228+
acceptance.Step{
229+
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
230+
"databricks": func() (tfprotov6.ProviderServer, error) {
231+
sdkv2Provider, pluginfwProvider := acceptance.ProvidersWithResourceFallbacks([]string{"databricks_some_resource"})
232+
return providers.GetProviderServer(context.Background(), providers.WithSdkV2Provider(sdkv2Provider), providers.WithPluginFrameworkProvider(pluginfwProvider))
233+
},
234+
},
235+
Template: `
236+
resource "databricks_some_resource" "this" {
237+
name = "abc"
238+
}
239+
`,
240+
},
241+
// Step 2: Update the resource using plugin framework implementation
242+
acceptance.Step{
243+
Template: `
244+
resource "databricks_some_resource" "this" {
245+
name = "abc"
246+
}
247+
`
248+
},
249+
250+
)
251+
}
252+
```
253+
181254
### Code Organization
182255
Each resource and data source should be defined in package `internal/providers/plugnifw/products/<resource>`, e.g.: `internal/providers/plugnifw/products/volume` package will contain both resource, data sources and other utils specific to volumes. Tests (both unit and integration tests) will also remain in this package.
183256

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* Document `table_update` trigger in `databricks_job` resource ([#5107](https://github.com/databricks/terraform-provider-databricks/pull/5107))
1616
* Document new attributes in `databricks_app` resource and data sources ([#5108](https://github.com/databricks/terraform-provider-databricks/pull/5108))
1717
* Document `git_email` in `databricks_git_credential` resource ([#5099](https://github.com/databricks/terraform-provider-databricks/pull/5099))
18+
* Update `CONTRIBUTING` guidelines for migrating resources to plugin framework ([#5121](https://github.com/databricks/terraform-provider-databricks/pull/5121))
1819

1920
### Exporter
2021

0 commit comments

Comments
 (0)