mirror of
https://github.com/hashicorp/terraform-provider-kubernetes.git
synced 2025-12-18 23:06:07 -05:00
Some checks failed
build / Detect Go toolchain version (push) Has been cancelled
build / Parse version file (push) Has been cancelled
Check examples / check (1.10.5) (push) Has been cancelled
Check examples / check (1.11.4) (push) Has been cancelled
Check examples / check (1.12.1) (push) Has been cancelled
Check examples / check (1.6.6) (push) Has been cancelled
Check examples / check (1.7.5) (push) Has been cancelled
Check examples / check (1.8.5) (push) Has been cancelled
Check examples / check (1.9.8) (push) Has been cancelled
Essential checkers and linters / checkers-and-linters (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
HashiCorp Copywrite / copywrite (push) Has been cancelled
Unit Tests / unit_test (push) Has been cancelled
build / generate-metadata-file (push) Has been cancelled
build / upload-terraform-registry-manifest-artifact (push) Has been cancelled
build / Go darwin 386 build (push) Has been cancelled
build / Go freebsd 386 build (push) Has been cancelled
build / Go linux 386 build (push) Has been cancelled
build / Go windows 386 build (push) Has been cancelled
build / Go darwin amd64 build (push) Has been cancelled
build / Go freebsd amd64 build (push) Has been cancelled
build / Go linux amd64 build (push) Has been cancelled
build / Go windows amd64 build (push) Has been cancelled
build / Go freebsd arm build (push) Has been cancelled
build / Go linux arm build (push) Has been cancelled
build / Go darwin arm64 build (push) Has been cancelled
build / Go linux arm64 build (push) Has been cancelled
build / What's next? (push) Has been cancelled
* Add kubernetes_validating_admission_policy resource * Update to use admissionregistration/v1 * Add changelog * tidy up validating_admission_policy resource * add copy-write headers, and tidy up resource * Fix identity schema * Fix md * Update dep * Tidy mod/sum
95 lines
2.7 KiB
Go
95 lines
2.7 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/hashicorp/go-plugin"
|
|
"github.com/hashicorp/terraform-exec/tfexec"
|
|
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
|
|
"github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server"
|
|
"github.com/hashicorp/terraform-provider-kubernetes/internal/mux"
|
|
)
|
|
|
|
const (
|
|
providerName = "registry.terraform.io/hashicorp/kubernetes"
|
|
|
|
Version = "dev"
|
|
)
|
|
|
|
// Generate docs for website
|
|
//go:generate go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs
|
|
|
|
func main() {
|
|
debugFlag := flag.Bool("debug", false, "Start provider in stand-alone debug mode.")
|
|
flag.Parse()
|
|
|
|
ctx := context.Background()
|
|
muxer, err := mux.MuxServer(ctx, Version)
|
|
if err != nil {
|
|
log.Println(err.Error())
|
|
os.Exit(1)
|
|
}
|
|
|
|
opts := []tf6server.ServeOpt{}
|
|
if *debugFlag {
|
|
reattachConfigCh := make(chan *plugin.ReattachConfig)
|
|
go func() {
|
|
reattachConfig, err := waitForReattachConfig(reattachConfigCh)
|
|
if err != nil {
|
|
fmt.Printf("Error getting reattach config: %s\n", err)
|
|
return
|
|
}
|
|
printReattachConfig(reattachConfig)
|
|
}()
|
|
opts = append(opts, tf6server.WithDebug(ctx, reattachConfigCh, nil))
|
|
}
|
|
|
|
tf6server.Serve(providerName, func() tfprotov6.ProviderServer { return muxer }, opts...)
|
|
}
|
|
|
|
// convertReattachConfig converts plugin.ReattachConfig to tfexec.ReattachConfig
|
|
func convertReattachConfig(reattachConfig *plugin.ReattachConfig) tfexec.ReattachConfig {
|
|
return tfexec.ReattachConfig{
|
|
Protocol: string(reattachConfig.Protocol),
|
|
ProtocolVersion: reattachConfig.ProtocolVersion,
|
|
Pid: reattachConfig.Pid,
|
|
Test: true,
|
|
Addr: tfexec.ReattachConfigAddr{
|
|
Network: reattachConfig.Addr.Network(),
|
|
String: reattachConfig.Addr.String(),
|
|
},
|
|
}
|
|
}
|
|
|
|
// printReattachConfig prints the line the user needs to copy and paste
|
|
// to set the TF_REATTACH_PROVIDERS variable
|
|
func printReattachConfig(config *plugin.ReattachConfig) {
|
|
reattachStr, err := json.Marshal(map[string]tfexec.ReattachConfig{
|
|
"kubernetes": convertReattachConfig(config),
|
|
})
|
|
if err != nil {
|
|
fmt.Printf("Error building reattach string: %s", err)
|
|
return
|
|
}
|
|
fmt.Printf("# Provider server started\nexport TF_REATTACH_PROVIDERS='%s'\n", string(reattachStr))
|
|
}
|
|
|
|
// waitForReattachConfig blocks until a ReattachConfig is recieved on the
|
|
// supplied channel or times out after 2 seconds.
|
|
func waitForReattachConfig(ch chan *plugin.ReattachConfig) (*plugin.ReattachConfig, error) {
|
|
select {
|
|
case config := <-ch:
|
|
return config, nil
|
|
case <-time.After(2 * time.Second):
|
|
return nil, fmt.Errorf("timeout while waiting for reattach configuration")
|
|
}
|
|
}
|