Skip to content

Commit

Permalink
[Internal] Added support to use protocol version 6 provider server fo…
Browse files Browse the repository at this point in the history
…r SDK plugin (#3862)

## Changes
<!-- Summary of your changes that are easy to understand -->
Merging
#3719 in
main branch before release.

## Tests
<!-- 
How is this tested? Please see the checklist below and also describe any
other relevant tests
-->
Nightly tests are running...
- [ ] `make test` run locally
- [ ] relevant change in `docs/` folder
- [ ] covered with integration tests in `internal/acceptance`
- [ ] relevant acceptance tests are passing
- [ ] using Go SDK
  • Loading branch information
tanmay-db authored Aug 16, 2024
1 parent e6e5d55 commit 2855ef5
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 @@ -8,7 +8,9 @@ require (
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/hcl v1.0.0
github.com/hashicorp/hcl/v2 v2.21.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.15.0
Expand Down Expand Up @@ -47,7 +49,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 @@ -134,6 +134,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 2855ef5

Please sign in to comment.