Skip to content

Commit

Permalink
introduced new protocol v6 server and muxing server to old provider
Browse files Browse the repository at this point in the history
  • Loading branch information
benPearce1 committed Jul 2, 2024
1 parent 33e7960 commit a968af9
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ jobs:
fetch-depth: 0
- uses: actions/setup-go@v3
with:
go-version: '1.21'
go-version: '1.22'
- run: go build ./...
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-go@v3
with:
go-version: '1.21'
go-version: '1.22'
- uses: crazy-max/ghaction-import-gpg@v5
id: import_gpg
with:
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ require (
github.com/gruntwork-io/terratest v0.41.11
github.com/hashicorp/go-cty v1.4.1-0.20200723130312-85980079f637
github.com/hashicorp/terraform-plugin-docs v0.13.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
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea
Expand Down Expand Up @@ -83,7 +86,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
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,14 @@ github.com/hashicorp/terraform-json v0.22.1 h1:xft84GZR0QzjPVWs4lRUwvTcPnegqlyS7
github.com/hashicorp/terraform-json v0.22.1/go.mod h1:JbWSQCLFSXFFhg42T7l9iJwdGXBYV8fmmD6o/ML4p3A=
github.com/hashicorp/terraform-plugin-docs v0.13.0 h1:6e+VIWsVGb6jYJewfzq2ok2smPzZrt1Wlm9koLeKazY=
github.com/hashicorp/terraform-plugin-docs v0.13.0/go.mod h1:W0oCmHAjIlTHBbvtppWHe8fLfZ2BznQbuv8+UD8OucQ=
github.com/hashicorp/terraform-plugin-framework v1.9.0 h1:caLcDoxiRucNi2hk8+j3kJwkKfvHznubyFsJMWfZqKU=
github.com/hashicorp/terraform-plugin-framework v1.9.0/go.mod h1:qBXLDn69kM97NNVi/MQ9qgd1uWWsVftGSnygYG1tImM=
github.com/hashicorp/terraform-plugin-go v0.23.0 h1:AALVuU1gD1kPb48aPQUjug9Ir/125t+AAurhqphJ2Co=
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
38 changes: 32 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package main

import (
"context"
"flag"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy"
"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"
"github.com/hashicorp/terraform-plugin-framework/providerserver"
"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"
"log"
)

//go:generate go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs
Expand All @@ -13,14 +19,34 @@ func main() {
flag.BoolVar(&debugMode, "debug", false, "set to true to run the provider with support for debuggers like delve")
flag.Parse()

opts := &plugin.ServeOpts{
ProviderFunc: octopusdeploy.Provider,
ctx := context.Background()

upgradedSdkServer, err := tf5to6server.UpgradeServer(
ctx,
octopusdeploy.Provider().GRPCProvider)
if err != nil {
log.Fatal(err)
}

providers := []func() tfprotov6.ProviderServer{
providerserver.NewProtocol6(octopusdeploy.NewOctopusDeployProviderV6()),
func() tfprotov6.ProviderServer {
return upgradedSdkServer
},
}

muxServer, err := tf6muxserver.NewMuxServer(ctx, providers...)

opts := []tf6server.ServeOpt{}

var providerName = "registry.terraform.io/OctopusDeployLabs/octopusdeploy"
if debugMode {
opts.Debug = true
opts.ProviderAddr = "octopus.com/com/octopusdeploy"
opts = append(opts, tf6server.WithManagedDebug())
providerName = "octopus.com/com/octopusdeploy"
}

plugin.Serve(opts)
err = tf6server.Serve(providerName, muxServer.ProviderServer, opts...)
if err != nil {
log.Fatal(err)
}
}
63 changes: 63 additions & 0 deletions octopusdeploy/providerv6.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package octopusdeploy

import (
"context"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/types"

"github.com/hashicorp/terraform-plugin-framework/provider"
)

type octopusDeployProviderV6 struct {
Address types.String `tfsdk:"address"`
ApiKey types.String `tfsdk:"api_key"`
SpaceID types.String `tfsdk:"space_id"`
}

var _ provider.Provider = (*octopusDeployProviderV6)(nil)
var _ provider.ProviderWithMetaSchema = (*octopusDeployProviderV6)(nil)

func NewOctopusDeployProviderV6() *octopusDeployProviderV6 {
return &octopusDeployProviderV6{}
}

func (p *octopusDeployProviderV6) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) {
}

func (p *octopusDeployProviderV6) MetaSchema(ctx context.Context, request provider.MetaSchemaRequest, response *provider.MetaSchemaResponse) {

}

func (p *octopusDeployProviderV6) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
}

func (p *octopusDeployProviderV6) DataSources(ctx context.Context) []func() datasource.DataSource {
return []func() datasource.DataSource{}
}

func (p *octopusDeployProviderV6) Resources(ctx context.Context) []func() resource.Resource {
return []func() resource.Resource{}
}

func (p *octopusDeployProviderV6) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"address": schema.StringAttribute{
Optional: false,
Required: true,
Description: "The endpoint of the Octopus REST API",
},
"api_key": schema.StringAttribute{
Optional: false,
Required: true,
Description: "The API key to use with the Octopus REST API",
},
"space_id": schema.StringAttribute{
Optional: true,
Description: "The space ID to target",
},
},
}
}

0 comments on commit a968af9

Please sign in to comment.