-
Notifications
You must be signed in to change notification settings - Fork 394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Internal][Draft] Plugin Framework Rollout #4101
Draft
edwardfeng-db
wants to merge
3
commits into
main
Choose a base branch
from
edwardfeng-db/rollout-pfw
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package pluginfw | ||
|
||
// This file contains all of the utils for controlling the plugin framework rollout. | ||
// For migrated resources and data sources, we can add them to the two maps below to have them registered with the plugin framework. | ||
// Users can manually specify resources and data sources to use SDK V2 instead of the plugin framework by setting the USE_SDK_V2_RESOURCES and USE_SDK_V2_DATA_SOURCES environment variables. | ||
// | ||
// Example: USE_SDK_V2_RESOURCES="databricks_library" would force the library resource to use SDK V2 instead of the plugin framework. | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
|
||
"github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/resources/cluster" | ||
"github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/resources/library" | ||
"github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/resources/qualitymonitor" | ||
"github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/resources/registered_model" | ||
"github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/resources/volume" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/resource" | ||
) | ||
|
||
// Map of resources that have been migrated from SDK V2 to plugin framework | ||
var migratedResourceMap = map[string]func() resource.Resource{ | ||
"databricks_qualitymonitor": qualitymonitor.ResourceQualityMonitor, | ||
"databricks_library": library.ResourceLibrary, | ||
} | ||
|
||
// Map of data sources that have been migrated from SDK V2 to plugin framework | ||
var migratedDataSourceMap = map[string]func() datasource.DataSource{ | ||
"databricks_cluster": cluster.DataSourceCluster, | ||
"databricks_volumes": volume.DataSourceVolumes, | ||
"databricks_registered_model": registered_model.DataSourceRegisteredModel, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was not migrated IIUC. It should only exist in the plugin framework. |
||
} | ||
|
||
// GetUseSdkV2DataSources is a helper function to get name of resources that should use SDK V2 instead of plugin framework | ||
func getUseSdkV2Resources() []string { | ||
useSdkV2 := os.Getenv("USE_SDK_V2_RESOURCES") | ||
if useSdkV2 == "" { | ||
return []string{} | ||
} | ||
return strings.Split(useSdkV2, ",") | ||
} | ||
|
||
// GetUseSdkV2DataSources is a helper function to get name of data sources that should use SDK V2 instead of plugin framework | ||
func getUseSdkV2DataSources() []string { | ||
useSdkV2 := os.Getenv("USE_SDK_V2_DATA_SOURCES") | ||
if useSdkV2 == "" { | ||
return []string{} | ||
} | ||
return strings.Split(useSdkV2, ",") | ||
} | ||
|
||
// Helper function to check if a resource should use be in SDK V2 instead of plugin framework | ||
func shouldUseSdkV2Resource(resourceName string) bool { | ||
useSdkV2Resources := getUseSdkV2Resources() | ||
for _, sdkV2Resource := range useSdkV2Resources { | ||
if resourceName == sdkV2Resource { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
// Helper function to check if a data source should use be in SDK V2 instead of plugin framework | ||
func shouldUseSdkV2DataSource(dataSourceName string) bool { | ||
sdkV2DataSources := getUseSdkV2DataSources() | ||
for _, sdkV2DataSource := range sdkV2DataSources { | ||
if dataSourceName == sdkV2DataSource { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
// getPluginFrameworkResourcesToRegister is a helper function to get the list of resources that are migrated away from sdkv2 to plugin framework | ||
func getPluginFrameworkResourcesToRegister() []func() resource.Resource { | ||
var resources []func() resource.Resource | ||
|
||
// Loop through the map and add resources if they're not specifically marked to use the SDK V2 | ||
for name, resourceFunc := range migratedResourceMap { | ||
if !shouldUseSdkV2Resource(name) { | ||
resources = append(resources, resourceFunc) | ||
} | ||
} | ||
|
||
return resources | ||
} | ||
|
||
// getPluginFrameworkDataSourcesToRegister is a helper function to get the list of data sources that are migrated away from sdkv2 to plugin framework | ||
func getPluginFrameworkDataSourcesToRegister() []func() datasource.DataSource { | ||
var dataSources []func() datasource.DataSource | ||
|
||
// Loop through the map and add data sources if they're not specifically marked to use the SDK V2 | ||
for name, dataSourceFunc := range migratedDataSourceMap { | ||
if !shouldUseSdkV2DataSource(name) { | ||
dataSources = append(dataSources, dataSourceFunc) | ||
} | ||
} | ||
|
||
return dataSources | ||
} | ||
|
||
// GetSdkV2ResourcesToRemove is a helper function to get the list of resources that are migrated away from sdkv2 to plugin framework | ||
func GetSdkV2ResourcesToRemove() []string { | ||
resourcesToRemove := []string{} | ||
for name := range migratedResourceMap { | ||
if !shouldUseSdkV2Resource(name) { | ||
resourcesToRemove = append(resourcesToRemove, name) | ||
} | ||
} | ||
return resourcesToRemove | ||
} | ||
|
||
// GetSdkV2DataSourcesToRemove is a helper function to get the list of data sources that are migrated away from sdkv2 to plugin framework | ||
func GetSdkV2DataSourcesToRemove() []string { | ||
dataSourcesToRemove := []string{} | ||
for name := range migratedDataSourceMap { | ||
if !shouldUseSdkV2DataSource(name) { | ||
dataSourcesToRemove = append(dataSourcesToRemove, name) | ||
} | ||
} | ||
return dataSourcesToRemove | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of hard-coding the names here, we can get them by calling the
Metadata()
method for each resource/data source.