/
cloudformationinclude.go
560 lines (493 loc) · 16 KB
/
cloudformationinclude.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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
package cloudformationinclude
import (
_init_ "github.com/aws/aws-cdk-go/awscdk/jsii"
_jsii_ "github.com/aws/jsii-runtime-go/runtime"
"github.com/aws/aws-cdk-go/awscdk"
"github.com/aws/aws-cdk-go/awscdk/cloudformationinclude/internal"
"github.com/aws/constructs-go/constructs/v3"
)
// Construct to import an existing CloudFormation template file into a CDK application.
//
// All resources defined in the template file can be retrieved by calling the {@link getResource} method.
// Any modifications made on the returned resource objects will be reflected in the resulting CDK template.
//
// Example:
// cfnTemplate := cfn_inc.NewCfnInclude(this, jsii.String("Template"), &cfnIncludeProps{
// templateFile: jsii.String("my-template.json"),
// })
//
// Experimental.
type CfnInclude interface {
awscdk.CfnElement
// Returns: the stack trace of the point where this Resource was created from, sourced
// from the +metadata+ entry typed +aws:cdk:logicalId+, and with the bottom-most
// node +internal+ entries filtered.
// Experimental.
CreationStack() *[]*string
// The logical ID for this CloudFormation stack element.
//
// The logical ID of the element
// is calculated from the path of the resource node in the construct tree.
//
// To override this value, use `overrideLogicalId(newLogicalId)`.
//
// Returns: the logical ID as a stringified token. This value will only get
// resolved during synthesis.
// Experimental.
LogicalId() *string
// The construct tree node associated with this construct.
// Experimental.
Node() awscdk.ConstructNode
// The stack in which this element is defined.
//
// CfnElements must be defined within a stack scope (directly or indirectly).
// Experimental.
Stack() awscdk.Stack
// Returns the CfnCondition object from the 'Conditions' section of the CloudFormation template with the given name.
//
// Any modifications performed on that object will be reflected in the resulting CDK template.
//
// If a Condition with the given name is not present in the template,
// throws an exception.
// Experimental.
GetCondition(conditionName *string) awscdk.CfnCondition
// Returns the CfnHook object from the 'Hooks' section of the included CloudFormation template with the given logical ID.
//
// Any modifications performed on the returned object will be reflected in the resulting CDK template.
//
// If a Hook with the given logical ID is not present in the template,
// an exception will be thrown.
// Experimental.
GetHook(hookLogicalId *string) awscdk.CfnHook
// Returns the CfnMapping object from the 'Mappings' section of the included template.
//
// Any modifications performed on that object will be reflected in the resulting CDK template.
//
// If a Mapping with the given name is not present in the template,
// an exception will be thrown.
// Experimental.
GetMapping(mappingName *string) awscdk.CfnMapping
// Returns a loaded NestedStack with name logicalId.
//
// For a nested stack to be returned by this method,
// it must be specified either in the {@link CfnIncludeProps.loadNestedStacks} property,
// or through the {@link loadNestedStack} method.
// Experimental.
GetNestedStack(logicalId *string) *IncludedNestedStack
// Returns the CfnOutput object from the 'Outputs' section of the included template.
//
// Any modifications performed on that object will be reflected in the resulting CDK template.
//
// If an Output with the given name is not present in the template,
// throws an exception.
// Experimental.
GetOutput(logicalId *string) awscdk.CfnOutput
// Returns the CfnParameter object from the 'Parameters' section of the included template.
//
// Any modifications performed on that object will be reflected in the resulting CDK template.
//
// If a Parameter with the given name is not present in the template,
// throws an exception.
// Experimental.
GetParameter(parameterName *string) awscdk.CfnParameter
// Returns the low-level CfnResource from the template with the given logical ID.
//
// Any modifications performed on that resource will be reflected in the resulting CDK template.
//
// The returned object will be of the proper underlying class;
// you can always cast it to the correct type in your code:
//
// // assume the template contains an AWS::S3::Bucket with logical ID 'Bucket'
// const cfnBucket = cfnTemplate.getResource('Bucket') as s3.CfnBucket;
// // cfnBucket is of type s3.CfnBucket
//
// If the template does not contain a resource with the given logical ID,
// an exception will be thrown.
// Experimental.
GetResource(logicalId *string) awscdk.CfnResource
// Returns the CfnRule object from the 'Rules' section of the CloudFormation template with the given name.
//
// Any modifications performed on that object will be reflected in the resulting CDK template.
//
// If a Rule with the given name is not present in the template,
// an exception will be thrown.
// Experimental.
GetRule(ruleName *string) awscdk.CfnRule
// Includes a template for a child stack inside of this parent template.
//
// A child with this logical ID must exist in the template,
// and be of type AWS::CloudFormation::Stack.
// This is equivalent to specifying the value in the {@link CfnIncludeProps.loadNestedStacks}
// property on object construction.
//
// Returns: the same {@link IncludedNestedStack} object that {@link getNestedStack} returns for this logical ID.
// Experimental.
LoadNestedStack(logicalId *string, nestedStackProps *CfnIncludeProps) *IncludedNestedStack
// Perform final modifications before synthesis.
//
// This method can be implemented by derived constructs in order to perform
// final changes before synthesis. prepare() will be called after child
// constructs have been prepared.
//
// This is an advanced framework feature. Only use this if you
// understand the implications.
// Experimental.
OnPrepare()
// Allows this construct to emit artifacts into the cloud assembly during synthesis.
//
// This method is usually implemented by framework-level constructs such as `Stack` and `Asset`
// as they participate in synthesizing the cloud assembly.
// Experimental.
OnSynthesize(session constructs.ISynthesisSession)
// Validate the current construct.
//
// This method can be implemented by derived constructs in order to perform
// validation logic. It is called on all constructs before synthesis.
//
// Returns: An array of validation error messages, or an empty array if the construct is valid.
// Experimental.
OnValidate() *[]*string
// Overrides the auto-generated logical ID with a specific ID.
// Experimental.
OverrideLogicalId(newLogicalId *string)
// Perform final modifications before synthesis.
//
// This method can be implemented by derived constructs in order to perform
// final changes before synthesis. prepare() will be called after child
// constructs have been prepared.
//
// This is an advanced framework feature. Only use this if you
// understand the implications.
// Experimental.
Prepare()
// Allows this construct to emit artifacts into the cloud assembly during synthesis.
//
// This method is usually implemented by framework-level constructs such as `Stack` and `Asset`
// as they participate in synthesizing the cloud assembly.
// Experimental.
Synthesize(session awscdk.ISynthesisSession)
// Returns a string representation of this construct.
// Experimental.
ToString() *string
// Validate the current construct.
//
// This method can be implemented by derived constructs in order to perform
// validation logic. It is called on all constructs before synthesis.
//
// Returns: An array of validation error messages, or an empty array if the construct is valid.
// Experimental.
Validate() *[]*string
}
// The jsii proxy struct for CfnInclude
type jsiiProxy_CfnInclude struct {
internal.Type__awscdkCfnElement
}
func (j *jsiiProxy_CfnInclude) CreationStack() *[]*string {
var returns *[]*string
_jsii_.Get(
j,
"creationStack",
&returns,
)
return returns
}
func (j *jsiiProxy_CfnInclude) LogicalId() *string {
var returns *string
_jsii_.Get(
j,
"logicalId",
&returns,
)
return returns
}
func (j *jsiiProxy_CfnInclude) Node() awscdk.ConstructNode {
var returns awscdk.ConstructNode
_jsii_.Get(
j,
"node",
&returns,
)
return returns
}
func (j *jsiiProxy_CfnInclude) Stack() awscdk.Stack {
var returns awscdk.Stack
_jsii_.Get(
j,
"stack",
&returns,
)
return returns
}
// Experimental.
func NewCfnInclude(scope constructs.Construct, id *string, props *CfnIncludeProps) CfnInclude {
_init_.Initialize()
j := jsiiProxy_CfnInclude{}
_jsii_.Create(
"monocdk.cloudformation_include.CfnInclude",
[]interface{}{scope, id, props},
&j,
)
return &j
}
// Experimental.
func NewCfnInclude_Override(c CfnInclude, scope constructs.Construct, id *string, props *CfnIncludeProps) {
_init_.Initialize()
_jsii_.Create(
"monocdk.cloudformation_include.CfnInclude",
[]interface{}{scope, id, props},
c,
)
}
// Returns `true` if a construct is a stack element (i.e. part of the synthesized cloudformation template).
//
// Uses duck-typing instead of `instanceof` to allow stack elements from different
// versions of this library to be included in the same stack.
//
// Returns: The construct as a stack element or undefined if it is not a stack element.
// Experimental.
func CfnInclude_IsCfnElement(x interface{}) *bool {
_init_.Initialize()
var returns *bool
_jsii_.StaticInvoke(
"monocdk.cloudformation_include.CfnInclude",
"isCfnElement",
[]interface{}{x},
&returns,
)
return returns
}
// Return whether the given object is a Construct.
// Experimental.
func CfnInclude_IsConstruct(x interface{}) *bool {
_init_.Initialize()
var returns *bool
_jsii_.StaticInvoke(
"monocdk.cloudformation_include.CfnInclude",
"isConstruct",
[]interface{}{x},
&returns,
)
return returns
}
func (c *jsiiProxy_CfnInclude) GetCondition(conditionName *string) awscdk.CfnCondition {
var returns awscdk.CfnCondition
_jsii_.Invoke(
c,
"getCondition",
[]interface{}{conditionName},
&returns,
)
return returns
}
func (c *jsiiProxy_CfnInclude) GetHook(hookLogicalId *string) awscdk.CfnHook {
var returns awscdk.CfnHook
_jsii_.Invoke(
c,
"getHook",
[]interface{}{hookLogicalId},
&returns,
)
return returns
}
func (c *jsiiProxy_CfnInclude) GetMapping(mappingName *string) awscdk.CfnMapping {
var returns awscdk.CfnMapping
_jsii_.Invoke(
c,
"getMapping",
[]interface{}{mappingName},
&returns,
)
return returns
}
func (c *jsiiProxy_CfnInclude) GetNestedStack(logicalId *string) *IncludedNestedStack {
var returns *IncludedNestedStack
_jsii_.Invoke(
c,
"getNestedStack",
[]interface{}{logicalId},
&returns,
)
return returns
}
func (c *jsiiProxy_CfnInclude) GetOutput(logicalId *string) awscdk.CfnOutput {
var returns awscdk.CfnOutput
_jsii_.Invoke(
c,
"getOutput",
[]interface{}{logicalId},
&returns,
)
return returns
}
func (c *jsiiProxy_CfnInclude) GetParameter(parameterName *string) awscdk.CfnParameter {
var returns awscdk.CfnParameter
_jsii_.Invoke(
c,
"getParameter",
[]interface{}{parameterName},
&returns,
)
return returns
}
func (c *jsiiProxy_CfnInclude) GetResource(logicalId *string) awscdk.CfnResource {
var returns awscdk.CfnResource
_jsii_.Invoke(
c,
"getResource",
[]interface{}{logicalId},
&returns,
)
return returns
}
func (c *jsiiProxy_CfnInclude) GetRule(ruleName *string) awscdk.CfnRule {
var returns awscdk.CfnRule
_jsii_.Invoke(
c,
"getRule",
[]interface{}{ruleName},
&returns,
)
return returns
}
func (c *jsiiProxy_CfnInclude) LoadNestedStack(logicalId *string, nestedStackProps *CfnIncludeProps) *IncludedNestedStack {
var returns *IncludedNestedStack
_jsii_.Invoke(
c,
"loadNestedStack",
[]interface{}{logicalId, nestedStackProps},
&returns,
)
return returns
}
func (c *jsiiProxy_CfnInclude) OnPrepare() {
_jsii_.InvokeVoid(
c,
"onPrepare",
nil, // no parameters
)
}
func (c *jsiiProxy_CfnInclude) OnSynthesize(session constructs.ISynthesisSession) {
_jsii_.InvokeVoid(
c,
"onSynthesize",
[]interface{}{session},
)
}
func (c *jsiiProxy_CfnInclude) OnValidate() *[]*string {
var returns *[]*string
_jsii_.Invoke(
c,
"onValidate",
nil, // no parameters
&returns,
)
return returns
}
func (c *jsiiProxy_CfnInclude) OverrideLogicalId(newLogicalId *string) {
_jsii_.InvokeVoid(
c,
"overrideLogicalId",
[]interface{}{newLogicalId},
)
}
func (c *jsiiProxy_CfnInclude) Prepare() {
_jsii_.InvokeVoid(
c,
"prepare",
nil, // no parameters
)
}
func (c *jsiiProxy_CfnInclude) Synthesize(session awscdk.ISynthesisSession) {
_jsii_.InvokeVoid(
c,
"synthesize",
[]interface{}{session},
)
}
func (c *jsiiProxy_CfnInclude) ToString() *string {
var returns *string
_jsii_.Invoke(
c,
"toString",
nil, // no parameters
&returns,
)
return returns
}
func (c *jsiiProxy_CfnInclude) Validate() *[]*string {
var returns *[]*string
_jsii_.Invoke(
c,
"validate",
nil, // no parameters
&returns,
)
return returns
}
// Construction properties of {@link CfnInclude}.
//
// Example:
// parentTemplate := cfn_inc.NewCfnInclude(this, jsii.String("ParentStack"), &cfnIncludeProps{
// templateFile: jsii.String("path/to/my-parent-template.json"),
// loadNestedStacks: map[string]*cfnIncludeProps{
// "ChildStack": &cfnIncludeProps{
// "templateFile": jsii.String("path/to/my-nested-template.json"),
// },
// },
// })
//
// Experimental.
type CfnIncludeProps struct {
// Path to the template file.
//
// Both JSON and YAML template formats are supported.
// Experimental.
TemplateFile *string `field:"required" json:"templateFile" yaml:"templateFile"`
// Specifies the template files that define nested stacks that should be included.
//
// If your template specifies a stack that isn't included here, it won't be created as a NestedStack
// resource, and it won't be accessible from the {@link CfnInclude.getNestedStack} method
// (but will still be accessible from the {@link CfnInclude.getResource} method).
//
// If you include a stack here with an ID that isn't in the template,
// or is in the template but is not a nested stack,
// template creation will fail and an error will be thrown.
// Experimental.
LoadNestedStacks *map[string]*CfnIncludeProps `field:"optional" json:"loadNestedStacks" yaml:"loadNestedStacks"`
// Specifies parameters to be replaced by the values in this mapping.
//
// Any parameters in the template that aren't specified here will be left unmodified.
// If you include a parameter here with an ID that isn't in the template,
// template creation will fail and an error will be thrown.
// Experimental.
Parameters *map[string]interface{} `field:"optional" json:"parameters" yaml:"parameters"`
// Whether the resources should have the same logical IDs in the resulting CDK template as they did in the original CloudFormation template file.
//
// If you're vending a Construct using an existing CloudFormation template,
// make sure to pass this as `false`.
//
// **Note**: regardless of whether this option is true or false,
// the {@link CfnInclude.getResource} and related methods always uses the original logical ID of the resource/element,
// as specified in the template file.
// Experimental.
PreserveLogicalIds *bool `field:"optional" json:"preserveLogicalIds" yaml:"preserveLogicalIds"`
}
// The type returned from {@link CfnInclude.getNestedStack}. Contains both the NestedStack object and CfnInclude representations of the child stack.
//
// Example:
// var parentTemplate cfnInclude
//
//
// includedChildStack := parentTemplate.getNestedStack(jsii.String("ChildStack"))
// childStack := includedChildStack.stack
// childTemplate := includedChildStack.includedTemplate
//
// Experimental.
type IncludedNestedStack struct {
// The CfnInclude that represents the template, which can be used to access Resources and other template elements.
// Experimental.
IncludedTemplate CfnInclude `field:"required" json:"includedTemplate" yaml:"includedTemplate"`
// The NestedStack object which represents the scope of the template.
// Experimental.
Stack awscdk.NestedStack `field:"required" json:"stack" yaml:"stack"`
}