Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmay-db committed Aug 26, 2024
1 parent 9e0ad79 commit feee667
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 22 deletions.
15 changes: 6 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,12 @@ provider_installation {
After installing the necessary software for building provider from sources, you should be able to run `make coverage` to run the tests and see the coverage.

## Package organization for Providers
We are migrating the resource from SDKv2 to Plugin Framework provider and hence both of them exist in the codebase. For uniform code convention, readability and development, they are defined under internal directory under root as:
- `common/provider`: This package contains the changes common to both the providers example provider factory and tests
- imports are declared as:
- `pluginframeworkprovider` "github.com/databricks/terraform-provider-databricks/internal/pluginframework/provider"
- `sdkv2provider` "github.com/databricks/terraform-provider-databricks/internal/sdkv2/provider"
- `sdkv2/provider`: This package contains the changes related to only sdkv2 provider and shouldn't depend on pluginframework provider
- `pluginframework/provider`: This package contains the changes related to only plugin framework provider and shouldn't depend on sdkv2

Note: Common dependencies for both providers will go into the internal/common/provider package.
We are migrating the resource from SDKv2 to Plugin Framework provider and hence both of them exist in the codebase. For uniform code convention, readability and development, they are organized in the `internal/providers` directory under root as follows:
- `common`: Contains the changes that `depends` on both internal/providers/sdkv2 and internal/providers/pluginfw packages, eg: `GetProviderServer`.
- `internal`: Contains the changes `used by` both internal/providers/sdkv2 and internal/providers/pluginfw packages, eg: `GetProviderName`.
- `pluginfw`: Contains the changes specific to Plugin Framework. This package shouldn't depend on sdkv2 or common.
- `sdkv2`: Contains the changes specific to SDKv2. This package shouldn't depend on pluginfw or common.


## Debugging

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package common contains the changes that depends on both internal/providers/sdkv2 and internal/providers/pluginfw packages
package common

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package common
package tests

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package common
package tests

import (
"context"
Expand Down
10 changes: 10 additions & 0 deletions internal/providers/internal/provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Package internal contains the changes used by both internal/providers/sdkv2 and internal/providers/pluginfw packages.
//
// Note: This is different from internal/providers/common which contains the changes that *depends* on both:
// internal/providers/sdkv2 and internal/providers/pluginfw packages. Whereas, internal/providers/internal package contains
// the changes *used* by both internal/providers/sdkv2 and internal/providers/pluginfw packages.
package internal

func GetProviderName() string {
return "databricks-tf-provider"
}
10 changes: 5 additions & 5 deletions internal/providers/pluginfw/provider.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Package pluginfw contains the changes specific to the plugin framework
//
// Note: This shouldn't depend on internal/providers/sdkv2 or internal/providers/common
package pluginfw

import (
Expand All @@ -12,6 +15,7 @@ import (
"github.com/databricks/databricks-sdk-go/config"
"github.com/databricks/terraform-provider-databricks/commands"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/databricks/terraform-provider-databricks/internal/providers/internal"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/diag"
Expand All @@ -23,10 +27,6 @@ import (
"github.com/hashicorp/terraform-plugin-log/tflog"
)

func GetProviderName() string {
return "databricks-tf-provider"
}

func GetDatabricksProviderPluginFramework() provider.Provider {
p := &DatabricksProviderPluginFramework{}
return p
Expand All @@ -50,7 +50,7 @@ func (p *DatabricksProviderPluginFramework) Schema(ctx context.Context, req prov
}

func (p *DatabricksProviderPluginFramework) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) {
resp.TypeName = GetProviderName()
resp.TypeName = internal.GetProviderName()
resp.Version = common.Version()
}

Expand Down
7 changes: 5 additions & 2 deletions internal/providers/sdkv2/provider.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Package sdkv2 contains the changes specific to the SDKv2
//
// Note: This package shouldn't depend on internal/providers/pluginfw or internal/providers/common
package sdkv2

import (
Expand Down Expand Up @@ -26,7 +29,7 @@ import (
"github.com/databricks/terraform-provider-databricks/commands"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/databricks/terraform-provider-databricks/dashboards"
"github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw"
"github.com/databricks/terraform-provider-databricks/internal/providers/internal"
"github.com/databricks/terraform-provider-databricks/jobs"
"github.com/databricks/terraform-provider-databricks/logger"
"github.com/databricks/terraform-provider-databricks/mlflow"
Expand All @@ -51,7 +54,7 @@ import (
func init() {
// IMPORTANT: this line cannot be changed, because it's used for
// internal purposes at Databricks.
useragent.WithProduct(pluginfw.GetProviderName(), common.Version())
useragent.WithProduct(internal.GetProviderName(), common.Version())

userAgentExtraEnv := os.Getenv("DATABRICKS_USER_AGENT_EXTRA")
out, err := ParseUserAgentExtra(userAgentExtraEnv)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sdkv2
package tests

import (
"fmt"
Expand All @@ -12,6 +12,7 @@ import (
"strings"
"testing"

"github.com/databricks/terraform-provider-databricks/internal/providers/sdkv2"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -143,7 +144,7 @@ func TestCoverageReport(t *testing.T) {
files, err := recursiveChildren("..")
assert.NoError(t, err)

p := DatabricksProvider()
p := sdkv2.DatabricksProvider()
var cr CoverageReport
var longestResourceName, longestFieldName int

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sdkv2
package tests

import (
"fmt"
Expand All @@ -11,6 +11,7 @@ import (
"testing"
"text/template"

"github.com/databricks/terraform-provider-databricks/internal/providers/sdkv2"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -233,7 +234,7 @@ func TestGenerateTestCodeStubs(t *testing.T) {
t.Logf("Got %d unit tests in total. %v",
len(funcs), resourceTestStub{})
t.Skip()
p := DatabricksProvider()
p := sdkv2.DatabricksProvider()
for name, resource := range p.ResourcesMap {
if name != "databricks_group_instance_profile" {
continue
Expand Down

0 comments on commit feee667

Please sign in to comment.