/
secretStaticAccount.go
424 lines (370 loc) · 18.5 KB
/
secretStaticAccount.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
// 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 gcp
import (
"context"
"reflect"
"errors"
"github.com/pulumi/pulumi-vault/sdk/v6/go/vault/internal"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
// Creates a Static Account in the [GCP Secrets Engine](https://www.vaultproject.io/docs/secrets/gcp/index.html) for Vault.
//
// Each [static account](https://www.vaultproject.io/docs/secrets/gcp/index.html#static-accounts) is tied to a separately managed
// Service Account, and can have one or more [bindings](https://www.vaultproject.io/docs/secrets/gcp/index.html#bindings) associated with it.
//
// ## Example Usage
//
// <!--Start PulumiCodeChooser -->
// ```go
// package main
//
// import (
//
// "fmt"
// "os"
//
// "github.com/pulumi/pulumi-gcp/sdk/v5/go/gcp/serviceAccount"
// "github.com/pulumi/pulumi-vault/sdk/v6/go/vault/gcp"
// "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 {
// this, err := serviceAccount.NewAccount(ctx, "this", &serviceAccount.AccountArgs{
// AccountId: pulumi.String("my-awesome-account"),
// })
// if err != nil {
// return err
// }
// gcp, err := gcp.NewSecretBackend(ctx, "gcp", &gcp.SecretBackendArgs{
// Path: pulumi.String("gcp"),
// Credentials: readFileOrPanic("credentials.json"),
// })
// if err != nil {
// return err
// }
// _, err = gcp.NewSecretStaticAccount(ctx, "staticAccount", &gcp.SecretStaticAccountArgs{
// Backend: gcp.Path,
// StaticAccount: pulumi.String("project_viewer"),
// SecretType: pulumi.String("access_token"),
// TokenScopes: pulumi.StringArray{
// pulumi.String("https://www.googleapis.com/auth/cloud-platform"),
// },
// ServiceAccountEmail: this.Email,
// Bindings: gcp.SecretStaticAccountBindingArray{
// &gcp.SecretStaticAccountBindingArgs{
// Resource: this.Project.ApplyT(func(project string) (string, error) {
// return fmt.Sprintf("//cloudresourcemanager.googleapis.com/projects/%v", project), nil
// }).(pulumi.StringOutput),
// Roles: pulumi.StringArray{
// pulumi.String("roles/viewer"),
// },
// },
// },
// })
// if err != nil {
// return err
// }
// return nil
// })
// }
//
// ```
// <!--End PulumiCodeChooser -->
//
// ## Import
//
// A static account can be imported using its Vault Path. For example, referencing the example above,
//
// ```sh
// $ pulumi import vault:gcp/secretStaticAccount:SecretStaticAccount static_account gcp/static-account/project_viewer
// ```
type SecretStaticAccount struct {
pulumi.CustomResourceState
// Path where the GCP Secrets Engine is mounted
Backend pulumi.StringOutput `pulumi:"backend"`
// Bindings to create for this static account. This can be specified multiple times for multiple bindings. Structure is documented below.
Bindings SecretStaticAccountBindingArrayOutput `pulumi:"bindings"`
// 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"`
// Type of secret generated for this static account. Accepted values: `accessToken`, `serviceAccountKey`. Defaults to `accessToken`.
SecretType pulumi.StringOutput `pulumi:"secretType"`
// Email of the GCP service account to manage.
ServiceAccountEmail pulumi.StringOutput `pulumi:"serviceAccountEmail"`
// Project the service account belongs to.
ServiceAccountProject pulumi.StringOutput `pulumi:"serviceAccountProject"`
// Name of the Static Account to create
StaticAccount pulumi.StringOutput `pulumi:"staticAccount"`
// List of OAuth scopes to assign to `accessToken` secrets generated under this static account (`accessToken` static accounts only).
TokenScopes pulumi.StringArrayOutput `pulumi:"tokenScopes"`
}
// NewSecretStaticAccount registers a new resource with the given unique name, arguments, and options.
func NewSecretStaticAccount(ctx *pulumi.Context,
name string, args *SecretStaticAccountArgs, opts ...pulumi.ResourceOption) (*SecretStaticAccount, error) {
if args == nil {
return nil, errors.New("missing one or more required arguments")
}
if args.Backend == nil {
return nil, errors.New("invalid value for required argument 'Backend'")
}
if args.ServiceAccountEmail == nil {
return nil, errors.New("invalid value for required argument 'ServiceAccountEmail'")
}
if args.StaticAccount == nil {
return nil, errors.New("invalid value for required argument 'StaticAccount'")
}
opts = internal.PkgResourceDefaultOpts(opts)
var resource SecretStaticAccount
err := ctx.RegisterResource("vault:gcp/secretStaticAccount:SecretStaticAccount", name, args, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// GetSecretStaticAccount gets an existing SecretStaticAccount 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 GetSecretStaticAccount(ctx *pulumi.Context,
name string, id pulumi.IDInput, state *SecretStaticAccountState, opts ...pulumi.ResourceOption) (*SecretStaticAccount, error) {
var resource SecretStaticAccount
err := ctx.ReadResource("vault:gcp/secretStaticAccount:SecretStaticAccount", name, id, state, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// Input properties used for looking up and filtering SecretStaticAccount resources.
type secretStaticAccountState struct {
// Path where the GCP Secrets Engine is mounted
Backend *string `pulumi:"backend"`
// Bindings to create for this static account. This can be specified multiple times for multiple bindings. Structure is documented below.
Bindings []SecretStaticAccountBinding `pulumi:"bindings"`
// 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"`
// Type of secret generated for this static account. Accepted values: `accessToken`, `serviceAccountKey`. Defaults to `accessToken`.
SecretType *string `pulumi:"secretType"`
// Email of the GCP service account to manage.
ServiceAccountEmail *string `pulumi:"serviceAccountEmail"`
// Project the service account belongs to.
ServiceAccountProject *string `pulumi:"serviceAccountProject"`
// Name of the Static Account to create
StaticAccount *string `pulumi:"staticAccount"`
// List of OAuth scopes to assign to `accessToken` secrets generated under this static account (`accessToken` static accounts only).
TokenScopes []string `pulumi:"tokenScopes"`
}
type SecretStaticAccountState struct {
// Path where the GCP Secrets Engine is mounted
Backend pulumi.StringPtrInput
// Bindings to create for this static account. This can be specified multiple times for multiple bindings. Structure is documented below.
Bindings SecretStaticAccountBindingArrayInput
// 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
// Type of secret generated for this static account. Accepted values: `accessToken`, `serviceAccountKey`. Defaults to `accessToken`.
SecretType pulumi.StringPtrInput
// Email of the GCP service account to manage.
ServiceAccountEmail pulumi.StringPtrInput
// Project the service account belongs to.
ServiceAccountProject pulumi.StringPtrInput
// Name of the Static Account to create
StaticAccount pulumi.StringPtrInput
// List of OAuth scopes to assign to `accessToken` secrets generated under this static account (`accessToken` static accounts only).
TokenScopes pulumi.StringArrayInput
}
func (SecretStaticAccountState) ElementType() reflect.Type {
return reflect.TypeOf((*secretStaticAccountState)(nil)).Elem()
}
type secretStaticAccountArgs struct {
// Path where the GCP Secrets Engine is mounted
Backend string `pulumi:"backend"`
// Bindings to create for this static account. This can be specified multiple times for multiple bindings. Structure is documented below.
Bindings []SecretStaticAccountBinding `pulumi:"bindings"`
// 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"`
// Type of secret generated for this static account. Accepted values: `accessToken`, `serviceAccountKey`. Defaults to `accessToken`.
SecretType *string `pulumi:"secretType"`
// Email of the GCP service account to manage.
ServiceAccountEmail string `pulumi:"serviceAccountEmail"`
// Name of the Static Account to create
StaticAccount string `pulumi:"staticAccount"`
// List of OAuth scopes to assign to `accessToken` secrets generated under this static account (`accessToken` static accounts only).
TokenScopes []string `pulumi:"tokenScopes"`
}
// The set of arguments for constructing a SecretStaticAccount resource.
type SecretStaticAccountArgs struct {
// Path where the GCP Secrets Engine is mounted
Backend pulumi.StringInput
// Bindings to create for this static account. This can be specified multiple times for multiple bindings. Structure is documented below.
Bindings SecretStaticAccountBindingArrayInput
// 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
// Type of secret generated for this static account. Accepted values: `accessToken`, `serviceAccountKey`. Defaults to `accessToken`.
SecretType pulumi.StringPtrInput
// Email of the GCP service account to manage.
ServiceAccountEmail pulumi.StringInput
// Name of the Static Account to create
StaticAccount pulumi.StringInput
// List of OAuth scopes to assign to `accessToken` secrets generated under this static account (`accessToken` static accounts only).
TokenScopes pulumi.StringArrayInput
}
func (SecretStaticAccountArgs) ElementType() reflect.Type {
return reflect.TypeOf((*secretStaticAccountArgs)(nil)).Elem()
}
type SecretStaticAccountInput interface {
pulumi.Input
ToSecretStaticAccountOutput() SecretStaticAccountOutput
ToSecretStaticAccountOutputWithContext(ctx context.Context) SecretStaticAccountOutput
}
func (*SecretStaticAccount) ElementType() reflect.Type {
return reflect.TypeOf((**SecretStaticAccount)(nil)).Elem()
}
func (i *SecretStaticAccount) ToSecretStaticAccountOutput() SecretStaticAccountOutput {
return i.ToSecretStaticAccountOutputWithContext(context.Background())
}
func (i *SecretStaticAccount) ToSecretStaticAccountOutputWithContext(ctx context.Context) SecretStaticAccountOutput {
return pulumi.ToOutputWithContext(ctx, i).(SecretStaticAccountOutput)
}
// SecretStaticAccountArrayInput is an input type that accepts SecretStaticAccountArray and SecretStaticAccountArrayOutput values.
// You can construct a concrete instance of `SecretStaticAccountArrayInput` via:
//
// SecretStaticAccountArray{ SecretStaticAccountArgs{...} }
type SecretStaticAccountArrayInput interface {
pulumi.Input
ToSecretStaticAccountArrayOutput() SecretStaticAccountArrayOutput
ToSecretStaticAccountArrayOutputWithContext(context.Context) SecretStaticAccountArrayOutput
}
type SecretStaticAccountArray []SecretStaticAccountInput
func (SecretStaticAccountArray) ElementType() reflect.Type {
return reflect.TypeOf((*[]*SecretStaticAccount)(nil)).Elem()
}
func (i SecretStaticAccountArray) ToSecretStaticAccountArrayOutput() SecretStaticAccountArrayOutput {
return i.ToSecretStaticAccountArrayOutputWithContext(context.Background())
}
func (i SecretStaticAccountArray) ToSecretStaticAccountArrayOutputWithContext(ctx context.Context) SecretStaticAccountArrayOutput {
return pulumi.ToOutputWithContext(ctx, i).(SecretStaticAccountArrayOutput)
}
// SecretStaticAccountMapInput is an input type that accepts SecretStaticAccountMap and SecretStaticAccountMapOutput values.
// You can construct a concrete instance of `SecretStaticAccountMapInput` via:
//
// SecretStaticAccountMap{ "key": SecretStaticAccountArgs{...} }
type SecretStaticAccountMapInput interface {
pulumi.Input
ToSecretStaticAccountMapOutput() SecretStaticAccountMapOutput
ToSecretStaticAccountMapOutputWithContext(context.Context) SecretStaticAccountMapOutput
}
type SecretStaticAccountMap map[string]SecretStaticAccountInput
func (SecretStaticAccountMap) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*SecretStaticAccount)(nil)).Elem()
}
func (i SecretStaticAccountMap) ToSecretStaticAccountMapOutput() SecretStaticAccountMapOutput {
return i.ToSecretStaticAccountMapOutputWithContext(context.Background())
}
func (i SecretStaticAccountMap) ToSecretStaticAccountMapOutputWithContext(ctx context.Context) SecretStaticAccountMapOutput {
return pulumi.ToOutputWithContext(ctx, i).(SecretStaticAccountMapOutput)
}
type SecretStaticAccountOutput struct{ *pulumi.OutputState }
func (SecretStaticAccountOutput) ElementType() reflect.Type {
return reflect.TypeOf((**SecretStaticAccount)(nil)).Elem()
}
func (o SecretStaticAccountOutput) ToSecretStaticAccountOutput() SecretStaticAccountOutput {
return o
}
func (o SecretStaticAccountOutput) ToSecretStaticAccountOutputWithContext(ctx context.Context) SecretStaticAccountOutput {
return o
}
// Path where the GCP Secrets Engine is mounted
func (o SecretStaticAccountOutput) Backend() pulumi.StringOutput {
return o.ApplyT(func(v *SecretStaticAccount) pulumi.StringOutput { return v.Backend }).(pulumi.StringOutput)
}
// Bindings to create for this static account. This can be specified multiple times for multiple bindings. Structure is documented below.
func (o SecretStaticAccountOutput) Bindings() SecretStaticAccountBindingArrayOutput {
return o.ApplyT(func(v *SecretStaticAccount) SecretStaticAccountBindingArrayOutput { return v.Bindings }).(SecretStaticAccountBindingArrayOutput)
}
// 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 SecretStaticAccountOutput) Namespace() pulumi.StringPtrOutput {
return o.ApplyT(func(v *SecretStaticAccount) pulumi.StringPtrOutput { return v.Namespace }).(pulumi.StringPtrOutput)
}
// Type of secret generated for this static account. Accepted values: `accessToken`, `serviceAccountKey`. Defaults to `accessToken`.
func (o SecretStaticAccountOutput) SecretType() pulumi.StringOutput {
return o.ApplyT(func(v *SecretStaticAccount) pulumi.StringOutput { return v.SecretType }).(pulumi.StringOutput)
}
// Email of the GCP service account to manage.
func (o SecretStaticAccountOutput) ServiceAccountEmail() pulumi.StringOutput {
return o.ApplyT(func(v *SecretStaticAccount) pulumi.StringOutput { return v.ServiceAccountEmail }).(pulumi.StringOutput)
}
// Project the service account belongs to.
func (o SecretStaticAccountOutput) ServiceAccountProject() pulumi.StringOutput {
return o.ApplyT(func(v *SecretStaticAccount) pulumi.StringOutput { return v.ServiceAccountProject }).(pulumi.StringOutput)
}
// Name of the Static Account to create
func (o SecretStaticAccountOutput) StaticAccount() pulumi.StringOutput {
return o.ApplyT(func(v *SecretStaticAccount) pulumi.StringOutput { return v.StaticAccount }).(pulumi.StringOutput)
}
// List of OAuth scopes to assign to `accessToken` secrets generated under this static account (`accessToken` static accounts only).
func (o SecretStaticAccountOutput) TokenScopes() pulumi.StringArrayOutput {
return o.ApplyT(func(v *SecretStaticAccount) pulumi.StringArrayOutput { return v.TokenScopes }).(pulumi.StringArrayOutput)
}
type SecretStaticAccountArrayOutput struct{ *pulumi.OutputState }
func (SecretStaticAccountArrayOutput) ElementType() reflect.Type {
return reflect.TypeOf((*[]*SecretStaticAccount)(nil)).Elem()
}
func (o SecretStaticAccountArrayOutput) ToSecretStaticAccountArrayOutput() SecretStaticAccountArrayOutput {
return o
}
func (o SecretStaticAccountArrayOutput) ToSecretStaticAccountArrayOutputWithContext(ctx context.Context) SecretStaticAccountArrayOutput {
return o
}
func (o SecretStaticAccountArrayOutput) Index(i pulumi.IntInput) SecretStaticAccountOutput {
return pulumi.All(o, i).ApplyT(func(vs []interface{}) *SecretStaticAccount {
return vs[0].([]*SecretStaticAccount)[vs[1].(int)]
}).(SecretStaticAccountOutput)
}
type SecretStaticAccountMapOutput struct{ *pulumi.OutputState }
func (SecretStaticAccountMapOutput) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*SecretStaticAccount)(nil)).Elem()
}
func (o SecretStaticAccountMapOutput) ToSecretStaticAccountMapOutput() SecretStaticAccountMapOutput {
return o
}
func (o SecretStaticAccountMapOutput) ToSecretStaticAccountMapOutputWithContext(ctx context.Context) SecretStaticAccountMapOutput {
return o
}
func (o SecretStaticAccountMapOutput) MapIndex(k pulumi.StringInput) SecretStaticAccountOutput {
return pulumi.All(o, k).ApplyT(func(vs []interface{}) *SecretStaticAccount {
return vs[0].(map[string]*SecretStaticAccount)[vs[1].(string)]
}).(SecretStaticAccountOutput)
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*SecretStaticAccountInput)(nil)).Elem(), &SecretStaticAccount{})
pulumi.RegisterInputType(reflect.TypeOf((*SecretStaticAccountArrayInput)(nil)).Elem(), SecretStaticAccountArray{})
pulumi.RegisterInputType(reflect.TypeOf((*SecretStaticAccountMapInput)(nil)).Elem(), SecretStaticAccountMap{})
pulumi.RegisterOutputType(SecretStaticAccountOutput{})
pulumi.RegisterOutputType(SecretStaticAccountArrayOutput{})
pulumi.RegisterOutputType(SecretStaticAccountMapOutput{})
}