/
key.go
424 lines (363 loc) · 16.7 KB
/
key.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
// *** WARNING: this file was generated by the Pulumi Terraform Bridge (tfgen) Tool. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
package serviceaccount
import (
"context"
"reflect"
"github.com/pkg/errors"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
// Creates and manages service account keys, which allow the use of a service account outside of Google Cloud.
//
// * [API documentation](https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts.keys)
// * How-to Guides
// * [Official Documentation](https://cloud.google.com/iam/docs/creating-managing-service-account-keys)
//
// ## Example Usage
// ### Creating A New Key
//
// ```go
// package main
//
// import (
// "github.com/pulumi/pulumi-gcp/sdk/v5/go/gcp/serviceAccount"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
// )
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// myaccount, err := serviceAccount.NewAccount(ctx, "myaccount", &serviceAccount.AccountArgs{
// AccountId: pulumi.String("myaccount"),
// DisplayName: pulumi.String("My Service Account"),
// })
// if err != nil {
// return err
// }
// _, err = serviceAccount.NewKey(ctx, "mykey", &serviceAccount.KeyArgs{
// ServiceAccountId: myaccount.Name,
// PublicKeyType: pulumi.String("TYPE_X509_PEM_FILE"),
// })
// if err != nil {
// return err
// }
// return nil
// })
// }
// ```
//
// ## Import
//
// This resource does not support import.
type Key struct {
pulumi.CustomResourceState
// Arbitrary map of values that, when changed, will trigger a new key to be generated.
Keepers pulumi.MapOutput `pulumi:"keepers"`
// The algorithm used to generate the key. KEY_ALG_RSA_2048 is the default algorithm.
// Valid values are listed at
// [ServiceAccountPrivateKeyType](https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts.keys#ServiceAccountKeyAlgorithm)
// (only used on create)
KeyAlgorithm pulumi.StringPtrOutput `pulumi:"keyAlgorithm"`
// The name used for this key pair
Name pulumi.StringOutput `pulumi:"name"`
// The private key in JSON format, base64 encoded. This is what you normally get as a file when creating
// service account keys through the CLI or web console. This is only populated when creating a new key.
PrivateKey pulumi.StringOutput `pulumi:"privateKey"`
// The output format of the private key. TYPE_GOOGLE_CREDENTIALS_FILE is the default output format.
PrivateKeyType pulumi.StringPtrOutput `pulumi:"privateKeyType"`
// The public key, base64 encoded
PublicKey pulumi.StringOutput `pulumi:"publicKey"`
// Public key data to create a service account key for given service account. The expected format for this field is a base64 encoded X509_PEM and it conflicts with `publicKeyType` and `privateKeyType`.
PublicKeyData pulumi.StringPtrOutput `pulumi:"publicKeyData"`
// The output format of the public key requested. TYPE_X509_PEM_FILE is the default output format.
PublicKeyType pulumi.StringPtrOutput `pulumi:"publicKeyType"`
// The Service account id of the Key. This can be a string in the format
// `{ACCOUNT}` or `projects/{PROJECT_ID}/serviceAccounts/{ACCOUNT}`, where `{ACCOUNT}` is the email address or
// unique id of the service account. If the `{ACCOUNT}` syntax is used, the project will be inferred from the account.
ServiceAccountId pulumi.StringOutput `pulumi:"serviceAccountId"`
// The key can be used after this timestamp. A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds. Example: "2014-10-02T15:01:23.045123456Z".
ValidAfter pulumi.StringOutput `pulumi:"validAfter"`
// The key can be used before this timestamp.
// A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds. Example: "2014-10-02T15:01:23.045123456Z".
ValidBefore pulumi.StringOutput `pulumi:"validBefore"`
}
// NewKey registers a new resource with the given unique name, arguments, and options.
func NewKey(ctx *pulumi.Context,
name string, args *KeyArgs, opts ...pulumi.ResourceOption) (*Key, error) {
if args == nil {
return nil, errors.New("missing one or more required arguments")
}
if args.ServiceAccountId == nil {
return nil, errors.New("invalid value for required argument 'ServiceAccountId'")
}
var resource Key
err := ctx.RegisterResource("gcp:serviceAccount/key:Key", name, args, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// GetKey gets an existing Key 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 GetKey(ctx *pulumi.Context,
name string, id pulumi.IDInput, state *KeyState, opts ...pulumi.ResourceOption) (*Key, error) {
var resource Key
err := ctx.ReadResource("gcp:serviceAccount/key:Key", name, id, state, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// Input properties used for looking up and filtering Key resources.
type keyState struct {
// Arbitrary map of values that, when changed, will trigger a new key to be generated.
Keepers map[string]interface{} `pulumi:"keepers"`
// The algorithm used to generate the key. KEY_ALG_RSA_2048 is the default algorithm.
// Valid values are listed at
// [ServiceAccountPrivateKeyType](https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts.keys#ServiceAccountKeyAlgorithm)
// (only used on create)
KeyAlgorithm *string `pulumi:"keyAlgorithm"`
// The name used for this key pair
Name *string `pulumi:"name"`
// The private key in JSON format, base64 encoded. This is what you normally get as a file when creating
// service account keys through the CLI or web console. This is only populated when creating a new key.
PrivateKey *string `pulumi:"privateKey"`
// The output format of the private key. TYPE_GOOGLE_CREDENTIALS_FILE is the default output format.
PrivateKeyType *string `pulumi:"privateKeyType"`
// The public key, base64 encoded
PublicKey *string `pulumi:"publicKey"`
// Public key data to create a service account key for given service account. The expected format for this field is a base64 encoded X509_PEM and it conflicts with `publicKeyType` and `privateKeyType`.
PublicKeyData *string `pulumi:"publicKeyData"`
// The output format of the public key requested. TYPE_X509_PEM_FILE is the default output format.
PublicKeyType *string `pulumi:"publicKeyType"`
// The Service account id of the Key. This can be a string in the format
// `{ACCOUNT}` or `projects/{PROJECT_ID}/serviceAccounts/{ACCOUNT}`, where `{ACCOUNT}` is the email address or
// unique id of the service account. If the `{ACCOUNT}` syntax is used, the project will be inferred from the account.
ServiceAccountId *string `pulumi:"serviceAccountId"`
// The key can be used after this timestamp. A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds. Example: "2014-10-02T15:01:23.045123456Z".
ValidAfter *string `pulumi:"validAfter"`
// The key can be used before this timestamp.
// A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds. Example: "2014-10-02T15:01:23.045123456Z".
ValidBefore *string `pulumi:"validBefore"`
}
type KeyState struct {
// Arbitrary map of values that, when changed, will trigger a new key to be generated.
Keepers pulumi.MapInput
// The algorithm used to generate the key. KEY_ALG_RSA_2048 is the default algorithm.
// Valid values are listed at
// [ServiceAccountPrivateKeyType](https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts.keys#ServiceAccountKeyAlgorithm)
// (only used on create)
KeyAlgorithm pulumi.StringPtrInput
// The name used for this key pair
Name pulumi.StringPtrInput
// The private key in JSON format, base64 encoded. This is what you normally get as a file when creating
// service account keys through the CLI or web console. This is only populated when creating a new key.
PrivateKey pulumi.StringPtrInput
// The output format of the private key. TYPE_GOOGLE_CREDENTIALS_FILE is the default output format.
PrivateKeyType pulumi.StringPtrInput
// The public key, base64 encoded
PublicKey pulumi.StringPtrInput
// Public key data to create a service account key for given service account. The expected format for this field is a base64 encoded X509_PEM and it conflicts with `publicKeyType` and `privateKeyType`.
PublicKeyData pulumi.StringPtrInput
// The output format of the public key requested. TYPE_X509_PEM_FILE is the default output format.
PublicKeyType pulumi.StringPtrInput
// The Service account id of the Key. This can be a string in the format
// `{ACCOUNT}` or `projects/{PROJECT_ID}/serviceAccounts/{ACCOUNT}`, where `{ACCOUNT}` is the email address or
// unique id of the service account. If the `{ACCOUNT}` syntax is used, the project will be inferred from the account.
ServiceAccountId pulumi.StringPtrInput
// The key can be used after this timestamp. A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds. Example: "2014-10-02T15:01:23.045123456Z".
ValidAfter pulumi.StringPtrInput
// The key can be used before this timestamp.
// A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds. Example: "2014-10-02T15:01:23.045123456Z".
ValidBefore pulumi.StringPtrInput
}
func (KeyState) ElementType() reflect.Type {
return reflect.TypeOf((*keyState)(nil)).Elem()
}
type keyArgs struct {
// Arbitrary map of values that, when changed, will trigger a new key to be generated.
Keepers map[string]interface{} `pulumi:"keepers"`
// The algorithm used to generate the key. KEY_ALG_RSA_2048 is the default algorithm.
// Valid values are listed at
// [ServiceAccountPrivateKeyType](https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts.keys#ServiceAccountKeyAlgorithm)
// (only used on create)
KeyAlgorithm *string `pulumi:"keyAlgorithm"`
// The output format of the private key. TYPE_GOOGLE_CREDENTIALS_FILE is the default output format.
PrivateKeyType *string `pulumi:"privateKeyType"`
// Public key data to create a service account key for given service account. The expected format for this field is a base64 encoded X509_PEM and it conflicts with `publicKeyType` and `privateKeyType`.
PublicKeyData *string `pulumi:"publicKeyData"`
// The output format of the public key requested. TYPE_X509_PEM_FILE is the default output format.
PublicKeyType *string `pulumi:"publicKeyType"`
// The Service account id of the Key. This can be a string in the format
// `{ACCOUNT}` or `projects/{PROJECT_ID}/serviceAccounts/{ACCOUNT}`, where `{ACCOUNT}` is the email address or
// unique id of the service account. If the `{ACCOUNT}` syntax is used, the project will be inferred from the account.
ServiceAccountId string `pulumi:"serviceAccountId"`
}
// The set of arguments for constructing a Key resource.
type KeyArgs struct {
// Arbitrary map of values that, when changed, will trigger a new key to be generated.
Keepers pulumi.MapInput
// The algorithm used to generate the key. KEY_ALG_RSA_2048 is the default algorithm.
// Valid values are listed at
// [ServiceAccountPrivateKeyType](https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts.keys#ServiceAccountKeyAlgorithm)
// (only used on create)
KeyAlgorithm pulumi.StringPtrInput
// The output format of the private key. TYPE_GOOGLE_CREDENTIALS_FILE is the default output format.
PrivateKeyType pulumi.StringPtrInput
// Public key data to create a service account key for given service account. The expected format for this field is a base64 encoded X509_PEM and it conflicts with `publicKeyType` and `privateKeyType`.
PublicKeyData pulumi.StringPtrInput
// The output format of the public key requested. TYPE_X509_PEM_FILE is the default output format.
PublicKeyType pulumi.StringPtrInput
// The Service account id of the Key. This can be a string in the format
// `{ACCOUNT}` or `projects/{PROJECT_ID}/serviceAccounts/{ACCOUNT}`, where `{ACCOUNT}` is the email address or
// unique id of the service account. If the `{ACCOUNT}` syntax is used, the project will be inferred from the account.
ServiceAccountId pulumi.StringInput
}
func (KeyArgs) ElementType() reflect.Type {
return reflect.TypeOf((*keyArgs)(nil)).Elem()
}
type KeyInput interface {
pulumi.Input
ToKeyOutput() KeyOutput
ToKeyOutputWithContext(ctx context.Context) KeyOutput
}
func (*Key) ElementType() reflect.Type {
return reflect.TypeOf((*Key)(nil))
}
func (i *Key) ToKeyOutput() KeyOutput {
return i.ToKeyOutputWithContext(context.Background())
}
func (i *Key) ToKeyOutputWithContext(ctx context.Context) KeyOutput {
return pulumi.ToOutputWithContext(ctx, i).(KeyOutput)
}
func (i *Key) ToKeyPtrOutput() KeyPtrOutput {
return i.ToKeyPtrOutputWithContext(context.Background())
}
func (i *Key) ToKeyPtrOutputWithContext(ctx context.Context) KeyPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(KeyPtrOutput)
}
type KeyPtrInput interface {
pulumi.Input
ToKeyPtrOutput() KeyPtrOutput
ToKeyPtrOutputWithContext(ctx context.Context) KeyPtrOutput
}
type keyPtrType KeyArgs
func (*keyPtrType) ElementType() reflect.Type {
return reflect.TypeOf((**Key)(nil))
}
func (i *keyPtrType) ToKeyPtrOutput() KeyPtrOutput {
return i.ToKeyPtrOutputWithContext(context.Background())
}
func (i *keyPtrType) ToKeyPtrOutputWithContext(ctx context.Context) KeyPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(KeyPtrOutput)
}
// KeyArrayInput is an input type that accepts KeyArray and KeyArrayOutput values.
// You can construct a concrete instance of `KeyArrayInput` via:
//
// KeyArray{ KeyArgs{...} }
type KeyArrayInput interface {
pulumi.Input
ToKeyArrayOutput() KeyArrayOutput
ToKeyArrayOutputWithContext(context.Context) KeyArrayOutput
}
type KeyArray []KeyInput
func (KeyArray) ElementType() reflect.Type {
return reflect.TypeOf((*[]*Key)(nil)).Elem()
}
func (i KeyArray) ToKeyArrayOutput() KeyArrayOutput {
return i.ToKeyArrayOutputWithContext(context.Background())
}
func (i KeyArray) ToKeyArrayOutputWithContext(ctx context.Context) KeyArrayOutput {
return pulumi.ToOutputWithContext(ctx, i).(KeyArrayOutput)
}
// KeyMapInput is an input type that accepts KeyMap and KeyMapOutput values.
// You can construct a concrete instance of `KeyMapInput` via:
//
// KeyMap{ "key": KeyArgs{...} }
type KeyMapInput interface {
pulumi.Input
ToKeyMapOutput() KeyMapOutput
ToKeyMapOutputWithContext(context.Context) KeyMapOutput
}
type KeyMap map[string]KeyInput
func (KeyMap) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*Key)(nil)).Elem()
}
func (i KeyMap) ToKeyMapOutput() KeyMapOutput {
return i.ToKeyMapOutputWithContext(context.Background())
}
func (i KeyMap) ToKeyMapOutputWithContext(ctx context.Context) KeyMapOutput {
return pulumi.ToOutputWithContext(ctx, i).(KeyMapOutput)
}
type KeyOutput struct{ *pulumi.OutputState }
func (KeyOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Key)(nil))
}
func (o KeyOutput) ToKeyOutput() KeyOutput {
return o
}
func (o KeyOutput) ToKeyOutputWithContext(ctx context.Context) KeyOutput {
return o
}
func (o KeyOutput) ToKeyPtrOutput() KeyPtrOutput {
return o.ToKeyPtrOutputWithContext(context.Background())
}
func (o KeyOutput) ToKeyPtrOutputWithContext(ctx context.Context) KeyPtrOutput {
return o.ApplyTWithContext(ctx, func(_ context.Context, v Key) *Key {
return &v
}).(KeyPtrOutput)
}
type KeyPtrOutput struct{ *pulumi.OutputState }
func (KeyPtrOutput) ElementType() reflect.Type {
return reflect.TypeOf((**Key)(nil))
}
func (o KeyPtrOutput) ToKeyPtrOutput() KeyPtrOutput {
return o
}
func (o KeyPtrOutput) ToKeyPtrOutputWithContext(ctx context.Context) KeyPtrOutput {
return o
}
func (o KeyPtrOutput) Elem() KeyOutput {
return o.ApplyT(func(v *Key) Key {
if v != nil {
return *v
}
var ret Key
return ret
}).(KeyOutput)
}
type KeyArrayOutput struct{ *pulumi.OutputState }
func (KeyArrayOutput) ElementType() reflect.Type {
return reflect.TypeOf((*[]Key)(nil))
}
func (o KeyArrayOutput) ToKeyArrayOutput() KeyArrayOutput {
return o
}
func (o KeyArrayOutput) ToKeyArrayOutputWithContext(ctx context.Context) KeyArrayOutput {
return o
}
func (o KeyArrayOutput) Index(i pulumi.IntInput) KeyOutput {
return pulumi.All(o, i).ApplyT(func(vs []interface{}) Key {
return vs[0].([]Key)[vs[1].(int)]
}).(KeyOutput)
}
type KeyMapOutput struct{ *pulumi.OutputState }
func (KeyMapOutput) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]Key)(nil))
}
func (o KeyMapOutput) ToKeyMapOutput() KeyMapOutput {
return o
}
func (o KeyMapOutput) ToKeyMapOutputWithContext(ctx context.Context) KeyMapOutput {
return o
}
func (o KeyMapOutput) MapIndex(k pulumi.StringInput) KeyOutput {
return pulumi.All(o, k).ApplyT(func(vs []interface{}) Key {
return vs[0].(map[string]Key)[vs[1].(string)]
}).(KeyOutput)
}
func init() {
pulumi.RegisterOutputType(KeyOutput{})
pulumi.RegisterOutputType(KeyPtrOutput{})
pulumi.RegisterOutputType(KeyArrayOutput{})
pulumi.RegisterOutputType(KeyMapOutput{})
}