-
Notifications
You must be signed in to change notification settings - Fork 132
/
provider.go
90 lines (84 loc) · 4.21 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
package fastly
import (
"context"
gofastly "github.com/fastly/go-fastly/v6/fastly"
"github.com/fastly/terraform-provider-fastly/version"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
const TerraformProviderProductUserAgent = "terraform-provider-fastly"
// Provider returns a *schema.Provider.
func Provider() *schema.Provider {
provider := &schema.Provider{
Schema: map[string]*schema.Schema{
"api_key": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("FASTLY_API_KEY", nil),
Description: "Fastly API Key from https://app.fastly.com/#account",
},
"base_url": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("FASTLY_API_URL", gofastly.DefaultEndpoint),
Description: "Fastly API URL",
},
"no_auth": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Set this to `true` if you only need data source that does not require authentication such as `fastly_ip_ranges`",
},
"force_http2": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Set this to `true` to disable HTTP/1.x fallback mechanism that the underlying Go library will attempt upon connection to `api.fastly.com:443` by default. This may slightly improve the provider's performance and reduce unnecessary TLS handshakes. Default: `false`",
},
},
DataSourcesMap: map[string]*schema.Resource{
"fastly_datacenters": dataSourceFastlyDatacenters(),
"fastly_ip_ranges": dataSourceFastlyIPRanges(),
"fastly_tls_activation": dataSourceFastlyTLSActivation(),
"fastly_tls_activation_ids": dataSourceFastlyTLSActivationIds(),
"fastly_tls_certificate": dataSourceFastlyTLSCertificate(),
"fastly_tls_certificate_ids": dataSourceFastlyTLSCertificateIDs(),
"fastly_tls_configuration": dataSourceFastlyTLSConfiguration(),
"fastly_tls_configuration_ids": dataSourceFastlyTLSConfigurationIDs(),
"fastly_tls_domain": dataSourceFastlyTLSDomain(),
"fastly_tls_platform_certificate": dataSourceFastlyTLSPlatformCertificate(),
"fastly_tls_platform_certificate_ids": dataSourceFastlyTLSPlatformCertificateIDs(),
"fastly_tls_private_key": dataSourceFastlyTLSPrivateKey(),
"fastly_tls_private_key_ids": dataSourceFastlyTLSPrivateKeyIDs(),
"fastly_tls_subscription": dataSourceFastlyTLSSubscription(),
"fastly_tls_subscription_ids": dataSourceFastlyTLSSubscriptionIDs(),
"fastly_waf_rules": dataSourceFastlyWAFRules(),
},
ResourcesMap: map[string]*schema.Resource{
"fastly_service_vcl": resourceServiceVCL(),
"fastly_service_compute": resourceServiceCompute(),
"fastly_service_acl_entries": resourceServiceAclEntries(),
"fastly_service_dictionary_items": resourceServiceDictionaryItems(),
"fastly_service_dynamic_snippet_content": resourceServiceDynamicSnippetContent(),
"fastly_service_waf_configuration": resourceServiceWAFConfiguration(),
"fastly_tls_activation": resourceFastlyTLSActivation(),
"fastly_tls_certificate": resourceFastlyTLSCertificate(),
"fastly_tls_private_key": resourceFastlyTLSPrivateKey(),
"fastly_tls_platform_certificate": resourceFastlyTLSPlatformCertificate(),
"fastly_tls_subscription": resourceFastlyTLSSubscription(),
"fastly_tls_subscription_validation": resourceFastlyTLSSubscriptionValidation(),
"fastly_user": resourceUser(),
},
}
provider.ConfigureContextFunc = func(_ context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
config := Config{
ApiKey: d.Get("api_key").(string),
BaseURL: d.Get("base_url").(string),
NoAuth: d.Get("no_auth").(bool),
ForceHttp2: d.Get("force_http2").(bool),
UserAgent: provider.UserAgent(TerraformProviderProductUserAgent, version.ProviderVersion),
}
return config.Client()
}
return provider
}