-
Notifications
You must be signed in to change notification settings - Fork 156
/
main.go
64 lines (54 loc) · 2.17 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package main
import (
"context"
"flag"
"log"
"os"
"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server"
"github.com/hashicorp/terraform-plugin-mux/tf5muxserver"
"github.com/hashicorp/terraform-provider-tfe/internal/provider"
)
const (
tfeProviderName = "registry.terraform.io/hashicorp/tfe"
)
func main() {
ctx := context.Background()
// Remove any date and time prefix in log package function output to
// prevent duplicate timestamp and incorrect log level setting
log.SetFlags(log.Flags() &^ (log.Ldate | log.Ltime))
debugFlag := flag.Bool("debug", false, "Start provider in debug mode.")
flag.Parse()
var serveOpts []tf5server.ServeOpt
if *debugFlag {
serveOpts = append(serveOpts, tf5server.WithManagedDebug())
}
// terraform-plugin-mux here is used to combine multiple Terraform providers
// built using different SDK and frameworks in order to combine them into a
// single logical provider for Terraform to work with.
// - The classic provider relies on terraform-plugin-sdk, and has the bulk
// of the resources and data sources.
// - The "next" provider relies on the newer terraform-plugin-framework, and
// we expect to migrate resources and data sources to it over time.
// - The low-level provider relies on terraform-plugin-go to handle more
// complex behavior, and should only be used for functionality that is not
// available otherwise. We suspect the framework can supplant it, but have
// not proven that out yet.
nextProvider := providerserver.NewProtocol5(provider.NewFrameworkProvider())
classicProvider := provider.Provider().GRPCProvider
lowLevelProvider := provider.PluginProviderServer
mux, err := tf5muxserver.NewMuxServer(
ctx, nextProvider, classicProvider, lowLevelProvider,
)
if err != nil {
log.Printf("[ERROR] Could not setup a mux server using the internal providers: %v", err)
os.Exit(1)
}
err = tf5server.Serve(tfeProviderName, mux.ProviderServer, serveOpts...)
if err != nil {
log.Printf("[ERROR] Could not start serving the ProviderServer: %v", err)
os.Exit(1)
}
}