/
oidcRole.go
439 lines (387 loc) · 15.4 KB
/
oidcRole.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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
// 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 identity
import (
"context"
"reflect"
"errors"
"github.com/pulumi/pulumi-vault/sdk/v6/go/vault/internal"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
// ## Example Usage
//
// You need to create a role with a named key.
// At creation time, the key can be created independently of the role. However, the key must
// exist before the role can be used to issue tokens. You must also configure the key with the
// role's Client ID to allow the role to use the key.
//
// <!--Start PulumiCodeChooser -->
// ```go
// package main
//
// import (
//
// "github.com/pulumi/pulumi-vault/sdk/v6/go/vault/identity"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
//
// )
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// cfg := config.New(ctx, "")
// key := "key"
// if param := cfg.Get("key"); param != "" {
// key = param
// }
// role, err := identity.NewOidcRole(ctx, "role", &identity.OidcRoleArgs{
// Key: pulumi.String(key),
// })
// if err != nil {
// return err
// }
// _, err = identity.NewOidcKey(ctx, "keyOidcKey", &identity.OidcKeyArgs{
// Algorithm: pulumi.String("RS256"),
// AllowedClientIds: pulumi.StringArray{
// role.ClientId,
// },
// })
// if err != nil {
// return err
// }
// return nil
// })
// }
//
// ```
// <!--End PulumiCodeChooser -->
//
// If you want to create the key first before creating the role, you can use a separate
// resource to configure the allowed Client ID on
// the key.
//
// <!--Start PulumiCodeChooser -->
// ```go
// package main
//
// import (
//
// "github.com/pulumi/pulumi-vault/sdk/v6/go/vault/identity"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
//
// )
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// key, err := identity.NewOidcKey(ctx, "key", &identity.OidcKeyArgs{
// Algorithm: pulumi.String("RS256"),
// })
// if err != nil {
// return err
// }
// roleOidcRole, err := identity.NewOidcRole(ctx, "roleOidcRole", &identity.OidcRoleArgs{
// Key: key.Name,
// })
// if err != nil {
// return err
// }
// _, err = identity.NewOidcKeyAllowedClientID(ctx, "roleOidcKeyAllowedClientID", &identity.OidcKeyAllowedClientIDArgs{
// KeyName: key.Name,
// AllowedClientId: roleOidcRole.ClientId,
// })
// if err != nil {
// return err
// }
// return nil
// })
// }
//
// ```
// <!--End PulumiCodeChooser -->
//
// ## Import
//
// The key can be imported with the role name, for example:
//
// ```sh
// $ pulumi import vault:identity/oidcRole:OidcRole role role
// ```
type OidcRole struct {
pulumi.CustomResourceState
// The value that will be included in the `aud` field of all the OIDC identity
// tokens issued by this role
ClientId pulumi.StringOutput `pulumi:"clientId"`
// A configured named key, the key must already exist
// before tokens can be issued.
Key pulumi.StringOutput `pulumi:"key"`
// Name of the OIDC Role to create.
Name pulumi.StringOutput `pulumi:"name"`
// The namespace to provision the resource in.
// 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.StringPtrOutput `pulumi:"namespace"`
// The template string to use for generating tokens. This may be in
// string-ified JSON or base64 format. See the
// [documentation](https://www.vaultproject.io/docs/secrets/identity/index.html#token-contents-and-templates)
// for the template format.
Template pulumi.StringPtrOutput `pulumi:"template"`
// TTL of the tokens generated against the role in number of seconds.
Ttl pulumi.IntPtrOutput `pulumi:"ttl"`
}
// NewOidcRole registers a new resource with the given unique name, arguments, and options.
func NewOidcRole(ctx *pulumi.Context,
name string, args *OidcRoleArgs, opts ...pulumi.ResourceOption) (*OidcRole, error) {
if args == nil {
return nil, errors.New("missing one or more required arguments")
}
if args.Key == nil {
return nil, errors.New("invalid value for required argument 'Key'")
}
opts = internal.PkgResourceDefaultOpts(opts)
var resource OidcRole
err := ctx.RegisterResource("vault:identity/oidcRole:OidcRole", name, args, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// GetOidcRole gets an existing OidcRole resource's state with the given name, ID, and optional
// state properties that are used to uniquely qualify the lookup (nil if not required).
func GetOidcRole(ctx *pulumi.Context,
name string, id pulumi.IDInput, state *OidcRoleState, opts ...pulumi.ResourceOption) (*OidcRole, error) {
var resource OidcRole
err := ctx.ReadResource("vault:identity/oidcRole:OidcRole", name, id, state, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// Input properties used for looking up and filtering OidcRole resources.
type oidcRoleState struct {
// The value that will be included in the `aud` field of all the OIDC identity
// tokens issued by this role
ClientId *string `pulumi:"clientId"`
// A configured named key, the key must already exist
// before tokens can be issued.
Key *string `pulumi:"key"`
// Name of the OIDC Role to create.
Name *string `pulumi:"name"`
// The namespace to provision the resource in.
// 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 template string to use for generating tokens. This may be in
// string-ified JSON or base64 format. See the
// [documentation](https://www.vaultproject.io/docs/secrets/identity/index.html#token-contents-and-templates)
// for the template format.
Template *string `pulumi:"template"`
// TTL of the tokens generated against the role in number of seconds.
Ttl *int `pulumi:"ttl"`
}
type OidcRoleState struct {
// The value that will be included in the `aud` field of all the OIDC identity
// tokens issued by this role
ClientId pulumi.StringPtrInput
// A configured named key, the key must already exist
// before tokens can be issued.
Key pulumi.StringPtrInput
// Name of the OIDC Role to create.
Name pulumi.StringPtrInput
// The namespace to provision the resource in.
// 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
// The template string to use for generating tokens. This may be in
// string-ified JSON or base64 format. See the
// [documentation](https://www.vaultproject.io/docs/secrets/identity/index.html#token-contents-and-templates)
// for the template format.
Template pulumi.StringPtrInput
// TTL of the tokens generated against the role in number of seconds.
Ttl pulumi.IntPtrInput
}
func (OidcRoleState) ElementType() reflect.Type {
return reflect.TypeOf((*oidcRoleState)(nil)).Elem()
}
type oidcRoleArgs struct {
// The value that will be included in the `aud` field of all the OIDC identity
// tokens issued by this role
ClientId *string `pulumi:"clientId"`
// A configured named key, the key must already exist
// before tokens can be issued.
Key string `pulumi:"key"`
// Name of the OIDC Role to create.
Name *string `pulumi:"name"`
// The namespace to provision the resource in.
// 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 template string to use for generating tokens. This may be in
// string-ified JSON or base64 format. See the
// [documentation](https://www.vaultproject.io/docs/secrets/identity/index.html#token-contents-and-templates)
// for the template format.
Template *string `pulumi:"template"`
// TTL of the tokens generated against the role in number of seconds.
Ttl *int `pulumi:"ttl"`
}
// The set of arguments for constructing a OidcRole resource.
type OidcRoleArgs struct {
// The value that will be included in the `aud` field of all the OIDC identity
// tokens issued by this role
ClientId pulumi.StringPtrInput
// A configured named key, the key must already exist
// before tokens can be issued.
Key pulumi.StringInput
// Name of the OIDC Role to create.
Name pulumi.StringPtrInput
// The namespace to provision the resource in.
// 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
// The template string to use for generating tokens. This may be in
// string-ified JSON or base64 format. See the
// [documentation](https://www.vaultproject.io/docs/secrets/identity/index.html#token-contents-and-templates)
// for the template format.
Template pulumi.StringPtrInput
// TTL of the tokens generated against the role in number of seconds.
Ttl pulumi.IntPtrInput
}
func (OidcRoleArgs) ElementType() reflect.Type {
return reflect.TypeOf((*oidcRoleArgs)(nil)).Elem()
}
type OidcRoleInput interface {
pulumi.Input
ToOidcRoleOutput() OidcRoleOutput
ToOidcRoleOutputWithContext(ctx context.Context) OidcRoleOutput
}
func (*OidcRole) ElementType() reflect.Type {
return reflect.TypeOf((**OidcRole)(nil)).Elem()
}
func (i *OidcRole) ToOidcRoleOutput() OidcRoleOutput {
return i.ToOidcRoleOutputWithContext(context.Background())
}
func (i *OidcRole) ToOidcRoleOutputWithContext(ctx context.Context) OidcRoleOutput {
return pulumi.ToOutputWithContext(ctx, i).(OidcRoleOutput)
}
// OidcRoleArrayInput is an input type that accepts OidcRoleArray and OidcRoleArrayOutput values.
// You can construct a concrete instance of `OidcRoleArrayInput` via:
//
// OidcRoleArray{ OidcRoleArgs{...} }
type OidcRoleArrayInput interface {
pulumi.Input
ToOidcRoleArrayOutput() OidcRoleArrayOutput
ToOidcRoleArrayOutputWithContext(context.Context) OidcRoleArrayOutput
}
type OidcRoleArray []OidcRoleInput
func (OidcRoleArray) ElementType() reflect.Type {
return reflect.TypeOf((*[]*OidcRole)(nil)).Elem()
}
func (i OidcRoleArray) ToOidcRoleArrayOutput() OidcRoleArrayOutput {
return i.ToOidcRoleArrayOutputWithContext(context.Background())
}
func (i OidcRoleArray) ToOidcRoleArrayOutputWithContext(ctx context.Context) OidcRoleArrayOutput {
return pulumi.ToOutputWithContext(ctx, i).(OidcRoleArrayOutput)
}
// OidcRoleMapInput is an input type that accepts OidcRoleMap and OidcRoleMapOutput values.
// You can construct a concrete instance of `OidcRoleMapInput` via:
//
// OidcRoleMap{ "key": OidcRoleArgs{...} }
type OidcRoleMapInput interface {
pulumi.Input
ToOidcRoleMapOutput() OidcRoleMapOutput
ToOidcRoleMapOutputWithContext(context.Context) OidcRoleMapOutput
}
type OidcRoleMap map[string]OidcRoleInput
func (OidcRoleMap) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*OidcRole)(nil)).Elem()
}
func (i OidcRoleMap) ToOidcRoleMapOutput() OidcRoleMapOutput {
return i.ToOidcRoleMapOutputWithContext(context.Background())
}
func (i OidcRoleMap) ToOidcRoleMapOutputWithContext(ctx context.Context) OidcRoleMapOutput {
return pulumi.ToOutputWithContext(ctx, i).(OidcRoleMapOutput)
}
type OidcRoleOutput struct{ *pulumi.OutputState }
func (OidcRoleOutput) ElementType() reflect.Type {
return reflect.TypeOf((**OidcRole)(nil)).Elem()
}
func (o OidcRoleOutput) ToOidcRoleOutput() OidcRoleOutput {
return o
}
func (o OidcRoleOutput) ToOidcRoleOutputWithContext(ctx context.Context) OidcRoleOutput {
return o
}
// The value that will be included in the `aud` field of all the OIDC identity
// tokens issued by this role
func (o OidcRoleOutput) ClientId() pulumi.StringOutput {
return o.ApplyT(func(v *OidcRole) pulumi.StringOutput { return v.ClientId }).(pulumi.StringOutput)
}
// A configured named key, the key must already exist
// before tokens can be issued.
func (o OidcRoleOutput) Key() pulumi.StringOutput {
return o.ApplyT(func(v *OidcRole) pulumi.StringOutput { return v.Key }).(pulumi.StringOutput)
}
// Name of the OIDC Role to create.
func (o OidcRoleOutput) Name() pulumi.StringOutput {
return o.ApplyT(func(v *OidcRole) pulumi.StringOutput { return v.Name }).(pulumi.StringOutput)
}
// The namespace to provision the resource in.
// 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*.
func (o OidcRoleOutput) Namespace() pulumi.StringPtrOutput {
return o.ApplyT(func(v *OidcRole) pulumi.StringPtrOutput { return v.Namespace }).(pulumi.StringPtrOutput)
}
// The template string to use for generating tokens. This may be in
// string-ified JSON or base64 format. See the
// [documentation](https://www.vaultproject.io/docs/secrets/identity/index.html#token-contents-and-templates)
// for the template format.
func (o OidcRoleOutput) Template() pulumi.StringPtrOutput {
return o.ApplyT(func(v *OidcRole) pulumi.StringPtrOutput { return v.Template }).(pulumi.StringPtrOutput)
}
// TTL of the tokens generated against the role in number of seconds.
func (o OidcRoleOutput) Ttl() pulumi.IntPtrOutput {
return o.ApplyT(func(v *OidcRole) pulumi.IntPtrOutput { return v.Ttl }).(pulumi.IntPtrOutput)
}
type OidcRoleArrayOutput struct{ *pulumi.OutputState }
func (OidcRoleArrayOutput) ElementType() reflect.Type {
return reflect.TypeOf((*[]*OidcRole)(nil)).Elem()
}
func (o OidcRoleArrayOutput) ToOidcRoleArrayOutput() OidcRoleArrayOutput {
return o
}
func (o OidcRoleArrayOutput) ToOidcRoleArrayOutputWithContext(ctx context.Context) OidcRoleArrayOutput {
return o
}
func (o OidcRoleArrayOutput) Index(i pulumi.IntInput) OidcRoleOutput {
return pulumi.All(o, i).ApplyT(func(vs []interface{}) *OidcRole {
return vs[0].([]*OidcRole)[vs[1].(int)]
}).(OidcRoleOutput)
}
type OidcRoleMapOutput struct{ *pulumi.OutputState }
func (OidcRoleMapOutput) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*OidcRole)(nil)).Elem()
}
func (o OidcRoleMapOutput) ToOidcRoleMapOutput() OidcRoleMapOutput {
return o
}
func (o OidcRoleMapOutput) ToOidcRoleMapOutputWithContext(ctx context.Context) OidcRoleMapOutput {
return o
}
func (o OidcRoleMapOutput) MapIndex(k pulumi.StringInput) OidcRoleOutput {
return pulumi.All(o, k).ApplyT(func(vs []interface{}) *OidcRole {
return vs[0].(map[string]*OidcRole)[vs[1].(string)]
}).(OidcRoleOutput)
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*OidcRoleInput)(nil)).Elem(), &OidcRole{})
pulumi.RegisterInputType(reflect.TypeOf((*OidcRoleArrayInput)(nil)).Elem(), OidcRoleArray{})
pulumi.RegisterInputType(reflect.TypeOf((*OidcRoleMapInput)(nil)).Elem(), OidcRoleMap{})
pulumi.RegisterOutputType(OidcRoleOutput{})
pulumi.RegisterOutputType(OidcRoleArrayOutput{})
pulumi.RegisterOutputType(OidcRoleMapOutput{})
}