-
Notifications
You must be signed in to change notification settings - Fork 14
/
provider.go
48 lines (42 loc) · 1.36 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
package main
import (
"os"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
contentful "github.com/tolgaakyuz/contentful-go"
)
// Provider does shit
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"cma_token": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("CONTENTFUL_MANAGEMENT_TOKEN", nil),
Description: "The Contentful Management API token",
},
"organization_id": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("CONTENTFUL_ORGANIZATION_ID", nil),
Description: "The organization ID",
},
},
ResourcesMap: map[string]*schema.Resource{
"contentful_space": resourceContentfulSpace(),
"contentful_contenttype": resourceContentfulContentType(),
"contentful_apikey": resourceContentfulAPIKey(),
"contentful_webhook": resourceContentfulWebhook(),
"contentful_locale": resourceContentfulLocale(),
},
ConfigureFunc: providerConfigure,
}
}
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
cma := contentful.NewCMA(d.Get("cma_token").(string))
cma.SetOrganization(d.Get("organization_id").(string))
if os.Getenv("TF_LOG") != "" {
cma.Debug = true
}
return cma, nil
}