This repository has been archived by the owner on Jun 18, 2024. It is now read-only.
forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider.go
66 lines (55 loc) · 1.6 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
package atlas
import (
"github.com/hashicorp/atlas-go/v1"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)
const (
// defaultAtlasServer is the default endpoint for Atlas if
// none is specified.
defaultAtlasServer = "https://atlas.hashicorp.com"
)
// Provider returns a terraform.ResourceProvider.
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"token": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("ATLAS_TOKEN", nil),
Description: descriptions["token"],
},
"address": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("ATLAS_ADDRESS", defaultAtlasServer),
Description: descriptions["address"],
},
},
ResourcesMap: map[string]*schema.Resource{
"atlas_artifact": resourceArtifact(),
},
ConfigureFunc: providerConfigure,
}
}
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
var err error
client := atlas.DefaultClient()
if v := d.Get("address").(string); v != "" {
client, err = atlas.NewClient(v)
if err != nil {
return nil, err
}
}
client.Token = d.Get("token").(string)
return client, nil
}
var descriptions map[string]string
func init() {
descriptions = map[string]string{
"address": "The address of the Atlas server. If blank, the public\n" +
"server at atlas.hashicorp.com will be used.",
"token": "The access token for reading artifacts. This is required\n" +
"if reading private artifacts.",
}
}