-
Notifications
You must be signed in to change notification settings - Fork 5
/
provider.go
92 lines (84 loc) · 2.61 KB
/
provider.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package spinnaker
import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/spf13/pflag"
gate "github.com/spinnaker/spin/cmd/gateclient"
)
func Provider() *schema.Provider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"server": {
Type: schema.TypeString,
Description: "URL for Spinnaker Gate",
Deprecated: "use `gate_endpoint` instead",
Optional: true,
ConflictsWith: []string{"gate_endpoint"},
},
"gate_endpoint": {
Type: schema.TypeString,
Optional: true,
Description: "URL for Spinnaker Gate",
DefaultFunc: schema.EnvDefaultFunc("GATE_ENDPOINT", nil),
},
"config": {
Type: schema.TypeString,
Optional: true,
Description: "Path to Gate config file",
DefaultFunc: schema.EnvDefaultFunc("SPINNAKER_CONFIG_PATH", nil),
},
"ignore_cert_errors": {
Type: schema.TypeBool,
Optional: true,
Description: "Ignore certificate errors from Gate",
Default: false,
},
"default_headers": {
Type: schema.TypeString,
Optional: true,
Description: "Headers to be passed to the gate endpoint by the client on each request",
Default: "",
},
},
ResourcesMap: map[string]*schema.Resource{
"spinnaker_application": resourceSpinnakerApplication(),
"spinnaker_pipeline": resourcePipeline(),
"spinnaker_pipeline_template": resourcePipelineTemplate(),
"spinnaker_project": resourceSpinnakerProject(),
},
DataSourcesMap: map[string]*schema.Resource{
"spinnaker_application": datasourceApplication(),
"spinnaker_pipeline": datasourcePipeline(),
"spinnaker_project": datasourceProject(),
},
ConfigureFunc: providerConfigureFunc,
}
}
type gateConfig struct {
client *gate.GatewayClient
}
func providerConfigureFunc(data *schema.ResourceData) (interface{}, error) {
var gateEndpoint string
if v, deprecated := data.Get("server").(string); deprecated {
gateEndpoint = v
} else {
gateEndpoint = data.Get("gate_endpoint").(string)
}
config := data.Get("config").(string)
ignoreCertErrors := data.Get("ignore_cert_errors").(bool)
defaultHeaders := data.Get("default_headers").(string)
flags := pflag.NewFlagSet("default", 1)
flags.String("gate-endpoint", gateEndpoint, "")
flags.Bool("quiet", false, "")
flags.Bool("insecure", ignoreCertErrors, "")
flags.Bool("no-color", true, "")
flags.String("output", "", "")
flags.String("config", config, "")
flags.String("default-headers", defaultHeaders, "")
client, err := gate.NewGateClient(flags)
if err != nil {
return nil, err
}
return gateConfig{
client: client,
}, nil
}