-
Notifications
You must be signed in to change notification settings - Fork 132
/
provider.go
61 lines (56 loc) · 2.16 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
package fastly
import (
gofastly "github.com/fastly/go-fastly/fastly"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)
// Provider returns a terraform.ResourceProvider.
func Provider() terraform.ResourceProvider {
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",
},
},
DataSourcesMap: map[string]*schema.Resource{
"fastly_ip_ranges": dataSourceFastlyIPRanges(),
"fastly_waf_rules": dataSourceFastlyWAFRules(),
},
ResourcesMap: map[string]*schema.Resource{
"fastly_service_v1": resourceServiceV1(),
"fastly_service_compute": resourceServiceComputeV1(),
"fastly_service_acl_entries_v1": resourceServiceAclEntriesV1(),
"fastly_service_dictionary_items_v1": resourceServiceDictionaryItemsV1(),
"fastly_service_dynamic_snippet_content_v1": resourceServiceDynamicSnippetContentV1(),
"fastly_user_v1": resourceUserV1(),
"fastly_service_waf_configuration": resourceServiceWAFConfigurationV1(),
},
}
provider.ConfigureFunc = func(d *schema.ResourceData) (interface{}, error) {
terraformVersion := provider.TerraformVersion
if terraformVersion == "" {
// Terraform 0.12 introduced this field to the protocol
// We can therefore assume that if it's missing it's 0.10 or 0.11
terraformVersion = "0.11+compatible"
}
return providerConfigure(d, terraformVersion)
}
return provider
}
func providerConfigure(d *schema.ResourceData, terraformVersion string) (interface{}, error) {
config := Config{
ApiKey: d.Get("api_key").(string),
BaseURL: d.Get("base_url").(string),
terraformVersion: terraformVersion,
}
return config.Client()
}