/
secretCiphertext.go
423 lines (367 loc) · 16.1 KB
/
secretCiphertext.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
// 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 kms
import (
"context"
"reflect"
"errors"
"github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/internal"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/pulumi/pulumi/sdk/v3/go/pulumix"
)
// Encrypts secret data with Google Cloud KMS and provides access to the ciphertext.
//
// > **NOTE:** Using this resource will allow you to conceal secret data within your
// resource definitions, but it does not take care of protecting that data in the
// logging output, plan output, or state output. Please take care to secure your secret
// data outside of resource definitions.
//
// To get more information about SecretCiphertext, see:
//
// * [API documentation](https://cloud.google.com/kms/docs/reference/rest/v1/projects.locations.keyRings.cryptoKeys/encrypt)
// * How-to Guides
// - [Encrypting and decrypting data with a symmetric key](https://cloud.google.com/kms/docs/encrypt-decrypt)
//
// > **Warning:** All arguments including `plaintext` and `additionalAuthenticatedData` will be stored in the raw state as plain-text.
//
// ## Example Usage
// ### Kms Secret Ciphertext Basic
//
// ```go
// package main
//
// import (
//
// "github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/compute"
// "github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/kms"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
//
// )
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// keyring, err := kms.NewKeyRing(ctx, "keyring", &kms.KeyRingArgs{
// Location: pulumi.String("global"),
// })
// if err != nil {
// return err
// }
// cryptokey, err := kms.NewCryptoKey(ctx, "cryptokey", &kms.CryptoKeyArgs{
// KeyRing: keyring.ID(),
// RotationPeriod: pulumi.String("100000s"),
// })
// if err != nil {
// return err
// }
// myPassword, err := kms.NewSecretCiphertext(ctx, "myPassword", &kms.SecretCiphertextArgs{
// CryptoKey: cryptokey.ID(),
// Plaintext: pulumi.String("my-secret-password"),
// })
// if err != nil {
// return err
// }
// _, err = compute.NewInstance(ctx, "instance", &compute.InstanceArgs{
// MachineType: pulumi.String("e2-medium"),
// Zone: pulumi.String("us-central1-a"),
// BootDisk: &compute.InstanceBootDiskArgs{
// InitializeParams: &compute.InstanceBootDiskInitializeParamsArgs{
// Image: pulumi.String("debian-cloud/debian-11"),
// },
// },
// NetworkInterfaces: compute.InstanceNetworkInterfaceArray{
// &compute.InstanceNetworkInterfaceArgs{
// Network: pulumi.String("default"),
// AccessConfigs: compute.InstanceNetworkInterfaceAccessConfigArray{
// nil,
// },
// },
// },
// Metadata: pulumi.StringMap{
// "password": myPassword.Ciphertext,
// },
// })
// if err != nil {
// return err
// }
// return nil
// })
// }
//
// ```
//
// ## Import
//
// This resource does not support import.
type SecretCiphertext struct {
pulumi.CustomResourceState
// The additional authenticated data used for integrity checks during encryption and decryption.
// **Note**: This property is sensitive and will not be displayed in the plan.
AdditionalAuthenticatedData pulumi.StringPtrOutput `pulumi:"additionalAuthenticatedData"`
// Contains the result of encrypting the provided plaintext, encoded in base64.
Ciphertext pulumi.StringOutput `pulumi:"ciphertext"`
// The full name of the CryptoKey that will be used to encrypt the provided plaintext.
// Format: `'projects/{{project}}/locations/{{location}}/keyRings/{{keyRing}}/cryptoKeys/{{cryptoKey}}'`
//
// ***
CryptoKey pulumi.StringOutput `pulumi:"cryptoKey"`
// The plaintext to be encrypted.
// **Note**: This property is sensitive and will not be displayed in the plan.
Plaintext pulumi.StringOutput `pulumi:"plaintext"`
}
// NewSecretCiphertext registers a new resource with the given unique name, arguments, and options.
func NewSecretCiphertext(ctx *pulumi.Context,
name string, args *SecretCiphertextArgs, opts ...pulumi.ResourceOption) (*SecretCiphertext, error) {
if args == nil {
return nil, errors.New("missing one or more required arguments")
}
if args.CryptoKey == nil {
return nil, errors.New("invalid value for required argument 'CryptoKey'")
}
if args.Plaintext == nil {
return nil, errors.New("invalid value for required argument 'Plaintext'")
}
if args.AdditionalAuthenticatedData != nil {
args.AdditionalAuthenticatedData = pulumi.ToSecret(args.AdditionalAuthenticatedData).(pulumi.StringPtrInput)
}
if args.Plaintext != nil {
args.Plaintext = pulumi.ToSecret(args.Plaintext).(pulumi.StringInput)
}
secrets := pulumi.AdditionalSecretOutputs([]string{
"additionalAuthenticatedData",
"plaintext",
})
opts = append(opts, secrets)
opts = internal.PkgResourceDefaultOpts(opts)
var resource SecretCiphertext
err := ctx.RegisterResource("gcp:kms/secretCiphertext:SecretCiphertext", name, args, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// GetSecretCiphertext gets an existing SecretCiphertext 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 GetSecretCiphertext(ctx *pulumi.Context,
name string, id pulumi.IDInput, state *SecretCiphertextState, opts ...pulumi.ResourceOption) (*SecretCiphertext, error) {
var resource SecretCiphertext
err := ctx.ReadResource("gcp:kms/secretCiphertext:SecretCiphertext", name, id, state, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// Input properties used for looking up and filtering SecretCiphertext resources.
type secretCiphertextState struct {
// The additional authenticated data used for integrity checks during encryption and decryption.
// **Note**: This property is sensitive and will not be displayed in the plan.
AdditionalAuthenticatedData *string `pulumi:"additionalAuthenticatedData"`
// Contains the result of encrypting the provided plaintext, encoded in base64.
Ciphertext *string `pulumi:"ciphertext"`
// The full name of the CryptoKey that will be used to encrypt the provided plaintext.
// Format: `'projects/{{project}}/locations/{{location}}/keyRings/{{keyRing}}/cryptoKeys/{{cryptoKey}}'`
//
// ***
CryptoKey *string `pulumi:"cryptoKey"`
// The plaintext to be encrypted.
// **Note**: This property is sensitive and will not be displayed in the plan.
Plaintext *string `pulumi:"plaintext"`
}
type SecretCiphertextState struct {
// The additional authenticated data used for integrity checks during encryption and decryption.
// **Note**: This property is sensitive and will not be displayed in the plan.
AdditionalAuthenticatedData pulumi.StringPtrInput
// Contains the result of encrypting the provided plaintext, encoded in base64.
Ciphertext pulumi.StringPtrInput
// The full name of the CryptoKey that will be used to encrypt the provided plaintext.
// Format: `'projects/{{project}}/locations/{{location}}/keyRings/{{keyRing}}/cryptoKeys/{{cryptoKey}}'`
//
// ***
CryptoKey pulumi.StringPtrInput
// The plaintext to be encrypted.
// **Note**: This property is sensitive and will not be displayed in the plan.
Plaintext pulumi.StringPtrInput
}
func (SecretCiphertextState) ElementType() reflect.Type {
return reflect.TypeOf((*secretCiphertextState)(nil)).Elem()
}
type secretCiphertextArgs struct {
// The additional authenticated data used for integrity checks during encryption and decryption.
// **Note**: This property is sensitive and will not be displayed in the plan.
AdditionalAuthenticatedData *string `pulumi:"additionalAuthenticatedData"`
// The full name of the CryptoKey that will be used to encrypt the provided plaintext.
// Format: `'projects/{{project}}/locations/{{location}}/keyRings/{{keyRing}}/cryptoKeys/{{cryptoKey}}'`
//
// ***
CryptoKey string `pulumi:"cryptoKey"`
// The plaintext to be encrypted.
// **Note**: This property is sensitive and will not be displayed in the plan.
Plaintext string `pulumi:"plaintext"`
}
// The set of arguments for constructing a SecretCiphertext resource.
type SecretCiphertextArgs struct {
// The additional authenticated data used for integrity checks during encryption and decryption.
// **Note**: This property is sensitive and will not be displayed in the plan.
AdditionalAuthenticatedData pulumi.StringPtrInput
// The full name of the CryptoKey that will be used to encrypt the provided plaintext.
// Format: `'projects/{{project}}/locations/{{location}}/keyRings/{{keyRing}}/cryptoKeys/{{cryptoKey}}'`
//
// ***
CryptoKey pulumi.StringInput
// The plaintext to be encrypted.
// **Note**: This property is sensitive and will not be displayed in the plan.
Plaintext pulumi.StringInput
}
func (SecretCiphertextArgs) ElementType() reflect.Type {
return reflect.TypeOf((*secretCiphertextArgs)(nil)).Elem()
}
type SecretCiphertextInput interface {
pulumi.Input
ToSecretCiphertextOutput() SecretCiphertextOutput
ToSecretCiphertextOutputWithContext(ctx context.Context) SecretCiphertextOutput
}
func (*SecretCiphertext) ElementType() reflect.Type {
return reflect.TypeOf((**SecretCiphertext)(nil)).Elem()
}
func (i *SecretCiphertext) ToSecretCiphertextOutput() SecretCiphertextOutput {
return i.ToSecretCiphertextOutputWithContext(context.Background())
}
func (i *SecretCiphertext) ToSecretCiphertextOutputWithContext(ctx context.Context) SecretCiphertextOutput {
return pulumi.ToOutputWithContext(ctx, i).(SecretCiphertextOutput)
}
func (i *SecretCiphertext) ToOutput(ctx context.Context) pulumix.Output[*SecretCiphertext] {
return pulumix.Output[*SecretCiphertext]{
OutputState: i.ToSecretCiphertextOutputWithContext(ctx).OutputState,
}
}
// SecretCiphertextArrayInput is an input type that accepts SecretCiphertextArray and SecretCiphertextArrayOutput values.
// You can construct a concrete instance of `SecretCiphertextArrayInput` via:
//
// SecretCiphertextArray{ SecretCiphertextArgs{...} }
type SecretCiphertextArrayInput interface {
pulumi.Input
ToSecretCiphertextArrayOutput() SecretCiphertextArrayOutput
ToSecretCiphertextArrayOutputWithContext(context.Context) SecretCiphertextArrayOutput
}
type SecretCiphertextArray []SecretCiphertextInput
func (SecretCiphertextArray) ElementType() reflect.Type {
return reflect.TypeOf((*[]*SecretCiphertext)(nil)).Elem()
}
func (i SecretCiphertextArray) ToSecretCiphertextArrayOutput() SecretCiphertextArrayOutput {
return i.ToSecretCiphertextArrayOutputWithContext(context.Background())
}
func (i SecretCiphertextArray) ToSecretCiphertextArrayOutputWithContext(ctx context.Context) SecretCiphertextArrayOutput {
return pulumi.ToOutputWithContext(ctx, i).(SecretCiphertextArrayOutput)
}
func (i SecretCiphertextArray) ToOutput(ctx context.Context) pulumix.Output[[]*SecretCiphertext] {
return pulumix.Output[[]*SecretCiphertext]{
OutputState: i.ToSecretCiphertextArrayOutputWithContext(ctx).OutputState,
}
}
// SecretCiphertextMapInput is an input type that accepts SecretCiphertextMap and SecretCiphertextMapOutput values.
// You can construct a concrete instance of `SecretCiphertextMapInput` via:
//
// SecretCiphertextMap{ "key": SecretCiphertextArgs{...} }
type SecretCiphertextMapInput interface {
pulumi.Input
ToSecretCiphertextMapOutput() SecretCiphertextMapOutput
ToSecretCiphertextMapOutputWithContext(context.Context) SecretCiphertextMapOutput
}
type SecretCiphertextMap map[string]SecretCiphertextInput
func (SecretCiphertextMap) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*SecretCiphertext)(nil)).Elem()
}
func (i SecretCiphertextMap) ToSecretCiphertextMapOutput() SecretCiphertextMapOutput {
return i.ToSecretCiphertextMapOutputWithContext(context.Background())
}
func (i SecretCiphertextMap) ToSecretCiphertextMapOutputWithContext(ctx context.Context) SecretCiphertextMapOutput {
return pulumi.ToOutputWithContext(ctx, i).(SecretCiphertextMapOutput)
}
func (i SecretCiphertextMap) ToOutput(ctx context.Context) pulumix.Output[map[string]*SecretCiphertext] {
return pulumix.Output[map[string]*SecretCiphertext]{
OutputState: i.ToSecretCiphertextMapOutputWithContext(ctx).OutputState,
}
}
type SecretCiphertextOutput struct{ *pulumi.OutputState }
func (SecretCiphertextOutput) ElementType() reflect.Type {
return reflect.TypeOf((**SecretCiphertext)(nil)).Elem()
}
func (o SecretCiphertextOutput) ToSecretCiphertextOutput() SecretCiphertextOutput {
return o
}
func (o SecretCiphertextOutput) ToSecretCiphertextOutputWithContext(ctx context.Context) SecretCiphertextOutput {
return o
}
func (o SecretCiphertextOutput) ToOutput(ctx context.Context) pulumix.Output[*SecretCiphertext] {
return pulumix.Output[*SecretCiphertext]{
OutputState: o.OutputState,
}
}
// The additional authenticated data used for integrity checks during encryption and decryption.
// **Note**: This property is sensitive and will not be displayed in the plan.
func (o SecretCiphertextOutput) AdditionalAuthenticatedData() pulumi.StringPtrOutput {
return o.ApplyT(func(v *SecretCiphertext) pulumi.StringPtrOutput { return v.AdditionalAuthenticatedData }).(pulumi.StringPtrOutput)
}
// Contains the result of encrypting the provided plaintext, encoded in base64.
func (o SecretCiphertextOutput) Ciphertext() pulumi.StringOutput {
return o.ApplyT(func(v *SecretCiphertext) pulumi.StringOutput { return v.Ciphertext }).(pulumi.StringOutput)
}
// The full name of the CryptoKey that will be used to encrypt the provided plaintext.
// Format: `'projects/{{project}}/locations/{{location}}/keyRings/{{keyRing}}/cryptoKeys/{{cryptoKey}}'`
//
// ***
func (o SecretCiphertextOutput) CryptoKey() pulumi.StringOutput {
return o.ApplyT(func(v *SecretCiphertext) pulumi.StringOutput { return v.CryptoKey }).(pulumi.StringOutput)
}
// The plaintext to be encrypted.
// **Note**: This property is sensitive and will not be displayed in the plan.
func (o SecretCiphertextOutput) Plaintext() pulumi.StringOutput {
return o.ApplyT(func(v *SecretCiphertext) pulumi.StringOutput { return v.Plaintext }).(pulumi.StringOutput)
}
type SecretCiphertextArrayOutput struct{ *pulumi.OutputState }
func (SecretCiphertextArrayOutput) ElementType() reflect.Type {
return reflect.TypeOf((*[]*SecretCiphertext)(nil)).Elem()
}
func (o SecretCiphertextArrayOutput) ToSecretCiphertextArrayOutput() SecretCiphertextArrayOutput {
return o
}
func (o SecretCiphertextArrayOutput) ToSecretCiphertextArrayOutputWithContext(ctx context.Context) SecretCiphertextArrayOutput {
return o
}
func (o SecretCiphertextArrayOutput) ToOutput(ctx context.Context) pulumix.Output[[]*SecretCiphertext] {
return pulumix.Output[[]*SecretCiphertext]{
OutputState: o.OutputState,
}
}
func (o SecretCiphertextArrayOutput) Index(i pulumi.IntInput) SecretCiphertextOutput {
return pulumi.All(o, i).ApplyT(func(vs []interface{}) *SecretCiphertext {
return vs[0].([]*SecretCiphertext)[vs[1].(int)]
}).(SecretCiphertextOutput)
}
type SecretCiphertextMapOutput struct{ *pulumi.OutputState }
func (SecretCiphertextMapOutput) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*SecretCiphertext)(nil)).Elem()
}
func (o SecretCiphertextMapOutput) ToSecretCiphertextMapOutput() SecretCiphertextMapOutput {
return o
}
func (o SecretCiphertextMapOutput) ToSecretCiphertextMapOutputWithContext(ctx context.Context) SecretCiphertextMapOutput {
return o
}
func (o SecretCiphertextMapOutput) ToOutput(ctx context.Context) pulumix.Output[map[string]*SecretCiphertext] {
return pulumix.Output[map[string]*SecretCiphertext]{
OutputState: o.OutputState,
}
}
func (o SecretCiphertextMapOutput) MapIndex(k pulumi.StringInput) SecretCiphertextOutput {
return pulumi.All(o, k).ApplyT(func(vs []interface{}) *SecretCiphertext {
return vs[0].(map[string]*SecretCiphertext)[vs[1].(string)]
}).(SecretCiphertextOutput)
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*SecretCiphertextInput)(nil)).Elem(), &SecretCiphertext{})
pulumi.RegisterInputType(reflect.TypeOf((*SecretCiphertextArrayInput)(nil)).Elem(), SecretCiphertextArray{})
pulumi.RegisterInputType(reflect.TypeOf((*SecretCiphertextMapInput)(nil)).Elem(), SecretCiphertextMap{})
pulumi.RegisterOutputType(SecretCiphertextOutput{})
pulumi.RegisterOutputType(SecretCiphertextArrayOutput{})
pulumi.RegisterOutputType(SecretCiphertextMapOutput{})
}