forked from paybyphone/terraform-provider-phpipam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider.go
78 lines (70 loc) · 2.23 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
package phpipam
import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)
// Provider returns a terraform.ResourceProvider.
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"app_id": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "",
Description: descriptions["app_id"],
},
"endpoint": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "",
Description: descriptions["endpoint"],
},
"password": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "",
Description: descriptions["password"],
},
"username": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "",
Description: descriptions["username"],
},
},
ResourcesMap: map[string]*schema.Resource{
"phpipam_address": resourcePHPIPAMAddress(),
"phpipam_section": resourcePHPIPAMSection(),
"phpipam_subnet": resourcePHPIPAMSubnet(),
"phpipam_vlan": resourcePHPIPAMVLAN(),
},
DataSourcesMap: map[string]*schema.Resource{
"phpipam_address": dataSourcePHPIPAMAddress(),
"phpipam_addresses": dataSourcePHPIPAMAddresses(),
"phpipam_first_free_address": dataSourcePHPIPAMFirstFreeAddress(),
"phpipam_section": dataSourcePHPIPAMSection(),
"phpipam_subnet": dataSourcePHPIPAMSubnet(),
"phpipam_subnets": dataSourcePHPIPAMSubnets(),
"phpipam_vlan": dataSourcePHPIPAMVLAN(),
},
ConfigureFunc: providerConfigure,
}
}
var descriptions map[string]string
func init() {
descriptions = map[string]string{
"app_id": "The application ID required for API requests",
"endpoint": "The full URL (plus path) to the API endpoint",
"password": "The password of the PHPIPAM account",
"username": "The username of the PHPIPAM account",
}
}
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config := Config{
AppID: d.Get("app_id").(string),
Endpoint: d.Get("endpoint").(string),
Password: d.Get("password").(string),
Username: d.Get("username").(string),
}
return config.Client()
}