This repository has been archived by the owner on Jul 21, 2020. It is now read-only.
forked from scaleway/terraform-provider-scaleway
/
provider.go
88 lines (78 loc) · 2.73 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
79
80
81
82
83
84
85
86
87
88
package scaleway
import (
"sync"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)
var mu = sync.Mutex{}
// Provider returns a terraform.ResourceProvider.
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"access_key": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("SCALEWAY_ACCESS_KEY", nil),
Deprecated: "Use `token` instead.",
Description: "The API key for Scaleway API operations.",
},
"token": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"SCALEWAY_TOKEN",
"SCALEWAY_ACCESS_KEY",
}, nil),
Description: "The API key for Scaleway API operations.",
},
"organization": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("SCALEWAY_ORGANIZATION", nil),
Description: "The Organization ID (a.k.a. 'access key') for Scaleway API operations.",
},
"region": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("SCALEWAY_REGION", "par1"),
Description: "The Scaleway API region to use.",
},
},
ResourcesMap: map[string]*schema.Resource{
"scaleway_bucket": resourceScalewayBucket(),
"scaleway_user_data": resourceScalewayUserData(),
"scaleway_server": resourceScalewayServer(),
"scaleway_token": resourceScalewayToken(),
"scaleway_ssh_key": resourceScalewaySSHKey(),
"scaleway_ip": resourceScalewayIP(),
"scaleway_ip_reverse_dns": resourceScalewayIPReverseDNS(),
"scaleway_security_group": resourceScalewaySecurityGroup(),
"scaleway_security_group_rule": resourceScalewaySecurityGroupRule(),
"scaleway_volume": resourceScalewayVolume(),
"scaleway_volume_attachment": resourceScalewayVolumeAttachment(),
},
DataSourcesMap: map[string]*schema.Resource{
"scaleway_bootscript": dataSourceScalewayBootscript(),
"scaleway_image": dataSourceScalewayImage(),
"scaleway_security_group": dataSourceScalewaySecurityGroup(),
"scaleway_volume": dataSourceScalewayVolume(),
},
ConfigureFunc: providerConfigure,
}
}
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
apiKey := ""
if v, ok := d.Get("token").(string); ok {
apiKey = v
} else {
if v, ok := d.Get("access_key").(string); ok {
apiKey = v
}
}
config := Config{
Organization: d.Get("organization").(string),
APIKey: apiKey,
Region: d.Get("region").(string),
}
return config.Client()
}