-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathresource_acl_bootstrap.go
121 lines (105 loc) · 3.32 KB
/
resource_acl_bootstrap.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package main
import (
"github.com/cenkalti/backoff/v4"
"github.com/hashicorp/terraform/helper/schema"
"log"
)
func aclBootstrap() *schema.Resource {
return &schema.Resource{
Create: bootstrapACLs,
Read: noop,
Update: noop,
Delete: forget,
Schema: map[string]*schema.Schema{
"address": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("NOMAD_ADDR", "http://127.0.0.1:4646"),
Description: "URL of the root of the target Nomad agent.",
},
"ca_file": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("NOMAD_CACERT", ""),
Description: "A path to a PEM-encoded certificate authority used to verify the remote agent's certificate.",
},
"cert_file": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("NOMAD_CLIENT_CERT", ""),
Description: "A path to a PEM-encoded certificate provided to the remote agent; requires use of key_file.",
},
"key_file": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("NOMAD_CLIENT_KEY", ""),
Description: "A path to a PEM-encoded private key, required if cert_file is specified.",
},
"tls_server_name": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("NOMAD_CLIENT_KEY", ""),
Description: "Specifies an optional string used to set the SNI host when connecting to Vault via TLS.",
},
"accessor_id": {
Description: "Nomad-generated ID for this token.",
Computed: true,
Type: schema.TypeString,
},
"secret_id": {
Description: "The value that grants access to Nomad.",
Computed: true,
Sensitive: true,
Type: schema.TypeString,
},
"name": {
Description: "Human-readable name for this token.",
Computed: true,
Type: schema.TypeString,
},
"type": {
Description: "The type of token to create, 'client' or 'management'.",
Computed: true,
Type: schema.TypeString,
},
"policies": {
Description: "The ACL policies to associate with the token, if it's a 'client' type.",
Computed: true,
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
},
"global": {
Description: "Whether the token should be replicated to all regions or not.",
Computed: true,
Type: schema.TypeBool,
},
"create_time": {
Description: "The timestamp the token was created.",
Type: schema.TypeString,
Computed: true,
},
},
}
}
func bootstrapACLs(d *schema.ResourceData, meta interface{}) error {
c := meta.(*Config)
client := getClient(d)
return backoff.Retry(func() error {
resp, _, err := client.ACLTokens().Bootstrap(nil)
if err != nil {
return maybeRetry(err)
}
log.Printf("[DEBUG] Created ACL token %q", resp.AccessorID)
d.SetId(resp.AccessorID)
err = multiError(
d.Set("accessor_id", resp.AccessorID),
d.Set("secret_id", resp.SecretID),
d.Set("name", resp.Name),
d.Set("type", resp.Type),
d.Set("policies", resp.Policies),
d.Set("global", resp.Global),
d.Set("create_time", resp.CreateTime.UTC().String()))
log.Printf("[DEBUG] Saved ACL token in state %q", resp.AccessorID)
return err
}, c.retryBackoff)
}