This repository has been archived by the owner on Jul 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
provider.go
88 lines (77 loc) · 3.05 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
package azureopenshift
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/rh-mobb/terraform-provider-azureopenshift/azureopenshift/auth"
"github.com/rh-mobb/terraform-provider-azureopenshift/azureopenshift/clients"
)
// Provider -
func Provider() *schema.Provider {
p := &schema.Provider{
Schema: map[string]*schema.Schema{
"subscription_id": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("ARM_SUBSCRIPTION_ID", ""),
Description: "The Subscription ID which should be used.",
ValidateFunc: validation.StringIsNotEmpty,
},
"client_id": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("ARM_CLIENT_ID", ""),
Description: "The Client ID which should be used.",
},
"client_secret": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("ARM_CLIENT_SECRET", ""),
Description: "The Client Secret which should be used. For use When authenticating as a Service Principal using a Client Secret.",
},
"tenant_id": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("ARM_TENANT_ID", ""),
Description: "The Tenant ID which should be used.",
},
"environment": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("ARM_ENVIRONMENT", "public"),
// TODO: remove China support for now until ARO supports it.
// Description: "The Cloud Environment which should be used. Possible values are public, usgovernment, and china. Defaults to public.",
// ValidateFunc: validation.StringInSlice([]string{auth.AzurePublicString, auth.AzureUSGovernmentString, auth.AzureChinaString}, false),
Description: "The Cloud Environment which should be used. Possible values are public and usgovernment. Defaults to public.",
ValidateFunc: validation.StringInSlice([]string{auth.AzurePublicString, auth.AzureUSGovernmentString}, false),
},
},
ResourcesMap: map[string]*schema.Resource{
"azureopenshift_redhatopenshift_cluster": resourceOpenShiftCluster(),
},
DataSourcesMap: map[string]*schema.Resource{},
}
p.ConfigureContextFunc = providerConfigure(p)
return p
}
func providerConfigure(p *schema.Provider) schema.ConfigureContextFunc {
return func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
stopCtx, ok := schema.StopContext(ctx)
if !ok {
stopCtx = ctx
}
config := auth.Config{
SubscriptionId: d.Get("subscription_id").(string),
TenantId: d.Get("tenant_id").(string),
ClientSecret: d.Get("client_secret").(string),
ClientId: d.Get("client_id").(string),
Environment: d.Get("environment").(string),
}
client, err := clients.NewClient(stopCtx, config)
if err != nil {
return nil, diag.Errorf("building AzureRM Client: %s", err)
}
return client, nil
}
}