ruby-cdk 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +253 -0
- data/README.md +28 -5
- data/lib/ruby_cdk/assets/hasher.rb +4 -0
- data/lib/ruby_cdk/assets.rb +4 -8
- data/lib/ruby_cdk/cli/aws.rb +23 -5
- data/lib/ruby_cdk/cli/drift.rb +94 -0
- data/lib/ruby_cdk/cli/import.rb +306 -0
- data/lib/ruby_cdk/cli/lookup.rb +214 -0
- data/lib/ruby_cdk/cli/session.rb +114 -3
- data/lib/ruby_cdk/cli/watch.rb +297 -0
- data/lib/ruby_cdk/cli.rb +76 -1
- data/lib/ruby_cdk/constructs/function.rb +24 -3
- data/lib/ruby_cdk/constructs/hosted_zone.rb +342 -0
- data/lib/ruby_cdk/constructs/record_set.rb +330 -0
- data/lib/ruby_cdk/constructs/ssm_parameter.rb +174 -0
- data/lib/ruby_cdk/constructs/vpc.rb +822 -0
- data/lib/ruby_cdk/constructs/vpc_network.rb +159 -0
- data/lib/ruby_cdk/constructs.rb +5 -1
- data/lib/ruby_cdk/core/app.rb +28 -2
- data/lib/ruby_cdk/core/construct.rb +2 -0
- data/lib/ruby_cdk/core/context.rb +138 -0
- data/lib/ruby_cdk/core/stack.rb +4 -0
- data/lib/ruby_cdk/core.rb +1 -0
- data/lib/ruby_cdk/deploy/deployer.rb +283 -8
- data/lib/ruby_cdk/deploy/drift.rb +389 -0
- data/lib/ruby_cdk/deploy/ec2_adapter.rb +214 -0
- data/lib/ruby_cdk/deploy/errors.rb +8 -0
- data/lib/ruby_cdk/deploy/fakes.rb +230 -22
- data/lib/ruby_cdk/deploy/output/base.rb +8 -0
- data/lib/ruby_cdk/deploy/output/json.rb +7 -0
- data/lib/ruby_cdk/deploy/poller.rb +10 -0
- data/lib/ruby_cdk/deploy/ports.rb +124 -8
- data/lib/ruby_cdk/deploy/sdk_adapters.rb +141 -6
- data/lib/ruby_cdk/deploy/ssm_adapter.rb +111 -0
- data/lib/ruby_cdk/deploy.rb +1 -0
- data/lib/ruby_cdk/diff/compare.rb +1 -1
- data/lib/ruby_cdk/diff/identity_center.rb +64 -0
- data/lib/ruby_cdk/diff/render.rb +147 -8
- data/lib/ruby_cdk/diff/security.rb +195 -10
- data/lib/ruby_cdk/diff/security_group.rb +94 -0
- data/lib/ruby_cdk/nag/rules/security_group_ingress.rb +2 -0
- data/lib/ruby_cdk/schema/sources/provider_type.rb +3 -0
- data/lib/ruby_cdk/test/private/cyclic.rb +4 -0
- data/lib/ruby_cdk/test/private/js.rb +1 -3
- data/lib/ruby_cdk/version.rb +1 -1
- metadata +43 -1
|
@@ -17,7 +17,8 @@ module RubyCdk
|
|
|
17
17
|
# get_template, stack_parameters and stack_tags from it;
|
|
18
18
|
# - creating a change set brings a new stack into REVIEW_IN_PROGRESS;
|
|
19
19
|
# - executing a change set ends in the status the test chose
|
|
20
|
-
# (execute_result), CREATE_COMPLETE or UPDATE_COMPLETE
|
|
20
|
+
# (execute_result), CREATE_COMPLETE, IMPORT_COMPLETE or UPDATE_COMPLETE
|
|
21
|
+
# by the kind of it; an import's resources join the stack's own;
|
|
21
22
|
# - deleting a stack ends in DELETE_COMPLETE.
|
|
22
23
|
#
|
|
23
24
|
# client = Fakes::CfnClient.new
|
|
@@ -38,12 +39,12 @@ module RubyCdk
|
|
|
38
39
|
|
|
39
40
|
# A stack as the fake keeps it.
|
|
40
41
|
Record = Struct.new(:name, :id, :status, :template, :parameters, :tags, :outputs, :termination_protection, :events,
|
|
41
|
-
:resources, keyword_init: true)
|
|
42
|
+
:resources, :notification_arns, :rollback_configuration, keyword_init: true)
|
|
42
43
|
|
|
43
44
|
# A change set as the fake keeps it. empty marks one CloudFormation would
|
|
44
45
|
# refuse: created for a stack whose template is already the new one.
|
|
45
46
|
ChangeSetRecord = Struct.new(:id, :type, :template, :template_url, :parameters, :tags, :capabilities, :on_stack_failure,
|
|
46
|
-
:empty, keyword_init: true)
|
|
47
|
+
:notification_arns, :rollback_configuration, :import_existing_resources, :resources_to_import, :empty, keyword_init: true)
|
|
47
48
|
|
|
48
49
|
# The CloudFormation port, scripted.
|
|
49
50
|
class CfnClient
|
|
@@ -53,6 +54,17 @@ module RubyCdk
|
|
|
53
54
|
REGION = "eu-west-1"
|
|
54
55
|
STACK_TYPE = "AWS::CloudFormation::Stack"
|
|
55
56
|
|
|
57
|
+
# The identifier property sets of the resource types the import cases
|
|
58
|
+
# bring, as CloudFormation answers GetTemplateSummary's
|
|
59
|
+
# ResourceIdentifierSummaries for them.
|
|
60
|
+
IDENTIFIER_SETS = {
|
|
61
|
+
"AWS::S3::Bucket" => [ [ "BucketName" ] ],
|
|
62
|
+
"AWS::SQS::Queue" => [ [ "QueueName" ] ],
|
|
63
|
+
"AWS::DynamoDB::Table" => [ [ "TableName" ] ],
|
|
64
|
+
"AWS::DynamoDB::GlobalTable" => [ [ "TableName" ], [ "TableArn" ], [ "TableStreamArn" ] ],
|
|
65
|
+
"AWS::Route53::KeySigningKey" => [ [ "HostedZoneId", "Name" ] ]
|
|
66
|
+
}.freeze
|
|
67
|
+
|
|
56
68
|
attr_reader :calls, :executions, :identity
|
|
57
69
|
# { change set id => ChangeSetRecord }, in the order they were created.
|
|
58
70
|
attr_reader :change_sets
|
|
@@ -65,6 +77,8 @@ module RubyCdk
|
|
|
65
77
|
@calls = []
|
|
66
78
|
@change_sets = {}
|
|
67
79
|
@executions = []
|
|
80
|
+
@drifts = {}
|
|
81
|
+
@drifts_by_detection_id = {}
|
|
68
82
|
@tick = 0
|
|
69
83
|
@execute_result = nil
|
|
70
84
|
end
|
|
@@ -83,12 +97,13 @@ module RubyCdk
|
|
|
83
97
|
# Registers a stack as CloudFormation describes it. Registering a name
|
|
84
98
|
# again keeps its ID and its events.
|
|
85
99
|
def stack(name, status: "CREATE_COMPLETE", template: nil, parameters: {}, tags: [], outputs: {}, termination_protection: false,
|
|
86
|
-
resources: [], id: nil)
|
|
100
|
+
resources: [], notification_arns: [], rollback_configuration: nil, id: nil)
|
|
87
101
|
old = lookup(name)
|
|
88
102
|
@stacks[name] = Record.new(
|
|
89
103
|
name: name, id: id || old&.id || "arn:aws:cloudformation:#{REGION}:#{ACCOUNT}:stack/#{name}/id-#{next_number}",
|
|
90
104
|
status: status, template: template, parameters: parameters, tags: tags, outputs: outputs,
|
|
91
|
-
termination_protection: termination_protection, events: old&.events || [], resources: resources
|
|
105
|
+
termination_protection: termination_protection, events: old&.events || [], resources: resources,
|
|
106
|
+
notification_arns: notification_arns, rollback_configuration: kept_rollback_configuration(rollback_configuration)
|
|
92
107
|
)
|
|
93
108
|
self
|
|
94
109
|
end
|
|
@@ -111,6 +126,21 @@ module RubyCdk
|
|
|
111
126
|
self
|
|
112
127
|
end
|
|
113
128
|
|
|
129
|
+
# Registers a stack's drift answers. detection_id is what
|
|
130
|
+
# detect_stack_drift answers; statuses are what
|
|
131
|
+
# describe_stack_drift_detection_status answers, consumed in order with
|
|
132
|
+
# the last repeating, which is what a poll needs -- hashes of the fields
|
|
133
|
+
# of DriftDetectionStatus; resources are what
|
|
134
|
+
# describe_stack_resource_drifts answers, hashes of the fields of
|
|
135
|
+
# ResourceDrift. A stack registered without one gets the defaults: an
|
|
136
|
+
# ID of its own, a completed detection, no drift.
|
|
137
|
+
def drift(name, detection_id: "drift-detection-#{next_number}",
|
|
138
|
+
statuses: [ { detection_status: "DETECTION_COMPLETE" } ], resources: [])
|
|
139
|
+
stack(name) unless lookup(name)
|
|
140
|
+
record_drift(name, detection_id, statuses, resources)
|
|
141
|
+
self
|
|
142
|
+
end
|
|
143
|
+
|
|
114
144
|
# --- what the engine did
|
|
115
145
|
|
|
116
146
|
# The operations, in the order they were called.
|
|
@@ -164,10 +194,12 @@ module RubyCdk
|
|
|
164
194
|
end
|
|
165
195
|
|
|
166
196
|
def create_change_set(name, change_set_name, template:, change_set_type:, parameters:, tags:, capabilities:,
|
|
167
|
-
on_stack_failure: nil, template_url: nil
|
|
197
|
+
on_stack_failure: nil, template_url: nil, notification_arns: nil, rollback_configuration: nil,
|
|
198
|
+
import_existing_resources: false, resources_to_import: nil)
|
|
168
199
|
scripted(:create_change_set, name, change_set_name, template: template, change_set_type: change_set_type,
|
|
169
200
|
parameters: parameters, tags: tags, capabilities: capabilities, on_stack_failure: on_stack_failure,
|
|
170
|
-
template_url: template_url
|
|
201
|
+
template_url: template_url, notification_arns: notification_arns, rollback_configuration: rollback_configuration,
|
|
202
|
+
import_existing_resources: import_existing_resources, resources_to_import: resources_to_import) do
|
|
171
203
|
id = "arn:aws:cloudformation:#{REGION}:#{ACCOUNT}:changeSet/#{change_set_name}/#{next_number}"
|
|
172
204
|
record = lookup(name)
|
|
173
205
|
# CloudFormation refuses a change set that would change nothing: the
|
|
@@ -179,23 +211,43 @@ module RubyCdk
|
|
|
179
211
|
# answer scripts it.
|
|
180
212
|
new_parameters = pairs_of(parameters, record)
|
|
181
213
|
unchanged = template_url.nil? && change_set_type == :update && record && record.template == template &&
|
|
182
|
-
new_parameters == (record.parameters || {}) && tags == (record.tags || [])
|
|
214
|
+
new_parameters == (record.parameters || {}) && tags == (record.tags || []) &&
|
|
215
|
+
same_notification_arns?(record, notification_arns)
|
|
183
216
|
@change_sets[id] = ChangeSetRecord.new(id: id, type: change_set_type, template: template, template_url: template_url,
|
|
184
|
-
parameters: new_parameters, tags: tags, capabilities: capabilities,
|
|
185
|
-
|
|
186
|
-
|
|
217
|
+
parameters: new_parameters, tags: tags, capabilities: capabilities, on_stack_failure: on_stack_failure,
|
|
218
|
+
notification_arns: notification_arns, rollback_configuration: rollback_configuration,
|
|
219
|
+
import_existing_resources: import_existing_resources, resources_to_import: resources_to_import, empty: unchanged)
|
|
220
|
+
# A change set brings a stack into existence only when there is
|
|
221
|
+
# none: a CREATE change set always, an IMPORT change set for a
|
|
222
|
+
# stack that does not exist yet, never one on a stack it would
|
|
223
|
+
# import into.
|
|
224
|
+
bring_into_review(name, template, parameters, tags, notification_arns) if change_set_type == :create ||
|
|
225
|
+
(change_set_type == :import && (record.nil? || record.status == StackStatus::DELETED))
|
|
187
226
|
ChangeSet.new(id: id)
|
|
188
227
|
end
|
|
189
228
|
end
|
|
190
229
|
|
|
230
|
+
# The identifier property sets of the types the template uses: the
|
|
231
|
+
# table below, or a scripted answer. The table carries the types the
|
|
232
|
+
# tests import; CloudFormation knows every type it takes.
|
|
233
|
+
def resource_identifier_summaries(template)
|
|
234
|
+
scripted(:resource_identifier_summaries, template) do
|
|
235
|
+
IDENTIFIER_SETS.map do |type, sets|
|
|
236
|
+
ResourceIdentifierSummary.new(type: type, identifier_sets: sets)
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
|
|
191
241
|
# The direct update of --hotswap. CloudFormation refuses an update that
|
|
192
242
|
# would change nothing (the CDK's direct deployment matches the words
|
|
193
243
|
# of the refusal), so the fake refuses one whose template and
|
|
194
244
|
# parameters and tags are already the stack's. A test that wants
|
|
195
245
|
# another answer scripts it.
|
|
196
|
-
def update_stack(name, template:, parameters:, tags:, capabilities:, template_url: nil
|
|
246
|
+
def update_stack(name, template:, parameters:, tags:, capabilities:, template_url: nil, notification_arns: nil,
|
|
247
|
+
rollback_configuration: nil)
|
|
197
248
|
scripted(:update_stack, name, template: template, template_url: template_url, parameters: parameters,
|
|
198
|
-
tags: tags, capabilities: capabilities
|
|
249
|
+
tags: tags, capabilities: capabilities, notification_arns: notification_arns,
|
|
250
|
+
rollback_configuration: rollback_configuration) do
|
|
199
251
|
record = lookup(name)
|
|
200
252
|
new_parameters = pairs_of(parameters, record)
|
|
201
253
|
if template_url.nil? && record && record.template == template &&
|
|
@@ -206,6 +258,8 @@ module RubyCdk
|
|
|
206
258
|
record.template = template if template
|
|
207
259
|
record.parameters = new_parameters
|
|
208
260
|
record.tags = tags
|
|
261
|
+
record.notification_arns = notification_arns || record.notification_arns
|
|
262
|
+
record.rollback_configuration = kept_rollback_configuration(rollback_configuration) || record.rollback_configuration
|
|
209
263
|
record.status = "UPDATE_COMPLETE"
|
|
210
264
|
nil
|
|
211
265
|
end
|
|
@@ -226,6 +280,15 @@ module RubyCdk
|
|
|
226
280
|
elsif change_set.empty
|
|
227
281
|
ChangeSet.new(id: change_set_id, status: "FAILED",
|
|
228
282
|
status_reason: "The submitted information didn't contain changes.", changes: [])
|
|
283
|
+
elsif change_set.type == :import
|
|
284
|
+
# An import's changes are its imports, as CloudFormation
|
|
285
|
+
# describes them: one Import action per resource, its logical
|
|
286
|
+
# id and its type.
|
|
287
|
+
ChangeSet.new(id: change_set_id, status: "CREATE_COMPLETE", execution_status: "AVAILABLE",
|
|
288
|
+
changes: (change_set.resources_to_import || []).map do |import|
|
|
289
|
+
Change.new(action: "Import", logical_id: import.logical_resource_id, resource_type: import.resource_type,
|
|
290
|
+
replacement: nil, detail: nil)
|
|
291
|
+
end)
|
|
229
292
|
else
|
|
230
293
|
ChangeSet.new(id: change_set_id, status: "CREATE_COMPLETE", execution_status: "AVAILABLE",
|
|
231
294
|
changes: [ Change.new(action: change_set.type == :update ? "Modify" : "Add", logical_id: "Bucket",
|
|
@@ -245,7 +308,12 @@ module RubyCdk
|
|
|
245
308
|
record.template = change_set.template
|
|
246
309
|
record.parameters = change_set.parameters
|
|
247
310
|
record.tags = change_set.tags
|
|
248
|
-
record.
|
|
311
|
+
record.notification_arns = change_set.notification_arns || record.notification_arns
|
|
312
|
+
record.rollback_configuration = kept_rollback_configuration(change_set.rollback_configuration) || record.rollback_configuration
|
|
313
|
+
record.status = @execute_result || default_result_of(change_set)
|
|
314
|
+
Array(change_set.resources_to_import).each do |import|
|
|
315
|
+
adopt(record, import)
|
|
316
|
+
end
|
|
249
317
|
end
|
|
250
318
|
end
|
|
251
319
|
end
|
|
@@ -299,6 +367,45 @@ module RubyCdk
|
|
|
299
367
|
scripted(:operation_events, name, change_set_id) { [] }
|
|
300
368
|
end
|
|
301
369
|
|
|
370
|
+
def detect_stack_drift(name_or_id)
|
|
371
|
+
scripted(:detect_stack_drift, name_or_id) do
|
|
372
|
+
record = lookup(name_or_id)
|
|
373
|
+
unless record
|
|
374
|
+
raise RubyCdk::PreconditionError, "ValidationError: Stack #{name_or_id} does not exist"
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
drift_entry(record).fetch(:detection_id)
|
|
378
|
+
end
|
|
379
|
+
end
|
|
380
|
+
|
|
381
|
+
def describe_stack_drift_detection_status(detection_id)
|
|
382
|
+
scripted(:describe_stack_drift_detection_status, detection_id) do
|
|
383
|
+
entry = @drifts_by_detection_id[detection_id]
|
|
384
|
+
unless entry
|
|
385
|
+
raise RubyCdk::PreconditionError, "ValidationError: There is no drift detection #{detection_id}"
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
answers = entry[:statuses]
|
|
389
|
+
answer = answers[entry[:taken]] || answers.last
|
|
390
|
+
entry[:taken] += 1
|
|
391
|
+
answer.is_a?(Hash) ? DriftDetectionStatus.new(**answer) : answer
|
|
392
|
+
end
|
|
393
|
+
end
|
|
394
|
+
|
|
395
|
+
def describe_stack_resource_drifts(name_or_id)
|
|
396
|
+
scripted(:describe_stack_resource_drifts, name_or_id) do
|
|
397
|
+
record = lookup(name_or_id)
|
|
398
|
+
unless record
|
|
399
|
+
raise RubyCdk::PreconditionError, "ValidationError: Stack #{name_or_id} does not exist"
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
entry = drift_entry(record)
|
|
403
|
+
return nil if entry[:resources].nil?
|
|
404
|
+
|
|
405
|
+
entry[:resources].map { |resource| resource_drift_of(resource) }
|
|
406
|
+
end
|
|
407
|
+
end
|
|
408
|
+
|
|
302
409
|
private
|
|
303
410
|
|
|
304
411
|
# Records the call, answers from the script when there is one, and
|
|
@@ -306,7 +413,7 @@ module RubyCdk
|
|
|
306
413
|
def scripted(operation, *args, **kwargs)
|
|
307
414
|
@calls << Call.new(operation: operation, args: args, kwargs: kwargs)
|
|
308
415
|
queue = @scripts[operation]
|
|
309
|
-
|
|
416
|
+
unless queue.empty?
|
|
310
417
|
answer = queue.length > 1 ? queue.shift : queue.first
|
|
311
418
|
raise answer if answer.is_a?(Exception)
|
|
312
419
|
return answer.call(Call.new(operation: operation, args: args, kwargs: kwargs)) if answer.respond_to?(:call)
|
|
@@ -320,22 +427,76 @@ module RubyCdk
|
|
|
320
427
|
@stacks.each_value.find { |record| record.name == name_or_id || record.id == name_or_id }
|
|
321
428
|
end
|
|
322
429
|
|
|
430
|
+
# The drift entry of a stack's record, made when first asked for.
|
|
431
|
+
def drift_entry(record)
|
|
432
|
+
@drifts[record.name] ||= record_drift(record.name, "drift-detection-#{next_number}",
|
|
433
|
+
[ { detection_status: "DETECTION_COMPLETE" } ], [])
|
|
434
|
+
end
|
|
435
|
+
|
|
436
|
+
def record_drift(name, detection_id, statuses, resources)
|
|
437
|
+
entry = { detection_id: detection_id, statuses: statuses, taken: 0, resources: resources }
|
|
438
|
+
@drifts[name] = entry
|
|
439
|
+
@drifts_by_detection_id[detection_id] = entry
|
|
440
|
+
end
|
|
441
|
+
|
|
442
|
+
# A drift record as the port describes it: the hash a test wrote, or one
|
|
443
|
+
# already built. A record without a status is in sync, which is the
|
|
444
|
+
# answer a plain detection gives.
|
|
445
|
+
def resource_drift_of(resource)
|
|
446
|
+
return resource if resource.is_a?(ResourceDrift)
|
|
447
|
+
|
|
448
|
+
ResourceDrift.new(
|
|
449
|
+
logical_id: resource[:logical_id],
|
|
450
|
+
physical_id: resource[:physical_id],
|
|
451
|
+
resource_type: resource[:resource_type],
|
|
452
|
+
status: resource[:status] || "IN_SYNC",
|
|
453
|
+
status_reason: resource[:status_reason],
|
|
454
|
+
property_differences: (resource[:property_differences] || []).map do |difference|
|
|
455
|
+
difference.is_a?(PropertyDifference) ? difference : PropertyDifference.new(**difference)
|
|
456
|
+
end
|
|
457
|
+
)
|
|
458
|
+
end
|
|
459
|
+
|
|
323
460
|
# A CREATE change set is what brings a stack into existence, with nothing
|
|
324
461
|
# in it yet, as in CloudFormation. A stack that does not exist, or was
|
|
325
462
|
# deleted, comes into being with an ID of its own; one that is already
|
|
326
463
|
# waiting in REVIEW_IN_PROGRESS keeps its ID and takes the new template.
|
|
327
|
-
def bring_into_review(name, template, parameters, tags)
|
|
464
|
+
def bring_into_review(name, template, parameters, tags, notification_arns)
|
|
328
465
|
record = lookup(name)
|
|
329
466
|
fresh = record.nil? || record.status == StackStatus::DELETED
|
|
330
467
|
stack(name, status: "REVIEW_IN_PROGRESS", template: template, parameters: pairs_of(parameters, fresh ? nil : record),
|
|
331
|
-
tags: tags,
|
|
468
|
+
tags: tags, notification_arns: notification_arns || record&.notification_arns || [],
|
|
332
469
|
id: fresh ? "arn:aws:cloudformation:#{REGION}:#{ACCOUNT}:stack/#{name}/id-#{next_number}" : nil,
|
|
333
470
|
outputs: record&.outputs || {}, resources: record&.resources || [])
|
|
334
471
|
end
|
|
335
472
|
|
|
336
473
|
def info_of(record)
|
|
337
474
|
StackInfo.new(name: record.name, id: record.id, status: record.status, outputs: record.outputs,
|
|
338
|
-
termination_protection: record.termination_protection
|
|
475
|
+
termination_protection: record.termination_protection, notification_arns: record.notification_arns || [],
|
|
476
|
+
rollback_configuration: record.rollback_configuration)
|
|
477
|
+
end
|
|
478
|
+
|
|
479
|
+
# The status a stack ends an execution in, when the test chose none:
|
|
480
|
+
# a creation CREATE_COMPLETE, an import IMPORT_COMPLETE, an update
|
|
481
|
+
# UPDATE_COMPLETE.
|
|
482
|
+
def default_result_of(change_set)
|
|
483
|
+
if change_set.type == :create
|
|
484
|
+
"CREATE_COMPLETE"
|
|
485
|
+
elsif change_set.type == :import
|
|
486
|
+
"IMPORT_COMPLETE"
|
|
487
|
+
else
|
|
488
|
+
"UPDATE_COMPLETE"
|
|
489
|
+
end
|
|
490
|
+
end
|
|
491
|
+
|
|
492
|
+
# The resources of an executed import now belong to the stack: one
|
|
493
|
+
# entry each, its physical id the identifier the import named (the
|
|
494
|
+
# values joined when the identifier set is compound).
|
|
495
|
+
def adopt(record, import)
|
|
496
|
+
physical = import.resource_identifier.values.join(",")
|
|
497
|
+
kept = (record.resources || []).reject { |resource| resource.logical_id == import.logical_resource_id }
|
|
498
|
+
record.resources = kept + [ StackResource.new(logical_id: import.logical_resource_id, status: "IMPORT_COMPLETE",
|
|
499
|
+
physical_id: physical) ]
|
|
339
500
|
end
|
|
340
501
|
|
|
341
502
|
# The parameters of a change set as the stack keeps them: { key => value }.
|
|
@@ -352,6 +513,31 @@ module RubyCdk
|
|
|
352
513
|
end.to_h
|
|
353
514
|
end
|
|
354
515
|
|
|
516
|
+
# Whether the change set's NotificationARNs are the stack's, as sets,
|
|
517
|
+
# the way the CDK's engine compares them before it skips a deploy
|
|
518
|
+
# (deploy-stack.ts, arrayEquals). A difference is a change CloudFormation
|
|
519
|
+
# would carry.
|
|
520
|
+
def same_notification_arns?(record, asked)
|
|
521
|
+
deployed = record&.notification_arns || []
|
|
522
|
+
asked = asked || []
|
|
523
|
+
deployed.all? { |arn| asked.include?(arn) } && asked.all? { |arn| deployed.include?(arn) }
|
|
524
|
+
end
|
|
525
|
+
|
|
526
|
+
# A rollback configuration as the stack keeps it: every trigger with
|
|
527
|
+
# its type, the way CloudFormation stores what a request named (the
|
|
528
|
+
# CDK's request conversion names the metric alarm for every trigger
|
|
529
|
+
# its command line gives it).
|
|
530
|
+
def kept_rollback_configuration(config)
|
|
531
|
+
return nil if config.nil?
|
|
532
|
+
|
|
533
|
+
RollbackConfiguration.new(
|
|
534
|
+
triggers: (config.triggers || []).map do |trigger|
|
|
535
|
+
trigger.is_a?(RollbackTrigger) ? trigger : RollbackTrigger.new(arn: trigger, type: RollbackTrigger::ALARM)
|
|
536
|
+
end,
|
|
537
|
+
monitoring_time_in_minutes: config.monitoring_time_in_minutes
|
|
538
|
+
)
|
|
539
|
+
end
|
|
540
|
+
|
|
355
541
|
def refuse_protected(record)
|
|
356
542
|
return unless record.termination_protection
|
|
357
543
|
|
|
@@ -377,7 +563,10 @@ module RubyCdk
|
|
|
377
563
|
# { [ bucket, key ] => body }
|
|
378
564
|
attr_reader :objects
|
|
379
565
|
|
|
380
|
-
|
|
566
|
+
# base_url is where object_url places the bucket: the origin of the
|
|
567
|
+
# endpoint a real client would have been built with.
|
|
568
|
+
def initialize(base_url: "https://s3.#{CfnClient::REGION}.amazonaws.com")
|
|
569
|
+
@base_url = base_url
|
|
381
570
|
@owners = {}
|
|
382
571
|
@objects = {}
|
|
383
572
|
@calls = []
|
|
@@ -409,6 +598,11 @@ module RubyCdk
|
|
|
409
598
|
@objects[[ bucket, key ]] = body
|
|
410
599
|
end
|
|
411
600
|
|
|
601
|
+
def object_url(bucket, key)
|
|
602
|
+
@calls << Call.new(operation: :object_url, args: [ bucket, key ], kwargs: {})
|
|
603
|
+
"#{@base_url}/#{bucket}/#{key}"
|
|
604
|
+
end
|
|
605
|
+
|
|
412
606
|
# The operations, in the order they were called.
|
|
413
607
|
def operations
|
|
414
608
|
calls.map(&:operation)
|
|
@@ -444,12 +638,14 @@ module RubyCdk
|
|
|
444
638
|
|
|
445
639
|
attr_reader :calls
|
|
446
640
|
|
|
447
|
-
# approvals answers ask
|
|
448
|
-
# or an Array consumed in
|
|
449
|
-
|
|
641
|
+
# approvals answers ask, confirmations answers confirm and requests
|
|
642
|
+
# answers request -- true, false, nil, a text, or an Array consumed in
|
|
643
|
+
# order whose last answer repeats.
|
|
644
|
+
def initialize(approvals: false, confirmations: false, requests: nil)
|
|
450
645
|
@calls = []
|
|
451
646
|
@approvals = answers_of(approvals)
|
|
452
647
|
@confirmations = answers_of(confirmations)
|
|
648
|
+
@requests = answers_of(requests)
|
|
453
649
|
end
|
|
454
650
|
|
|
455
651
|
def target(account:, region:, profile:)
|
|
@@ -472,6 +668,12 @@ module RubyCdk
|
|
|
472
668
|
next_answer(@confirmations) == text
|
|
473
669
|
end
|
|
474
670
|
|
|
671
|
+
# The answer is the line that was typed, or nil for nobody there.
|
|
672
|
+
def request(question)
|
|
673
|
+
record(:request, question)
|
|
674
|
+
next_answer(@requests)
|
|
675
|
+
end
|
|
676
|
+
|
|
475
677
|
def event(event)
|
|
476
678
|
record(:event, event)
|
|
477
679
|
end
|
|
@@ -521,6 +723,12 @@ module RubyCdk
|
|
|
521
723
|
said(:confirm).flat_map(&:args)
|
|
522
724
|
end
|
|
523
725
|
|
|
726
|
+
# The free-form questions that were asked, what an import's
|
|
727
|
+
# identifiers are collected through.
|
|
728
|
+
def typed_questions
|
|
729
|
+
said(:request).flat_map(&:args)
|
|
730
|
+
end
|
|
731
|
+
|
|
524
732
|
# The capabilities shown with each change view.
|
|
525
733
|
def shown_capabilities
|
|
526
734
|
said(:changes).map { |call| call.kwargs[:capabilities] }
|
|
@@ -66,6 +66,14 @@ module RubyCdk
|
|
|
66
66
|
read_line == text
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
+
# The line the person typed, or nil when nobody is there to type one.
|
|
70
|
+
def request(question)
|
|
71
|
+
return nil unless interactive?
|
|
72
|
+
|
|
73
|
+
say("#{paint(question, BOLD)} ")
|
|
74
|
+
read_line
|
|
75
|
+
end
|
|
76
|
+
|
|
69
77
|
# One line per event: the time, the status in a column, what it is about,
|
|
70
78
|
# and why when it failed.
|
|
71
79
|
def event(event)
|
|
@@ -35,6 +35,13 @@ module RubyCdk
|
|
|
35
35
|
read_line == text
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
+
def request(question)
|
|
39
|
+
emit(type: "request", question: question)
|
|
40
|
+
return nil unless interactive?
|
|
41
|
+
|
|
42
|
+
read_line
|
|
43
|
+
end
|
|
44
|
+
|
|
38
45
|
def event(event)
|
|
39
46
|
emit(type: "event", event: plain(event.to_h))
|
|
40
47
|
end
|
|
@@ -17,6 +17,10 @@ module RubyCdk
|
|
|
17
17
|
# A stack operation can run for hours. This is the longest the engine follows one.
|
|
18
18
|
OPERATION_LIMIT = 4 * 60 * 60
|
|
19
19
|
|
|
20
|
+
# Drift detection runs on CloudFormation's side; this is the longest the
|
|
21
|
+
# engine waits for one (the CDK's maxWaitForDrift, api/drift/drift.ts:81).
|
|
22
|
+
DRIFT_LIMIT = 300
|
|
23
|
+
|
|
20
24
|
attr_reader :limit
|
|
21
25
|
|
|
22
26
|
# sleep is called with a number of seconds.
|
|
@@ -38,6 +42,12 @@ module RubyCdk
|
|
|
38
42
|
new(interval: 2, factor: 1.5, max_interval: 10, limit: OPERATION_LIMIT)
|
|
39
43
|
end
|
|
40
44
|
|
|
45
|
+
# The CDK's drift wait: a fixed two seconds between status reads
|
|
46
|
+
# (api/drift/drift.ts:83), five minutes all told.
|
|
47
|
+
def self.drift
|
|
48
|
+
new(interval: 2, factor: 1, max_interval: 2, limit: DRIFT_LIMIT)
|
|
49
|
+
end
|
|
50
|
+
|
|
41
51
|
# For tests, which script every answer: it never really waits, and it still
|
|
42
52
|
# gives up, so a test that forgot the last answer fails instead of hanging.
|
|
43
53
|
def self.instant
|
|
@@ -7,9 +7,60 @@ module RubyCdk
|
|
|
7
7
|
Event = Struct.new(:resource_status, :logical_id, :resource_type, :status_reason, :timestamp, keyword_init: true)
|
|
8
8
|
StackResource = Struct.new(:logical_id, :status, :physical_id, keyword_init: true)
|
|
9
9
|
Identity = Struct.new(:account, :region, :arn, keyword_init: true)
|
|
10
|
-
|
|
10
|
+
# notification_arns is what the stack carries as its NotificationARNs; []
|
|
11
|
+
# when it carries none. rollback_configuration is the stack's
|
|
12
|
+
# RollbackConfiguration, or nil when it has none.
|
|
13
|
+
StackInfo = Struct.new(:name, :id, :status, :outputs, :termination_protection, :notification_arns, :rollback_configuration,
|
|
14
|
+
keyword_init: true)
|
|
11
15
|
ListedStack = Struct.new(:name, :id, :status, keyword_init: true)
|
|
12
16
|
|
|
17
|
+
# One entry of GetTemplateSummary's ResourceIdentifierSummaries: a resource
|
|
18
|
+
# type and the property sets that identify an existing one of it for an
|
|
19
|
+
# import. identifier_sets is an array of property-name arrays, one way to
|
|
20
|
+
# identify the resource each: [["QueueName"]],
|
|
21
|
+
# [["TableName"], ["TableArn"], ["TableStreamArn"]],
|
|
22
|
+
# [["HostedZoneId", "Name"]].
|
|
23
|
+
ResourceIdentifierSummary = Struct.new(:type, :identifier_sets, keyword_init: true)
|
|
24
|
+
|
|
25
|
+
# One resource of a change set's ResourcesToImport: the logical id of the
|
|
26
|
+
# resource in the template, its type, and the identifier properties that
|
|
27
|
+
# name the existing physical one, as the CDK builds the entry
|
|
28
|
+
# (api/resource-import/importer.ts:448-454 in aws/aws-cdk-cli).
|
|
29
|
+
ResourceToImport = Struct.new(:logical_resource_id, :resource_type, :resource_identifier, keyword_init: true)
|
|
30
|
+
|
|
31
|
+
# One rollback trigger of a stack, as CloudFormation describes it and as a
|
|
32
|
+
# request names it. type is the type the alarm field carries; the command
|
|
33
|
+
# line's ARNs are all metric alarms, the CDK's default
|
|
34
|
+
# (RollbackTriggerType.ALARM, actions/deploy/index.ts:230-235 in
|
|
35
|
+
# aws/aws-cdk-cli).
|
|
36
|
+
RollbackTrigger = Struct.new(:arn, :type, keyword_init: true)
|
|
37
|
+
|
|
38
|
+
# The type the command line's triggers are sent with.
|
|
39
|
+
RollbackTrigger::ALARM = "AWS::CloudWatch::Alarm"
|
|
40
|
+
|
|
41
|
+
# The rollback configuration of a stack operation: the ARNs of the
|
|
42
|
+
# CloudWatch alarms CloudFormation monitors while the operation runs, at
|
|
43
|
+
# most five of them, and the minutes it keeps watching after it. triggers
|
|
44
|
+
# may be empty, which asks for the triggers on the stack to be cleared;
|
|
45
|
+
# monitoring_time_in_minutes may be nil, which is the field not given.
|
|
46
|
+
RollbackConfiguration = Struct.new(:triggers, :monitoring_time_in_minutes, keyword_init: true)
|
|
47
|
+
|
|
48
|
+
# One property CloudFormation found different on a drifted resource, as
|
|
49
|
+
# DescribeStackResourceDrifts carries it. difference_type is the AWS word:
|
|
50
|
+
# ADD, REMOVE or NOT_EQUAL.
|
|
51
|
+
PropertyDifference = Struct.new(:property_path, :expected_value, :actual_value, :difference_type, keyword_init: true)
|
|
52
|
+
|
|
53
|
+
# One resource of a stack, as drift detection described it. status is the
|
|
54
|
+
# AWS word: IN_SYNC, MODIFIED, DELETED, NOT_CHECKED or UNKNOWN.
|
|
55
|
+
ResourceDrift = Struct.new(:logical_id, :physical_id, :resource_type, :status, :status_reason, :property_differences,
|
|
56
|
+
keyword_init: true)
|
|
57
|
+
|
|
58
|
+
# What drift detection answers while it runs and when it is done.
|
|
59
|
+
# detection_status is DETECTION_IN_PROGRESS, DETECTION_COMPLETE or
|
|
60
|
+
# DETECTION_FAILED; stack_drift_status is the stack's own word (IN_SYNC,
|
|
61
|
+
# DRIFTED, UNKNOWN) and is set only once the detection is complete.
|
|
62
|
+
DriftDetectionStatus = Struct.new(:detection_status, :stack_drift_status, :status_reason, keyword_init: true)
|
|
63
|
+
|
|
13
64
|
# What stack_state answers.
|
|
14
65
|
#
|
|
15
66
|
# :absent no such stack, or DELETE_COMPLETE: create it
|
|
@@ -82,6 +133,14 @@ module RubyCdk
|
|
|
82
133
|
Kernel.raise NotImplementedError
|
|
83
134
|
end
|
|
84
135
|
|
|
136
|
+
# Asks the person to type one line of free text, and answers the line:
|
|
137
|
+
# the physical identifier a resource is imported under, the CDK's
|
|
138
|
+
# free-form question beside ask's yes-or-no (its requestResponse,
|
|
139
|
+
# user-input.ts). nil when nobody is there to type one.
|
|
140
|
+
def request(question)
|
|
141
|
+
Kernel.raise NotImplementedError
|
|
142
|
+
end
|
|
143
|
+
|
|
85
144
|
def event(event)
|
|
86
145
|
Kernel.raise NotImplementedError
|
|
87
146
|
end
|
|
@@ -132,9 +191,32 @@ module RubyCdk
|
|
|
132
191
|
# template is the JSON text of the template, sent inline; template_url,
|
|
133
192
|
# when given, is the URL of the template placed in the bucket, and
|
|
134
193
|
# template is nil then: CloudFormation takes one or the other, never
|
|
135
|
-
# both (architecture §8).
|
|
194
|
+
# both (architecture §8). notification_arns, when given, is the SNS
|
|
195
|
+
# topic ARNs of the request's NotificationARNs; nil leaves the field
|
|
196
|
+
# out, and whatever the stack carries stays. rollback_configuration,
|
|
197
|
+
# when given, is the RollbackConfiguration of the request; nil is the
|
|
198
|
+
# field not given, and the triggers the stack has are left alone.
|
|
199
|
+
# import_existing_resources is the request's ImportExistingResources,
|
|
200
|
+
# sent either way, as the CDK sends it (deploy-stack.ts:640).
|
|
201
|
+
# resources_to_import, when given, is the request's ResourcesToImport,
|
|
202
|
+
# and the request's ChangeSetType is IMPORT because of it -- an import
|
|
203
|
+
# runs as a change set of type IMPORT carrying the list, never as
|
|
204
|
+
# CREATE with the field on (deploy-stack.ts:636-637). It is an Array of
|
|
205
|
+
# ResourceToImport. No import, nil, and the field is not sent.
|
|
136
206
|
def create_change_set(name, change_set_name, template:, change_set_type:, parameters:, tags:, capabilities:, on_stack_failure: nil,
|
|
137
|
-
template_url: nil)
|
|
207
|
+
template_url: nil, notification_arns: nil, rollback_configuration: nil, import_existing_resources: false, resources_to_import: nil)
|
|
208
|
+
Kernel.raise NotImplementedError
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
# The property sets that identify an existing resource of each type the
|
|
212
|
+
# template uses, for an import: GetTemplateSummary's
|
|
213
|
+
# ResourceIdentifierSummaries for the template, the call the CDK's
|
|
214
|
+
# importer asks before it questions anybody
|
|
215
|
+
# (api/deployments/deployments.ts:375-415,
|
|
216
|
+
# api/resource-import/importer.ts:332-341). template is the JSON text
|
|
217
|
+
# of the template to summarize. An Array of ResourceIdentifierSummary,
|
|
218
|
+
# empty when CloudFormation names none.
|
|
219
|
+
def resource_identifier_summaries(template)
|
|
138
220
|
Kernel.raise NotImplementedError
|
|
139
221
|
end
|
|
140
222
|
|
|
@@ -143,17 +225,21 @@ module RubyCdk
|
|
|
143
225
|
# JSON text of the template, sent inline; template_url, when given, is
|
|
144
226
|
# the URL of the template placed in the bucket, and template is nil
|
|
145
227
|
# then: CloudFormation takes one or the other, never both (architecture
|
|
146
|
-
# §8) -- the same contract create_change_set carries
|
|
147
|
-
#
|
|
148
|
-
#
|
|
149
|
-
|
|
228
|
+
# §8) -- the same contract create_change_set carries,
|
|
229
|
+
# notification_arns and rollback_configuration included, which the CDK
|
|
230
|
+
# puts on its UpdateStack too (deploy-stack.ts, commonPrepareOptions).
|
|
231
|
+
# The template is the whole new one: CloudFormation updates what
|
|
232
|
+
# differs and needs the rest to know what to keep.
|
|
233
|
+
def update_stack(name, template:, parameters:, tags:, capabilities:, template_url: nil, notification_arns: nil, rollback_configuration: nil)
|
|
150
234
|
Kernel.raise NotImplementedError
|
|
151
235
|
end
|
|
152
236
|
|
|
153
237
|
# The change set change_set_id names, by its ARN or by its name. One that
|
|
154
238
|
# is not there -- never created, or already deleted -- raises
|
|
155
239
|
# ChangeSetNotFound (errors.rb), which is CloudFormation's own answer and
|
|
156
|
-
# is matched by its class, never by its words.
|
|
240
|
+
# is matched by its class, never by its words. The changes of an import
|
|
241
|
+
# answer as any change set's do: one Change per resource, its action
|
|
242
|
+
# "Import", its logical id and its type.
|
|
157
243
|
def describe_change_set(name, change_set_id)
|
|
158
244
|
Kernel.raise NotImplementedError
|
|
159
245
|
end
|
|
@@ -202,6 +288,27 @@ module RubyCdk
|
|
|
202
288
|
def operation_events(name, change_set_id)
|
|
203
289
|
Kernel.raise NotImplementedError
|
|
204
290
|
end
|
|
291
|
+
|
|
292
|
+
# Asks CloudFormation to start detecting the drift of a stack, and
|
|
293
|
+
# answers the ID the detection runs under. The detection runs on
|
|
294
|
+
# CloudFormation's side; describe_stack_drift_detection_status follows it.
|
|
295
|
+
def detect_stack_drift(name_or_id)
|
|
296
|
+
Kernel.raise NotImplementedError
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
# Where the detection that detection_id names has got to. Called until it
|
|
300
|
+
# answers DETECTION_COMPLETE, or DETECTION_FAILED, which is the end of it.
|
|
301
|
+
def describe_stack_drift_detection_status(detection_id)
|
|
302
|
+
Kernel.raise NotImplementedError
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
# The drift of every resource of the stack, from the last completed
|
|
306
|
+
# detection. Every page, so the list is never truncated: a truncated one
|
|
307
|
+
# would read as resources unchecked, not as resources drifted. nil when
|
|
308
|
+
# CloudFormation holds no drift results for the stack.
|
|
309
|
+
def describe_stack_resource_drifts(name_or_id)
|
|
310
|
+
Kernel.raise NotImplementedError
|
|
311
|
+
end
|
|
205
312
|
end
|
|
206
313
|
|
|
207
314
|
# The port to S3. Every call takes the expected bucket owner.
|
|
@@ -218,6 +325,15 @@ module RubyCdk
|
|
|
218
325
|
def put(bucket, key, body:, expected_owner:)
|
|
219
326
|
Kernel.raise NotImplementedError
|
|
220
327
|
end
|
|
328
|
+
|
|
329
|
+
# The address the store would serve the object back from: the URL a
|
|
330
|
+
# change set carries as TemplateURL (architecture §8). Derived from the
|
|
331
|
+
# client's own region and endpoint configuration, so a partition shows
|
|
332
|
+
# in the host and an overridden endpoint (AWS_ENDPOINT_URL, the
|
|
333
|
+
# emulator) names itself.
|
|
334
|
+
def object_url(bucket, key)
|
|
335
|
+
Kernel.raise NotImplementedError
|
|
336
|
+
end
|
|
221
337
|
end
|
|
222
338
|
end
|
|
223
339
|
end
|