Skip to content

Commit

Permalink
[Feature] Added support to use protocol version 6 provider server for…
Browse files Browse the repository at this point in the history
… SDK plugin (#3719)

## Changes
<!-- Summary of your changes that are easy to understand -->
Upgrade SDK plugin to use protocol version 6 as this will be used
further for introducing plugin framework. We need to mux them (i.e.
support both sdkv2 and plugin framework) until all resources are
migrated to plugin framework.

Reference for PR on main branch:
#3714,
this PR against the main branch will be used to get the binary for
testing with data team.

## Tests
<!-- 
How is this tested? Please see the checklist below and also describe any
other relevant tests
-->
All Unit and Integration test passed.
- [x] `make test` run locally
- [ ] relevant change in `docs/` folder
- [ ] covered with integration tests in `internal/acceptance`
- [x] relevant acceptance tests are passing
- [ ] using Go SDK
  • Loading branch information
tanmay-db authored Jul 17, 2024
1 parent 1f88025 commit 3f3ad23
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ require (
github.com/hashicorp/hcl v1.0.0
github.com/hashicorp/hcl/v2 v2.21.0
github.com/hashicorp/terraform-plugin-framework v1.9.0
github.com/hashicorp/terraform-plugin-go v0.23.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-mux v0.16.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0
github.com/stretchr/testify v1.9.0
github.com/zclconf/go-cty v1.14.4
Expand Down Expand Up @@ -49,7 +51,6 @@ require (
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-exec v0.21.0 // indirect
github.com/hashicorp/terraform-json v0.22.1 // indirect
github.com/hashicorp/terraform-plugin-go v0.23.0 // indirect
github.com/hashicorp/terraform-registry-address v0.2.3 // indirect
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ github.com/hashicorp/terraform-plugin-go v0.23.0 h1:AALVuU1gD1kPb48aPQUjug9Ir/12
github.com/hashicorp/terraform-plugin-go v0.23.0/go.mod h1:1E3Cr9h2vMlahWMbsSEcNrOCxovCZhOOIXjFHbjc/lQ=
github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=
github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow=
github.com/hashicorp/terraform-plugin-mux v0.16.0 h1:RCzXHGDYwUwwqfYYWJKBFaS3fQsWn/ZECEiW7p2023I=
github.com/hashicorp/terraform-plugin-mux v0.16.0/go.mod h1:PF79mAsPc8CpusXPfEVa4X8PtkB+ngWoiUClMrNZlYo=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0 h1:kJiWGx2kiQVo97Y5IOGR4EMcZ8DtMswHhUuFibsCQQE=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0/go.mod h1:sl/UoabMc37HA6ICVMmGO+/0wofkVIRxf+BMb/dnoIg=
github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI=
Expand Down
58 changes: 45 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
package main

import (
"context"
"fmt"
"log"
"os"

"github.com/databricks/terraform-provider-databricks/common"
"github.com/databricks/terraform-provider-databricks/exporter"
"github.com/databricks/terraform-provider-databricks/provider"
"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server"
"github.com/hashicorp/terraform-plugin-mux/tf5to6server"
"github.com/hashicorp/terraform-plugin-mux/tf6muxserver"
)

const startMessageFormat = `Databricks Terraform Provider
Version %s
https://registry.terraform.io/providers/databricks/databricks/latest/docs
`

func main() {
log.SetFlags(0)
if len(os.Args) > 1 && os.Args[1] == "version" {
Expand All @@ -24,20 +36,40 @@ func main() {
}
return
}
var debug bool
if len(os.Args) > 1 && os.Args[1] == "debug" {
debug = true
}
log.Printf(`Databricks Terraform Provider

Version %s
log.Printf(startMessageFormat, common.Version())

https://registry.terraform.io/providers/databricks/databricks/latest/docs
sdkPluginProvider := provider.DatabricksProvider()

upgradedSdkPluginProvider, err := tf5to6server.UpgradeServer(
context.Background(),
sdkPluginProvider.GRPCProvider,
)
if err != nil {
log.Fatal(err)
}

`, common.Version())
plugin.Serve(&plugin.ServeOpts{
ProviderFunc: provider.DatabricksProvider,
ProviderAddr: "registry.terraform.io/databricks/databricks",
Debug: debug,
ctx := context.Background()
muxServer, err := tf6muxserver.NewMuxServer(ctx, func() tfprotov6.ProviderServer {
return upgradedSdkPluginProvider
})

if err != nil {
log.Fatal(err)
}

var serveOpts []tf6server.ServeOpt
if len(os.Args) > 1 && os.Args[1] == "debug" { // debug mode
serveOpts = append(serveOpts, tf6server.WithManagedDebug())
}

err = tf6server.Serve(
"registry.terraform.io/databricks/databricks",
muxServer.ProviderServer,
serveOpts...,
)

if err != nil {
log.Fatal(err)
}
}

0 comments on commit 3f3ad23

Please sign in to comment.