/
getServiceAccountToken.go
258 lines (231 loc) · 10.4 KB
/
getServiceAccountToken.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
// Code generated by the Pulumi Terraform Bridge (tfgen) Tool DO NOT EDIT.
// *** WARNING: Do not edit by hand unless you're certain you know what you are doing! ***
package kubernetes
import (
"context"
"reflect"
"github.com/pulumi/pulumi-vault/sdk/v6/go/vault/internal"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
// ## Example Usage
//
// <!--Start PulumiCodeChooser -->
// ```go
// package main
//
// import (
//
// "os"
//
// "github.com/pulumi/pulumi-vault/sdk/v6/go/vault/kubernetes"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
//
// )
//
// func readFileOrPanic(path string) pulumi.StringPtrInput {
// data, err := os.ReadFile(path)
// if err != nil {
// panic(err.Error())
// }
// return pulumi.String(string(data))
// }
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// config, err := kubernetes.NewSecretBackend(ctx, "config", &kubernetes.SecretBackendArgs{
// Path: pulumi.String("kubernetes"),
// Description: pulumi.String("kubernetes secrets engine description"),
// KubernetesHost: pulumi.String("https://127.0.0.1:61233"),
// KubernetesCaCert: readFileOrPanic("/path/to/cert"),
// ServiceAccountJwt: readFileOrPanic("/path/to/token"),
// DisableLocalCaJwt: pulumi.Bool(false),
// })
// if err != nil {
// return err
// }
// role, err := kubernetes.NewSecretBackendRole(ctx, "role", &kubernetes.SecretBackendRoleArgs{
// Backend: config.Path,
// AllowedKubernetesNamespaces: pulumi.StringArray{
// pulumi.String("*"),
// },
// TokenMaxTtl: pulumi.Int(43200),
// TokenDefaultTtl: pulumi.Int(21600),
// ServiceAccountName: pulumi.String("test-service-account-with-generated-token"),
// ExtraLabels: pulumi.StringMap{
// "id": pulumi.String("abc123"),
// "name": pulumi.String("some_name"),
// },
// ExtraAnnotations: pulumi.StringMap{
// "env": pulumi.String("development"),
// "location": pulumi.String("earth"),
// },
// })
// if err != nil {
// return err
// }
// _ = kubernetes.GetServiceAccountTokenOutput(ctx, kubernetes.GetServiceAccountTokenOutputArgs{
// Backend: config.Path,
// Role: role.Name,
// KubernetesNamespace: pulumi.String("test"),
// ClusterRoleBinding: pulumi.Bool(false),
// Ttl: pulumi.String("1h"),
// }, nil)
// return nil
// })
// }
//
// ```
// <!--End PulumiCodeChooser -->
func GetServiceAccountToken(ctx *pulumi.Context, args *GetServiceAccountTokenArgs, opts ...pulumi.InvokeOption) (*GetServiceAccountTokenResult, error) {
opts = internal.PkgInvokeDefaultOpts(opts)
var rv GetServiceAccountTokenResult
err := ctx.Invoke("vault:kubernetes/getServiceAccountToken:getServiceAccountToken", args, &rv, opts...)
if err != nil {
return nil, err
}
return &rv, nil
}
// A collection of arguments for invoking getServiceAccountToken.
type GetServiceAccountTokenArgs struct {
// The Kubernetes secret backend to generate service account
// tokens from.
Backend string `pulumi:"backend"`
// If true, generate a ClusterRoleBinding to grant
// permissions across the whole cluster instead of within a namespace.
ClusterRoleBinding *bool `pulumi:"clusterRoleBinding"`
// The name of the Kubernetes namespace in which to
// generate the credentials.
KubernetesNamespace string `pulumi:"kubernetesNamespace"`
// The namespace of the target resource.
// The value should not contain leading or trailing forward slashes.
// The `namespace` is always relative to the provider's configured [namespace](https://www.terraform.io/docs/providers/vault/index.html#namespace).
// *Available only for Vault Enterprise*.
Namespace *string `pulumi:"namespace"`
// The name of the Kubernetes secret backend role to generate service
// account tokens from.
Role string `pulumi:"role"`
// The TTL of the generated Kubernetes service account token, specified in
// seconds or as a Go duration format string.
Ttl *string `pulumi:"ttl"`
}
// A collection of values returned by getServiceAccountToken.
type GetServiceAccountTokenResult struct {
Backend string `pulumi:"backend"`
ClusterRoleBinding *bool `pulumi:"clusterRoleBinding"`
// The provider-assigned unique ID for this managed resource.
Id string `pulumi:"id"`
KubernetesNamespace string `pulumi:"kubernetesNamespace"`
// The duration of the lease in seconds.
LeaseDuration int `pulumi:"leaseDuration"`
// The lease identifier assigned by Vault.
LeaseId string `pulumi:"leaseId"`
// True if the duration of this lease can be extended through renewal.
LeaseRenewable bool `pulumi:"leaseRenewable"`
Namespace *string `pulumi:"namespace"`
Role string `pulumi:"role"`
// The name of the service account associated with the token.
ServiceAccountName string `pulumi:"serviceAccountName"`
// The Kubernetes namespace that the service account resides in.
ServiceAccountNamespace string `pulumi:"serviceAccountNamespace"`
// The Kubernetes service account token.
ServiceAccountToken string `pulumi:"serviceAccountToken"`
Ttl *string `pulumi:"ttl"`
}
func GetServiceAccountTokenOutput(ctx *pulumi.Context, args GetServiceAccountTokenOutputArgs, opts ...pulumi.InvokeOption) GetServiceAccountTokenResultOutput {
return pulumi.ToOutputWithContext(context.Background(), args).
ApplyT(func(v interface{}) (GetServiceAccountTokenResult, error) {
args := v.(GetServiceAccountTokenArgs)
r, err := GetServiceAccountToken(ctx, &args, opts...)
var s GetServiceAccountTokenResult
if r != nil {
s = *r
}
return s, err
}).(GetServiceAccountTokenResultOutput)
}
// A collection of arguments for invoking getServiceAccountToken.
type GetServiceAccountTokenOutputArgs struct {
// The Kubernetes secret backend to generate service account
// tokens from.
Backend pulumi.StringInput `pulumi:"backend"`
// If true, generate a ClusterRoleBinding to grant
// permissions across the whole cluster instead of within a namespace.
ClusterRoleBinding pulumi.BoolPtrInput `pulumi:"clusterRoleBinding"`
// The name of the Kubernetes namespace in which to
// generate the credentials.
KubernetesNamespace pulumi.StringInput `pulumi:"kubernetesNamespace"`
// The namespace of the target resource.
// The value should not contain leading or trailing forward slashes.
// The `namespace` is always relative to the provider's configured [namespace](https://www.terraform.io/docs/providers/vault/index.html#namespace).
// *Available only for Vault Enterprise*.
Namespace pulumi.StringPtrInput `pulumi:"namespace"`
// The name of the Kubernetes secret backend role to generate service
// account tokens from.
Role pulumi.StringInput `pulumi:"role"`
// The TTL of the generated Kubernetes service account token, specified in
// seconds or as a Go duration format string.
Ttl pulumi.StringPtrInput `pulumi:"ttl"`
}
func (GetServiceAccountTokenOutputArgs) ElementType() reflect.Type {
return reflect.TypeOf((*GetServiceAccountTokenArgs)(nil)).Elem()
}
// A collection of values returned by getServiceAccountToken.
type GetServiceAccountTokenResultOutput struct{ *pulumi.OutputState }
func (GetServiceAccountTokenResultOutput) ElementType() reflect.Type {
return reflect.TypeOf((*GetServiceAccountTokenResult)(nil)).Elem()
}
func (o GetServiceAccountTokenResultOutput) ToGetServiceAccountTokenResultOutput() GetServiceAccountTokenResultOutput {
return o
}
func (o GetServiceAccountTokenResultOutput) ToGetServiceAccountTokenResultOutputWithContext(ctx context.Context) GetServiceAccountTokenResultOutput {
return o
}
func (o GetServiceAccountTokenResultOutput) Backend() pulumi.StringOutput {
return o.ApplyT(func(v GetServiceAccountTokenResult) string { return v.Backend }).(pulumi.StringOutput)
}
func (o GetServiceAccountTokenResultOutput) ClusterRoleBinding() pulumi.BoolPtrOutput {
return o.ApplyT(func(v GetServiceAccountTokenResult) *bool { return v.ClusterRoleBinding }).(pulumi.BoolPtrOutput)
}
// The provider-assigned unique ID for this managed resource.
func (o GetServiceAccountTokenResultOutput) Id() pulumi.StringOutput {
return o.ApplyT(func(v GetServiceAccountTokenResult) string { return v.Id }).(pulumi.StringOutput)
}
func (o GetServiceAccountTokenResultOutput) KubernetesNamespace() pulumi.StringOutput {
return o.ApplyT(func(v GetServiceAccountTokenResult) string { return v.KubernetesNamespace }).(pulumi.StringOutput)
}
// The duration of the lease in seconds.
func (o GetServiceAccountTokenResultOutput) LeaseDuration() pulumi.IntOutput {
return o.ApplyT(func(v GetServiceAccountTokenResult) int { return v.LeaseDuration }).(pulumi.IntOutput)
}
// The lease identifier assigned by Vault.
func (o GetServiceAccountTokenResultOutput) LeaseId() pulumi.StringOutput {
return o.ApplyT(func(v GetServiceAccountTokenResult) string { return v.LeaseId }).(pulumi.StringOutput)
}
// True if the duration of this lease can be extended through renewal.
func (o GetServiceAccountTokenResultOutput) LeaseRenewable() pulumi.BoolOutput {
return o.ApplyT(func(v GetServiceAccountTokenResult) bool { return v.LeaseRenewable }).(pulumi.BoolOutput)
}
func (o GetServiceAccountTokenResultOutput) Namespace() pulumi.StringPtrOutput {
return o.ApplyT(func(v GetServiceAccountTokenResult) *string { return v.Namespace }).(pulumi.StringPtrOutput)
}
func (o GetServiceAccountTokenResultOutput) Role() pulumi.StringOutput {
return o.ApplyT(func(v GetServiceAccountTokenResult) string { return v.Role }).(pulumi.StringOutput)
}
// The name of the service account associated with the token.
func (o GetServiceAccountTokenResultOutput) ServiceAccountName() pulumi.StringOutput {
return o.ApplyT(func(v GetServiceAccountTokenResult) string { return v.ServiceAccountName }).(pulumi.StringOutput)
}
// The Kubernetes namespace that the service account resides in.
func (o GetServiceAccountTokenResultOutput) ServiceAccountNamespace() pulumi.StringOutput {
return o.ApplyT(func(v GetServiceAccountTokenResult) string { return v.ServiceAccountNamespace }).(pulumi.StringOutput)
}
// The Kubernetes service account token.
func (o GetServiceAccountTokenResultOutput) ServiceAccountToken() pulumi.StringOutput {
return o.ApplyT(func(v GetServiceAccountTokenResult) string { return v.ServiceAccountToken }).(pulumi.StringOutput)
}
func (o GetServiceAccountTokenResultOutput) Ttl() pulumi.StringPtrOutput {
return o.ApplyT(func(v GetServiceAccountTokenResult) *string { return v.Ttl }).(pulumi.StringPtrOutput)
}
func init() {
pulumi.RegisterOutputType(GetServiceAccountTokenResultOutput{})
}