forked from aiven/terraform-provider-aiven
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprovider.go
More file actions
93 lines (85 loc) · 2.14 KB
/
Copy pathprovider.go
File metadata and controls
93 lines (85 loc) · 2.14 KB
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
91
92
93
package main
import (
"errors"
"github.com/hashicorp/terraform/helper/schema"
"github.com/jelmersnoeck/aiven"
)
// Provider returns the Terraform Aiven Provider configuration object.
func Provider() *schema.Provider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"email": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
Description: "Aiven email address",
Default: "",
},
"otp": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
Description: "Aiven One-Time password",
Default: "",
},
"password": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
Description: "Aiven password",
Default: "",
},
"api_token": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
Description: "Aiven Authentication Token",
Default: "",
},
},
ResourcesMap: map[string]*schema.Resource{
"aiven_project": resourceProject(),
"aiven_service": resourceService(),
"aiven_database": resourceDatabase(),
"aiven_service_user": resourceServiceUser(),
"aiven_kafka_topic": resourceKafkaTopic(),
"aiven_kafka_acls": resourceKafkaAcls(),
},
ConfigureFunc: func(d *schema.ResourceData) (interface{}, error) {
if d.Get("api_token") == "" && (d.Get("email") == "" || d.Get("password") == "") {
return nil, errors.New("Must provide an API Token or email and password")
}
if d.Get("api_token") != "" {
return aiven.NewTokenClient(
d.Get("api_token").(string),
)
}
return aiven.NewMFAUserClient(
d.Get("email").(string),
d.Get("otp").(string),
d.Get("password").(string),
)
},
}
}
func optionalString(d *schema.ResourceData, key string) string {
str, ok := d.Get(key).(string)
if !ok {
return ""
}
return str
}
func optionalStringPointer(d *schema.ResourceData, key string) *string {
str, ok := d.Get(key).(string)
if !ok {
return nil
}
return &str
}
func optionalIntPointer(d *schema.ResourceData, key string) *int {
val, ok := d.Get(key).(int)
if !ok {
return nil
}
return &val
}