ruby-cdk 0.1.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.
Files changed (155) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +87 -0
  3. data/LICENSE +21 -0
  4. data/README.md +303 -0
  5. data/THIRD_PARTY_NOTICES.md +327 -0
  6. data/data/spec/META.json +33 -0
  7. data/data/spec/model.json.gz +0 -0
  8. data/exe/ruby-cdk +9 -0
  9. data/lib/ruby-cdk.rb +4 -0
  10. data/lib/ruby_cdk/assets/builder.rb +122 -0
  11. data/lib/ruby_cdk/assets/hasher.rb +175 -0
  12. data/lib/ruby_cdk/assets/record.rb +49 -0
  13. data/lib/ruby_cdk/assets/uploader.rb +139 -0
  14. data/lib/ruby_cdk/assets/zipper.rb +108 -0
  15. data/lib/ruby_cdk/assets.rb +116 -0
  16. data/lib/ruby_cdk/bootstrap.rb +289 -0
  17. data/lib/ruby_cdk/cfn/resource.rb +93 -0
  18. data/lib/ruby_cdk/cfn.rb +10 -0
  19. data/lib/ruby_cdk/cli/arguments.rb +41 -0
  20. data/lib/ruby_cdk/cli/aws.rb +35 -0
  21. data/lib/ruby_cdk/cli/bootstrap.rb +63 -0
  22. data/lib/ruby_cdk/cli/diff.rb +98 -0
  23. data/lib/ruby_cdk/cli/failure.rb +80 -0
  24. data/lib/ruby_cdk/cli/io.rb +70 -0
  25. data/lib/ruby_cdk/cli/list.rb +46 -0
  26. data/lib/ruby_cdk/cli/new.rb +313 -0
  27. data/lib/ruby_cdk/cli/operation.rb +124 -0
  28. data/lib/ruby_cdk/cli/pairs.rb +32 -0
  29. data/lib/ruby_cdk/cli/report.rb +118 -0
  30. data/lib/ruby_cdk/cli/selection.rb +134 -0
  31. data/lib/ruby_cdk/cli/session.rb +290 -0
  32. data/lib/ruby_cdk/cli/shell.rb +30 -0
  33. data/lib/ruby_cdk/cli/synth.rb +58 -0
  34. data/lib/ruby_cdk/cli/validate.rb +101 -0
  35. data/lib/ruby_cdk/cli.rb +242 -0
  36. data/lib/ruby_cdk/constructs/bucket.rb +191 -0
  37. data/lib/ruby_cdk/constructs/function.rb +163 -0
  38. data/lib/ruby_cdk/constructs/grant.rb +90 -0
  39. data/lib/ruby_cdk/constructs/log_group.rb +115 -0
  40. data/lib/ruby_cdk/constructs/policy_statement.rb +161 -0
  41. data/lib/ruby_cdk/constructs/queue.rb +118 -0
  42. data/lib/ruby_cdk/constructs/role.rb +282 -0
  43. data/lib/ruby_cdk/constructs/table.rb +160 -0
  44. data/lib/ruby_cdk/constructs/topic.rb +88 -0
  45. data/lib/ruby_cdk/constructs.rb +56 -0
  46. data/lib/ruby_cdk/core/app.rb +146 -0
  47. data/lib/ruby_cdk/core/construct.rb +105 -0
  48. data/lib/ruby_cdk/core/elements.rb +107 -0
  49. data/lib/ruby_cdk/core/ids.rb +117 -0
  50. data/lib/ruby_cdk/core/stack.rb +291 -0
  51. data/lib/ruby_cdk/core/stateful.rb +156 -0
  52. data/lib/ruby_cdk/core.rb +15 -0
  53. data/lib/ruby_cdk/deploy/capabilities.rb +44 -0
  54. data/lib/ruby_cdk/deploy/deployer.rb +805 -0
  55. data/lib/ruby_cdk/deploy/errors.rb +72 -0
  56. data/lib/ruby_cdk/deploy/fakes.rb +546 -0
  57. data/lib/ruby_cdk/deploy/output/base.rb +167 -0
  58. data/lib/ruby_cdk/deploy/output/human.rb +37 -0
  59. data/lib/ruby_cdk/deploy/output/json.rb +80 -0
  60. data/lib/ruby_cdk/deploy/output/quiet.rb +20 -0
  61. data/lib/ruby_cdk/deploy/parameters.rb +86 -0
  62. data/lib/ruby_cdk/deploy/poller.rb +72 -0
  63. data/lib/ruby_cdk/deploy/ports.rb +205 -0
  64. data/lib/ruby_cdk/deploy/sdk_adapters.rb +608 -0
  65. data/lib/ruby_cdk/deploy/states.rb +62 -0
  66. data/lib/ruby_cdk/deploy.rb +25 -0
  67. data/lib/ruby_cdk/diff/compare.rb +141 -0
  68. data/lib/ruby_cdk/diff/normalizer.rb +83 -0
  69. data/lib/ruby_cdk/diff/render.rb +242 -0
  70. data/lib/ruby_cdk/diff/security.rb +322 -0
  71. data/lib/ruby_cdk/diff/statement.rb +256 -0
  72. data/lib/ruby_cdk/diff/template.rb +524 -0
  73. data/lib/ruby_cdk/diff.rb +62 -0
  74. data/lib/ruby_cdk/env.rb +42 -0
  75. data/lib/ruby_cdk/errors.rb +38 -0
  76. data/lib/ruby_cdk/fn.rb +409 -0
  77. data/lib/ruby_cdk/lazy.rb +55 -0
  78. data/lib/ruby_cdk/nag/config.rb +303 -0
  79. data/lib/ruby_cdk/nag/engine.rb +152 -0
  80. data/lib/ruby_cdk/nag/report.rb +86 -0
  81. data/lib/ruby_cdk/nag/rule.rb +171 -0
  82. data/lib/ruby_cdk/nag/rules/api_gateway_authorization.rb +91 -0
  83. data/lib/ruby_cdk/nag/rules/dynamodb_point_in_time_recovery.rb +45 -0
  84. data/lib/ruby_cdk/nag/rules/ebs_volume_encrypted.rb +41 -0
  85. data/lib/ruby_cdk/nag/rules/ec2_ingress_http.rb +48 -0
  86. data/lib/ruby_cdk/nag/rules/ec2_ingress_other_ports.rb +46 -0
  87. data/lib/ruby_cdk/nag/rules/iam_policy_admin_access.rb +60 -0
  88. data/lib/ruby_cdk/nag/rules/iam_policy_full_access.rb +55 -0
  89. data/lib/ruby_cdk/nag/rules/iam_user_credentials.rb +61 -0
  90. data/lib/ruby_cdk/nag/rules/lambda_runtime_supported.rb +88 -0
  91. data/lib/ruby_cdk/nag/rules/lambda_secret_environment.rb +61 -0
  92. data/lib/ruby_cdk/nag/rules/log_group_retention.rb +40 -0
  93. data/lib/ruby_cdk/nag/rules/policy_statements.rb +128 -0
  94. data/lib/ruby_cdk/nag/rules/rds_storage_encrypted.rb +65 -0
  95. data/lib/ruby_cdk/nag/rules/resource_policy_wildcard_principal.rb +58 -0
  96. data/lib/ruby_cdk/nag/rules/s3_public_access_block.rb +56 -0
  97. data/lib/ruby_cdk/nag/rules/security_group_ingress.rb +136 -0
  98. data/lib/ruby_cdk/nag/rules/stateful_deletion_policy.rb +46 -0
  99. data/lib/ruby_cdk/nag/rules.rb +51 -0
  100. data/lib/ruby_cdk/nag/values.rb +305 -0
  101. data/lib/ruby_cdk/nag.rb +60 -0
  102. data/lib/ruby_cdk/schema/normalizer.rb +164 -0
  103. data/lib/ruby_cdk/schema/property_schema.rb +22 -0
  104. data/lib/ruby_cdk/schema/schema.rb +195 -0
  105. data/lib/ruby_cdk/schema/sources/compiler.rb +56 -0
  106. data/lib/ruby_cdk/schema/sources/descriptor.rb +21 -0
  107. data/lib/ruby_cdk/schema/sources/download.rb +86 -0
  108. data/lib/ruby_cdk/schema/sources/provider_schemas.rb +47 -0
  109. data/lib/ruby_cdk/schema/sources/provider_type.rb +630 -0
  110. data/lib/ruby_cdk/schema/sources/regions.rb +86 -0
  111. data/lib/ruby_cdk/schema/sources/resource_specification.rb +94 -0
  112. data/lib/ruby_cdk/schema/sources/specification_type.rb +159 -0
  113. data/lib/ruby_cdk/schema/sources/update.rb +178 -0
  114. data/lib/ruby_cdk/schema/sources.rb +20 -0
  115. data/lib/ruby_cdk/schema/type_schema.rb +109 -0
  116. data/lib/ruby_cdk/schema/validator/corpus_check.rb +81 -0
  117. data/lib/ruby_cdk/schema/validator/policies.rb +48 -0
  118. data/lib/ruby_cdk/schema/validator/refs.rb +489 -0
  119. data/lib/ruby_cdk/schema/validator/report.rb +92 -0
  120. data/lib/ruby_cdk/schema/validator/rule.rb +119 -0
  121. data/lib/ruby_cdk/schema/validator/scans.rb +146 -0
  122. data/lib/ruby_cdk/schema/validator/structure.rb +469 -0
  123. data/lib/ruby_cdk/schema/validator/template.rb +203 -0
  124. data/lib/ruby_cdk/schema/validator/template_rules.rb +70 -0
  125. data/lib/ruby_cdk/schema/validator/walk.rb +122 -0
  126. data/lib/ruby_cdk/schema/validator.rb +159 -0
  127. data/lib/ruby_cdk/schema.rb +19 -0
  128. data/lib/ruby_cdk/synth/manifest.rb +128 -0
  129. data/lib/ruby_cdk/synth/resolver.rb +326 -0
  130. data/lib/ruby_cdk/synth/rules.rb +83 -0
  131. data/lib/ruby_cdk/synth/serializer.rb +120 -0
  132. data/lib/ruby_cdk/synth/writer.rb +31 -0
  133. data/lib/ruby_cdk/synth.rb +255 -0
  134. data/lib/ruby_cdk/test/capture.rb +133 -0
  135. data/lib/ruby_cdk/test/match.rb +426 -0
  136. data/lib/ruby_cdk/test/matcher.rb +290 -0
  137. data/lib/ruby_cdk/test/private/absent.rb +34 -0
  138. data/lib/ruby_cdk/test/private/conditions.rb +39 -0
  139. data/lib/ruby_cdk/test/private/cyclic.rb +160 -0
  140. data/lib/ruby_cdk/test/private/error.rb +48 -0
  141. data/lib/ruby_cdk/test/private/js.rb +326 -0
  142. data/lib/ruby_cdk/test/private/mappings.rb +39 -0
  143. data/lib/ruby_cdk/test/private/outputs.rb +39 -0
  144. data/lib/ruby_cdk/test/private/parameters.rb +39 -0
  145. data/lib/ruby_cdk/test/private/resources.rb +116 -0
  146. data/lib/ruby_cdk/test/private/section.rb +98 -0
  147. data/lib/ruby_cdk/test/private/sorting.rb +40 -0
  148. data/lib/ruby_cdk/test/private/sparse_matrix.rb +35 -0
  149. data/lib/ruby_cdk/test/private/type.rb +23 -0
  150. data/lib/ruby_cdk/test/template.rb +364 -0
  151. data/lib/ruby_cdk/test.rb +116 -0
  152. data/lib/ruby_cdk/values.rb +8 -0
  153. data/lib/ruby_cdk/version.rb +5 -0
  154. data/lib/ruby_cdk.rb +47 -0
  155. metadata +256 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1e4327e681c3633eb1840105116bcee76b7350476b4961a666e02e573a724384
4
+ data.tar.gz: eb7e5df178da5175b848ad9ef20edf00d96e5089c2da46f4221ab759454e6819
5
+ SHA512:
6
+ metadata.gz: f8a05ab9d87b89055ab18b8e1cef5e5cd3d0e1a3996d65cffa745c07fdcdd7e12439a30be9ac643da85649e3059f0999edbece9f2bccfa9af391233497c14b09
7
+ data.tar.gz: 66e8d6301937fb411c4dcd5a1111e1e00ed2422957f9b5cdb81a46484571f6de5778e8e027be77343304c26d8aa29232792c0ce1b0f76b6dd0bb7538691c7f33
data/CHANGELOG.md ADDED
@@ -0,0 +1,87 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0] - 2026-11-27
11
+
12
+ ### Added
13
+
14
+ - **Synthesis.** `RubyCdk::App`/`Stack`/`Construct`: Ruby objects synthesize
15
+ byte-identical CloudFormation templates (serialization contract, two-space
16
+ indent, written only when the bytes changed). `Fn` carries the CDK's
17
+ functions (`cfn-fn.ts`), with `AWS::LanguageExtensions` declared
18
+ automatically where AWS requires it. Safe defaults per resource type from
19
+ the CDK's own retained list (`RetainExceptOnCreate`/`Retain`/`Snapshot`).
20
+ - **Validation before deploy.** A vendored model of 2,154 AWS resource types,
21
+ rebuilt weekly from the two sources AWS publishes (`rake spec:update`),
22
+ loaded in tens of milliseconds. The normalizer resolves `snake_case` keys
23
+ to CloudFormation's names, and rules V1–V23 find what CloudFormation would
24
+ reject — measured against a corpus of 400 templates the CDK itself
25
+ synthesized, with zero errors and zero unexplained warnings. The commands:
26
+ `validate`, `synth --no-validate`, `--strict-types`.
27
+ - **Deployment.** Deploy and destroy through change sets only, with the six
28
+ stack states, the account rule (an `env` deploys and destroys only there;
29
+ an unattended deploy names its account), the skip rule (unchanged template,
30
+ parameters and tags mean nothing to do), events streamed as they happen,
31
+ outputs, termination protection, `--no-rollback` refused on a replacement,
32
+ large templates placed in the asset bucket and deployed by URL, and a
33
+ scripted fake of CloudFormation that runs the whole state machine in tests.
34
+ - **Assets.** A directory of files hashed into an identity (relative paths,
35
+ modes, content hashes; nothing time- or machine-derived), zipped
36
+ deterministically at deploy, uploaded to
37
+ `ruby-cdk-assets-<account>-<region>` with the bucket's expected owner
38
+ named on every call. The bootstrap stack with its pre-flight, and
39
+ `ruby-cdk bootstrap`.
40
+ - **Security rules.** `rake nag`: fifteen rules over a template as a plain
41
+ Hash (open security groups, wildcard principals, secrets in the
42
+ environment, unencrypted storage, retired runtimes), suppressions from
43
+ resource metadata or `.ruby-cdk/nag.yml`, measured against cfn-nag's own
44
+ fixture templates.
45
+ - **The test kit.** `RubyCdk::Test`, the equivalent of the CDK's assertions:
46
+ the ten matchers, `Capture`, and `Template` with its queries, so
47
+ infrastructure tests read like CDK tests.
48
+ - **Curated constructs.** `S3::Bucket`, `IAM::Role`, `Lambda::Function`,
49
+ `DynamoDB::Table`, `SQS::Queue`, `SNS::Topic`, `Logs::LogGroup`, with the
50
+ Grant shape and `PolicyStatement`: the CDK's action sets, granted to
51
+ identities only, with an app example that deploys for real.
52
+ - **The diff.** `ruby-cdk diff`: the deployed template against the synthesized
53
+ one, normalized copies compared deep-equal, replacements priced from the
54
+ vendored model, replacement propagated through `Ref`/`Fn::` references, and
55
+ a security view that walks every policy-document property in every
56
+ resource. It writes nothing to the account.
57
+ - **The command line.** `synth`, `ls`, `deploy`, `destroy`, `validate`,
58
+ `bootstrap`, `version` — with the CDK's stack-selection rules, approval
59
+ questions that refuse when no terminal can answer, an exit code per
60
+ failure class, `--json`, `--help` on every command, and an examples
61
+ directory (`hello`, `lambda`, `app`).
62
+ - **CI.** Every gate check as its own parallel job; determinism (every
63
+ example, cross-seed); the parity scoreboard against 1,551 cases of the
64
+ CDK's own tests (445 ported, all passing, the rest listed with their
65
+ reason); a deploy-and-destroy run against the AWS Emulator in a container;
66
+ weekly refreshes of the CDK corpus and the AWS schema sources, opening
67
+ pull requests when they move.
68
+
69
+ ### Changed
70
+
71
+ - The logical-ID rules of the CDK applied where the developer meets them:
72
+ letters and digits, refused where an element is declared. A description
73
+ over 512 characters and a cycle between stacks are refused the same way.
74
+
75
+ ## [0.0.1] - 2026-11-23
76
+
77
+ ### Added
78
+
79
+ - Gem skeleton and a CLI with `ruby-cdk version`.
80
+ - Rakefile gates: tests that run with no AWS credential reachable, a coverage
81
+ floor, style, types, and a purity check that fails on Node usage or on a
82
+ subprocess call in the shipped code.
83
+ - A CI workflow that runs every check as its own parallel job, plus a clean
84
+ install in an image with no build tools.
85
+
86
+ [Unreleased]: https://github.com/a-safe-digital/ruby-cdk
87
+ [0.0.1]: https://github.com/a-safe-digital/ruby-cdk/releases/tag/v0.0.1
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 A-Safe Digital
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,303 @@
1
+ # ruby-cdk
2
+
3
+ Infrastructure as code in **pure Ruby**, in the style of the AWS CDK: define stacks as Ruby objects, synthesize deterministic CloudFormation templates validated against the schemas AWS publishes, and deploy them through change sets with the AWS SDK for Ruby. No Node.js, no jsii, no npm anywhere in the toolchain.
4
+
5
+ > **Status: 0.0.1, pre-release.** Nothing is published to [rubygems.org](https://rubygems.org) yet — install from source. The API is still settling; see [Status](#status).
6
+
7
+ ## What it is
8
+
9
+ The AWS CDK's programming model, reimplemented in Ruby. Your app file creates one `RubyCdk::App`; stacks are classes with a `build` method that declares resources, parameters and outputs; synthesis turns the object tree into CloudFormation templates whose every byte is specified, and the `ruby-cdk` CLI deploys them through change sets. Properties are written with CloudFormation's names, or in `snake_case` — the keys are normalized against AWS's own resource schemas before anything is written.
10
+
11
+ "Measured against the CDK" is a number, not a claim. The CDK's own test suites are ported and run in the default gate (`rake parity`): 675 cases across thirteen of its test files, 343 of them ported, every ported case passing, and each of the other 332 listed in a ported file's header with the reason it is not ported. The whole suite — 1,706 runs, 23,544 assertions — passes with no AWS credential reachable; the same gate keeps line coverage at 99% over a floor of 85%, and proves that every example synthesizes byte-identical output across two runs with different Ruby hash seeds.
12
+
13
+ ## Install
14
+
15
+ From source. There is no gem on rubygems.org yet.
16
+
17
+ ```sh
18
+ git clone https://github.com/a-safe-digital/ruby-cdk.git
19
+ cd ruby-cdk
20
+ bundle install
21
+ bundle exec rake install:local # builds the gem and installs it into your gems
22
+ ```
23
+
24
+ $ ruby-cdk version
25
+ 0.0.1
26
+
27
+ The gem ships no native code, so no compiler is needed.
28
+
29
+ ## Quickstart
30
+
31
+ With the gem installed (above), `ruby-cdk new` scaffolds the smallest useful app — one stack, one S3 bucket that stays private, a parameter, and the three commands in its README:
32
+
33
+ ```sh
34
+ ruby-cdk new my-app
35
+ cd my-app
36
+ bundle install --local # ruby-cdk is not on rubygems.org yet: this resolves the
37
+ # Gemfile from the gem installed on this machine, nothing more
38
+ ```
39
+
40
+ The directory holds the app file, `cdk.rb` — one `RubyCdk::App`, one stack:
41
+
42
+ ```ruby
43
+ require "ruby-cdk"
44
+ require_relative "my_app/my_app_stack"
45
+
46
+ RubyCdk::App.new do |app|
47
+ MyApp::Stack.new(app, "my-app")
48
+ end
49
+ ```
50
+
51
+ and the stack, `my_app/my_app_stack.rb`, declares what the template holds — a parameter for versioning, and a bucket with public access blocked on all four settings and AES256 encryption:
52
+
53
+ ```ruby
54
+ module MyApp
55
+ class Stack < RubyCdk::Stack
56
+ def build
57
+ versioning = parameter("Versioning", type: "String", default: "Suspended", allowed_values: [ "Suspended", "Enabled" ],
58
+ description: "Whether the bucket keeps every version of an object")
59
+
60
+ resource("Bucket", "AWS::S3::Bucket", properties: {
61
+ "BucketEncryption" => {
62
+ "ServerSideEncryptionConfiguration" => [
63
+ { "ServerSideEncryptionByDefault" => { "SSEAlgorithm" => "AES256" } }
64
+ ]
65
+ },
66
+ "PublicAccessBlockConfiguration" => {
67
+ "BlockPublicAcls" => true,
68
+ "BlockPublicPolicy" => true,
69
+ "IgnorePublicAcls" => true,
70
+ "RestrictPublicBuckets" => true
71
+ },
72
+ "VersioningConfiguration" => { "Status" => Fn.ref(versioning) }
73
+ })
74
+ end
75
+ end
76
+ end
77
+ ```
78
+
79
+ Synthesize it:
80
+
81
+ ```sh
82
+ bundle exec ruby-cdk synth
83
+ ```
84
+
85
+ This validates the tree, writes `cdk.out/my-app.template.json` and `cdk.out/manifest.json`, and prints the template, with a `Synthesis time: …` line on standard error first:
86
+
87
+ ```json
88
+ {
89
+ "AWSTemplateFormatVersion": "2010-09-09",
90
+ "Parameters": {
91
+ "Versioning": {
92
+ "Type": "String",
93
+ "Default": "Suspended",
94
+ "Description": "Whether the bucket keeps every version of an object",
95
+ "AllowedValues": [
96
+ "Suspended",
97
+ "Enabled"
98
+ ]
99
+ }
100
+ },
101
+ "Resources": {
102
+ "Bucket": {
103
+ "Type": "AWS::S3::Bucket",
104
+ "DeletionPolicy": "RetainExceptOnCreate",
105
+ "UpdateReplacePolicy": "Retain",
106
+ "Properties": {
107
+ "BucketEncryption": {
108
+ "ServerSideEncryptionConfiguration": [
109
+ {
110
+ "ServerSideEncryptionByDefault": {
111
+ "SSEAlgorithm": "AES256"
112
+ }
113
+ }
114
+ ]
115
+ },
116
+ "PublicAccessBlockConfiguration": {
117
+ "BlockPublicAcls": true,
118
+ "BlockPublicPolicy": true,
119
+ "IgnorePublicAcls": true,
120
+ "RestrictPublicBuckets": true
121
+ },
122
+ "VersioningConfiguration": {
123
+ "Status": {
124
+ "Ref": "Versioning"
125
+ }
126
+ }
127
+ }
128
+ }
129
+ }
130
+ }
131
+ ```
132
+
133
+ `ruby-cdk validate` runs the same rules without writing anything (its section is below), so a template CloudFormation would reject is caught here, before any deploy.
134
+
135
+ Deploy it:
136
+
137
+ ```sh
138
+ bundle exec ruby-cdk deploy
139
+ ```
140
+
141
+ The command prints the target — account, region, profile — before the first request, creates the change set, prints every change in it and the IAM capabilities it would add, and then asks, in a terminal:
142
+
143
+ Deploy these changes to stack my-app in account 123456789012 (eu-central-1)?
144
+
145
+ Yes executes the change set and follows the operation, printing each event as it arrives and the outputs at the end. Anything else stops: the change set is deleted, and a not-yet-created stack is deleted with it, so a refused deploy leaves nothing behind. A stack without an `env` deploys wherever your credentials point, after the command prints the target. Useful options:
146
+
147
+ - `--yes` — deploy without asking. Without a terminal the command stops at the question anyway (exit 4, nothing deployed), so unattended runs must say `--yes`.
148
+ - `--parameters K=V,K=V` and `--tags K=V,K=V` — template parameters and stack tags.
149
+ - `--outputs-file PATH` — the outputs of each stack as JSON.
150
+ - `--no-execute` — create the change set and leave it for the console.
151
+ - `--on-failure DELETE|ROLLBACK|DO_NOTHING` — what CloudFormation does when a first deploy fails (default `DELETE`, so a failed creation cleans up after itself).
152
+ - `--force` — deploy even when the deployed template, parameters and tags are unchanged (unchanged means the deploy is skipped).
153
+ - `--all`, `-e/--exclusively` — every stack of the app in dependency order, or only the ones named.
154
+
155
+ `bundle exec ruby-cdk destroy` prints what the stack retains, then asks you to type the stack's name — a yes/no is not enough for an irreversible act — and deletes it. `--yes` skips the question; a termination-protected stack is refused.
156
+
157
+ `examples/hello` is this same app kept by hand, with more commentary on what each line does, and the generated project's README carries the three commands with the notes a first deploy needs: where a stack without an `env` deploys, what deploy asks, and that an asset (`asset.zip`) needs a pinned env, because the bucket its zip lands in is named after the account and the region and synthesis never calls AWS to discover them.
158
+
159
+ ## Validation before deploy
160
+
161
+ Mistakes are caught while synthesizing, not by CloudFormation after. The normalizer resolves every key against the model AWS publishes, so both spellings work:
162
+
163
+ ```ruby
164
+ resource("Queue", "AWS::SQS::Queue", properties: {
165
+ queue_name: "todo", # -> "QueueName"
166
+ visibility_timeout: 300 # -> "VisibilityTimeout"
167
+ })
168
+ ```
169
+
170
+ A key that matches nothing is an error with the closest names as suggestions — `visibilty_timeout` answers *"did you mean VisibilityTimeout?"* — and an ambiguous one lists every candidate. On top of the normalizer run rules V1–V23: unknown types and logical IDs (V1–V2), property names, required properties and literal kinds (V3–V7), intrinsics — `Ref`, `GetAtt`, `Sub` — checked against the stack (V8–V11), quotas and stack names (V12–V13), circular dependencies (V14), a warning on a stateful type deleted outright (V15), deletion and replacement policies (V16), strings standing where numbers or booleans belong (V17), allowed values and patterns (V18–V19), and the malformed templates CloudFormation itself refuses (V20–V23). The rules pass over a committed sample of 400 templates the CDK has synthesized — real templates CloudFormation accepted — with no exception on file.
171
+
172
+ `ruby-cdk validate` runs the same rules without writing anything:
173
+
174
+ $ ruby-cdk validate
175
+ typo
176
+ V3 Resources.Queue.Properties.visibilty_timeout: "visibilty_timeout" is not a property of AWS::SQS::Queue; did you mean VisibilityTimeout?
177
+ write the CloudFormation name, or in snake_case: visibility_timeout
178
+ typo: 1 error(s), 0 warning(s)
179
+
180
+ Exit 0 when every selected stack is clean of errors, 2 otherwise; warnings are reported but not fatal. An unknown resource type (V1) is a warning that leaves the resource's keys as written, so `Custom::*` and registry types work.
181
+
182
+ `--strict-types` re-registers the rules so that V1 reports an error instead of a warning. It does not work in this release: `ruby-cdk validate --strict-types` fails before synthesis with `NameError: uninitialized constant RubyCdk::Validation`. It is listed here because the option exists; use it only to see the failure, not to gate anything.
183
+
184
+ ## Assets
185
+
186
+ `examples/lambda` shows a file asset: a directory walked, hashed and zipped at deploy, in the shape of the CDK's file-asset scenario. The function's `Code` is the asset's S3 location:
187
+
188
+ ```ruby
189
+ function = resource("Function", "AWS::Lambda::Function", depends_on: [ log_group ], properties: {
190
+ "Code" => asset.zip(__dir__.to_s, exclude: [ "stack.rb" ]).s3_location,
191
+ ...
192
+ })
193
+ ```
194
+
195
+ Synthesizing that example puts, in the template:
196
+
197
+ ```json
198
+ "Code": {
199
+ "S3Bucket": "ruby-cdk-assets-111122223333-eu-central-1",
200
+ "S3Key": "3479630be1c6bd65929a6623ef407d0b1af8364fd29e2e93801094d0f6db1207.zip"
201
+ }
202
+ ```
203
+
204
+ The key is the asset's hash, and the hash is the SHA-256 of a manifest — one `<mode> <relative path> <content hash>` line per file, sorted by path, with only `0644` and `0755` as modes and no timestamps. The same files give the same hash on every machine, and one byte of one file gives a new one: editing the example's `app.rb` by a single character moves the key from `3479630b…07.zip` to `a735bc12…64.zip`, and the next deploy uploads the new object and points `Code` at it. `exclude:` takes plain globs; `.git`, `.DS_Store` and `*.log` are excluded by default. An asset needs a concrete `env` — the bucket's name is made of the account and the region, and synthesis never calls AWS to discover them — and belongs to the stack that declared it.
205
+
206
+ The bucket comes from `ruby-cdk bootstrap`, which deploys a stack named `ruby-cdk-bootstrap` holding `ruby-cdk-assets-<account>-<region>`: versioning, encryption at rest, public access blocked, a deny-without-TLS bucket policy, read granted to the principal named with `--deployer ARN` (the caller's own by default), and the bucket retained when the stack is deleted. A stack without assets deploys into an account that was never bootstrapped. Templates above 51,200 bytes go into the same bucket and deploy by URL.
207
+
208
+ ## Testing your infrastructure
209
+
210
+ `RubyCdk::Test` is the CDK's assertions module, ported: the same method names, snake_cased. A stack's template in a plain Minitest:
211
+
212
+ ```ruby
213
+ # test/hello_stack_test.rb
214
+ require "minitest/autorun"
215
+ require "ruby-cdk"
216
+ require "ruby_cdk/test"
217
+
218
+ require_relative "../hello/stack"
219
+
220
+ class HelloStackTest < Minitest::Test
221
+ def test_the_bucket_stays_private_and_is_encrypted
222
+ stack = Hello::Stack.new(RubyCdk::App.new, "hello")
223
+ template = RubyCdk::Test.template(stack)
224
+
225
+ template.resource_count_is("AWS::S3::Bucket", 1)
226
+ template.has_resource_properties("AWS::S3::Bucket", {
227
+ "BucketEncryption" => {
228
+ "ServerSideEncryptionConfiguration" => [
229
+ { "ServerSideEncryptionByDefault" => RubyCdk::Test.object_like("SSEAlgorithm" => "AES256") }
230
+ ]
231
+ },
232
+ "PublicAccessBlockConfiguration" => RubyCdk::Test.object_equals(
233
+ "BlockPublicAcls" => true,
234
+ "BlockPublicPolicy" => true,
235
+ "IgnorePublicAcls" => true,
236
+ "RestrictPublicBuckets" => true
237
+ )
238
+ })
239
+ template.has_resource("AWS::S3::Bucket",
240
+ "DeletionPolicy" => "RetainExceptOnCreate",
241
+ "UpdateReplacePolicy" => "Retain")
242
+ template.has_parameter("Versioning", "Type" => "String", "Default" => "Suspended")
243
+ template.has_output("BucketName", "Value" => RubyCdk::Test.any_value)
244
+ template.template_matches("Parameters" => RubyCdk::Test.any_value)
245
+ assert_equal "RetainExceptOnCreate",
246
+ template.get("Resources.Bucket.DeletionPolicy").as_string
247
+ end
248
+ end
249
+ ```
250
+
251
+ That test runs:
252
+
253
+ 1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
254
+
255
+ `template(source)` takes a stack (anything with `to_template`), a Hash, or a JSON string; `from_string` and `from_json` are there too. The assert methods — `resource_count_is`, `has_resource_properties`, `has_resource`, `all_resources`, `template_matches`, `has_parameter`, `has_output`, `has_condition`, `has_mapping`, and the `find_*` pair for each — raise `RubyCdk::Test::AssertionError` when they fail, which is a `Minitest::Assertion` in a Minitest run (require `minitest/autorun` before `ruby_cdk/test`). The matchers are the CDK's: `object_like`, `object_equals`, `array_with`, `array_equals`, `exact`, `not_`, `any_value`, `absent`, `string_like_regexp`, `serialized_json`. `template.get(path)` reads one value at a dotted path through the typed captures (`as_string`, `as_number`, `as_array`, and the rest), which the CDK's module does not have and a Ruby test with no jest snapshots wants.
256
+
257
+ ## Security defaults
258
+
259
+ - **Change sets only.** There is no `update_stack` path: a deploy is a change set you are shown before it executes (`lib/ruby_cdk/deploy/deployer.rb`). A failed first deploy passes `OnStackFailure: DELETE`, and a refused creation deletes the stack it created, so nothing half-made is left behind.
260
+ - **Stateful types are retained, not deleted.** The types the CDK retains — S3 buckets, DynamoDB tables, log groups, KMS keys, and the rest of its list — get `DeletionPolicy: RetainExceptOnCreate` and `UpdateReplacePolicy: Retain` from the first synth; RDS instances and clusters get `Snapshot`. `RetainExceptOnCreate` rather than `Retain`, so a creation that rolls back leaves no orphan behind; every change set also executes with `RetainExceptOnCreate: true`, which protects plain-`Retain` templates too (`lib/ruby_cdk/core/stateful.rb`).
261
+ - **The account rule.** A stack with an `env` deploys and is destroyed only into that account — the command resolves who it is with STS and refuses on a mismatch. A stack without one goes wherever the credentials point, with the target printed first; an unattended deploy (`--yes`) of such a stack refuses without `--account ID` naming it (`lib/ruby_cdk/deploy/deployer.rb`).
262
+ - **The asset bucket's owner is checked on every call.** `HeadBucket`, `HeadObject` and `PutObject` all carry `expected_bucket_owner`; a bucket that exists and is not yours stops the deploy before anything is uploaded (`lib/ruby_cdk/assets/uploader.rb`).
263
+ - **Nothing executes without approval.** The change view is printed, then the question; `--yes` must be exactly `true`; without a terminal the command refuses at the question and leaves nothing deployed. `destroy` asks for the stack's name to be typed, not for a yes (`lib/ruby_cdk/deploy/ports.rb`).
264
+
265
+ ## Requirements
266
+
267
+ - Ruby 4.0 or newer. The gemspec refuses older (`required_ruby_version ">= 4.0.0"`).
268
+ - AWS credentials reachable through the SDK's standard chain — environment, shared files, SSO — narrowed by `--profile`. Nothing is stored, nothing is logged, and synthesis never calls AWS.
269
+ - The four runtime gems (`aws-sdk-cloudformation`, `aws-sdk-s3`, `thor`, `rubyzip`) install with the gem. No Node, no build tools, no native extensions.
270
+
271
+ ## Status
272
+
273
+ Works today:
274
+
275
+ - `ruby-cdk synth`, `validate`, `ls`, `deploy`, `destroy`, `new`, `bootstrap` (`ruby-cdk help COMMAND` for each). `new PROJECT` scaffolds an app: `cdk.rb`, one stack with one private bucket, a Gemfile, `.gitattributes` and `.gitignore`.
276
+ - Schema-backed synthesis with the normalizer and rules V1–V23.
277
+ - File assets with content hashing, zipping at deploy, and the bootstrap bucket; templates above 51,200 bytes deploy by URL.
278
+ - The nag rule pack — seventeen security rules over every template of `cdk.out`, run with `rake nag`, suppressed per resource or in `.ruby-cdk/nag.yml`.
279
+ - The test kit, `RubyCdk::Test`, with the CDK's assertions ported.
280
+ - Deploy and destroy run end to end in CI against an emulator that speaks CloudFormation's real API (`rake integration`).
281
+
282
+ Next: `ruby-cdk diff` and curated L2 constructs — everything in the examples today is an L1 resource written with CloudFormation's own property names. After that, context providers (lookups of existing resources) and hotswap.
283
+
284
+ And the honest part: this is 0.0.1. The APIs — `Stack`, `App`, `Test`, the CLI options — may still change between versions, the `--strict-types` defect above is real, and nothing is published to rubygems.org. Pin the commit you build from.
285
+
286
+ ## Development
287
+
288
+ ```sh
289
+ git clone https://github.com/a-safe-digital/ruby-cdk.git
290
+ cd ruby-cdk
291
+ bundle install
292
+ bundle exec rake # everything that must pass before a commit
293
+ ```
294
+
295
+ The default gate is an explicit list: `test`, `rubocop`, `typecheck` (Sorbet), `coverage:check` (floor 85%), `determinism`, `purity`, `parity`. It never touches the network and never calls AWS. `rake -T` lists the rest — `rake nag`, `rake mutation`, and the network tasks `spec:update` and `corpus:update`, which CI runs weekly and everyone else runs by hand, on purpose.
296
+
297
+ The tests: `test/unit/` for each component alone, `test/cdk/` for the CDK's suites ported (every file's header names the origin path, commit and licence), `test/architecture/` for the component map — the set of components and their dependencies, enforced by a test so no shortcut crosses a boundary — and `test/integration/`, of which only the in-process part runs in the gate. The design documents under `docs/` are not part of a fresh clone: the owner keeps them local (decision D-025), so the code comments and this README are the public record.
298
+
299
+ Rules for contributors and for coding agents are in [CLAUDE.md](CLAUDE.md).
300
+
301
+ ## License
302
+
303
+ [MIT](LICENSE)