-
Notifications
You must be signed in to change notification settings - Fork 1
/
provider.go
57 lines (50 loc) · 1.59 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
package njalla
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
// Provider for Njalla resources
func Provider() *schema.Provider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"api_token": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("NJALLA_API_TOKEN", nil),
Description: "Njalla API token",
},
},
ResourcesMap: map[string]*schema.Resource{
"njalla_record_txt": resourceRecordTXT(),
"njalla_record_a": resourceRecordA(),
"njalla_record_aaaa": resourceRecordAAAA(),
"njalla_record_mx": resourceRecordMX(),
"njalla_record_cname": resourceRecordCNAME(),
"njalla_record_caa": resourceRecordCAA(),
"njalla_record_ptr": resourceRecordPTR(),
"njalla_record_ns": resourceRecordNS(),
"njalla_record_tlsa": resourceRecordTLSA(),
"njalla_record_naptr": resourceRecordNAPTR(),
},
ConfigureContextFunc: providerConfigure,
}
}
func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
var diags diag.Diagnostics
if v, ok := d.GetOk("api_token"); ok {
token := v.(string)
config := Config{
Token: token,
}
return &config, diags
}
// Reaching here means the token wasn't given through the Terraform
// config NOR environment variable (`DefaultFunc`).
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: "Unable to setup Njalla provider",
Detail: "Missing required API token for provider Njalla",
})
return nil, diags
}