cfndsl 0.15.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +3 -0
- data/.rubocop.yml +6 -6
- data/.travis.yml +10 -5
- data/CHANGELOG.md +721 -400
- data/Gemfile +2 -0
- data/README.md +85 -23
- data/Rakefile +28 -6
- data/TODO.md +18 -0
- data/UPGRADING.md +22 -0
- data/cfndsl.gemspec +17 -16
- data/exe/cfndsl +5 -0
- data/lib/cfndsl.rb +3 -113
- data/lib/cfndsl/aws/cloud_formation_template.rb +10 -1
- data/lib/cfndsl/aws/patches/000_CloudFormationResourceSpecification.json +51726 -0
- data/lib/cfndsl/aws/patches/000_sam.spec.json +1242 -0
- data/lib/cfndsl/aws/patches/100_sam.spec_DeploymentPreference_patch.json +64 -0
- data/lib/cfndsl/aws/patches/200_Scrutinies_patch.json +86 -0
- data/lib/cfndsl/aws/patches/500_Cognito_IdentityPoolRoleAttachment_patches.json +25 -0
- data/lib/cfndsl/aws/patches/500_IoT1Click_patch_PlacementTemplate_DeviceTemplates.json +20 -0
- data/lib/cfndsl/aws/patches/500_NetworkAclEntry_patch.json +16 -0
- data/lib/cfndsl/aws/patches/500_SAM_Serverless_Function_S3Event_Events_patch.json +16 -0
- data/lib/cfndsl/aws/patches/500_SAM_Serverless_Function_S3Location_Version_patch.json +16 -0
- data/lib/cfndsl/aws/patches/500_SSM_AssociationName_patch.json +16 -0
- data/lib/cfndsl/aws/patches/500_VPCEndpoint_patch.json +17 -0
- data/lib/cfndsl/aws/patches/510_ElasticSearch_Domain_patches.json +15 -0
- data/lib/cfndsl/aws/patches/520_ServiceDiscovery_InstanceAttributes_patch.json +16 -0
- data/lib/cfndsl/aws/patches/600_RefKinds_patch.json +3654 -0
- data/lib/cfndsl/aws/patches/700_SAM_Serverless_Function_InlineCode_patch.json +20 -0
- data/lib/cfndsl/aws/patches/800_List_types_patch.json +115 -0
- data/lib/cfndsl/aws/resource_specification.json +39955 -9293
- data/lib/cfndsl/aws/types.rb +5 -3
- data/lib/cfndsl/cfnlego.rb +34 -0
- data/lib/{cfnlego → cfndsl/cfnlego}/cloudformation.erb +0 -0
- data/lib/{cfnlego → cfndsl/cfnlego}/cloudformation.rb +3 -1
- data/lib/{cfnlego → cfndsl/cfnlego}/resource.rb +5 -8
- data/lib/cfndsl/cloudformation.rb +114 -0
- data/lib/cfndsl/conditions.rb +13 -1
- data/lib/cfndsl/creation_policy.rb +3 -1
- data/lib/cfndsl/deep_merge.rb +4 -0
- data/lib/cfndsl/external_parameters.rb +12 -13
- data/lib/cfndsl/globals.rb +51 -10
- data/lib/cfndsl/json_serialisable_object.rb +4 -2
- data/lib/cfndsl/jsonable.rb +51 -68
- data/lib/cfndsl/mappings.rb +3 -1
- data/lib/cfndsl/module.rb +18 -5
- data/lib/cfndsl/names.rb +2 -0
- data/lib/cfndsl/orchestration_template.rb +193 -73
- data/lib/cfndsl/outputs.rb +7 -1
- data/lib/cfndsl/parameters.rb +3 -1
- data/lib/cfndsl/plurals.rb +23 -10
- data/lib/cfndsl/properties.rb +3 -1
- data/lib/cfndsl/rake_task.rb +217 -15
- data/lib/cfndsl/ref_check.rb +21 -11
- data/lib/cfndsl/resources.rb +8 -19
- data/lib/cfndsl/rules.rb +46 -0
- data/lib/cfndsl/runner.rb +143 -0
- data/lib/cfndsl/specification.rb +82 -84
- data/lib/cfndsl/types.rb +212 -95
- data/lib/cfndsl/update_policy.rb +3 -1
- data/lib/cfndsl/version.rb +3 -1
- data/lib/deep_merge/core.rb +10 -6
- data/lib/deep_merge/deep_merge.rb +3 -1
- data/sample/autoscale.rb +1 -1
- data/sample/autoscale2.rb +4 -3
- data/sample/circular.rb +2 -0
- data/sample/codedeploy.rb +3 -1
- data/sample/config_service.rb +5 -3
- data/sample/ecs.rb +3 -1
- data/sample/export.rb +5 -3
- data/sample/iam_policies.rb +2 -0
- data/sample/import.rb +4 -2
- data/sample/lambda.rb +3 -1
- data/sample/s3.rb +2 -0
- data/sample/t1.rb +3 -1
- data/sample/vpc_example.rb +3 -1
- data/sample/vpc_with_vpn_example.rb +3 -1
- data/spec/aws/ec2_security_group_spec.rb +2 -0
- data/spec/aws/ecs_task_definition_spec.rb +2 -0
- data/spec/aws/iam_managed_policy_spec.rb +2 -0
- data/spec/aws/kms_alias_spec.rb +2 -0
- data/spec/aws/list_type_patches_spec.rb +35 -0
- data/spec/aws/logs_log_group_spec.rb +2 -0
- data/spec/aws/nested_arrays_spec.rb +194 -0
- data/spec/aws/rds_db_instance_spec.rb +2 -0
- data/spec/aws/serverless_spec.rb +2 -2
- data/spec/cfndsl_spec.rb +102 -63
- data/spec/cli_spec.rb +52 -49
- data/spec/cloud_formation_template_spec.rb +235 -0
- data/spec/condition_spec.rb +24 -0
- data/spec/deep_merge_spec.rb +2 -0
- data/spec/direct_ruby_spec.rb +19 -0
- data/spec/external_parameters_spec.rb +25 -20
- data/spec/fixtures/condition-assertion.json +1 -0
- data/spec/fixtures/params.json +1 -0
- data/spec/fixtures/params.yaml +2 -0
- data/spec/fixtures/params_struct1.yaml +4 -0
- data/spec/fixtures/params_struct2.yaml +4 -0
- data/spec/fixtures/rule-assertion.json +1 -0
- data/spec/fixtures/test.rb +12 -4
- data/spec/generate_spec.rb +4 -0
- data/spec/jsonable_spec.rb +2 -0
- data/spec/metadata_spec.rb +2 -0
- data/spec/names_spec.rb +2 -0
- data/spec/output_spec.rb +2 -0
- data/spec/plurals_spec.rb +2 -0
- data/spec/resource_name_spec.rb +21 -0
- data/spec/resources_spec.rb +2 -7
- data/spec/rule_spec.rb +17 -0
- data/spec/spec_helper.rb +4 -7
- data/spec/support/shared_examples/orchestration_template.rb +17 -2
- data/spec/transform_spec.rb +2 -0
- data/spec/types_definition_spec.rb +6 -7
- metadata +79 -25
- data/bin/cfndsl +0 -143
- data/lib/cfndsl/errors.rb +0 -29
- data/lib/cfndsl/os/heat_template.rb +0 -16
- data/lib/cfndsl/os/types.rb +0 -12
- data/lib/cfndsl/os/types.yaml +0 -2423
- data/lib/cfndsl/patches.rb +0 -98
- data/lib/cfnlego.rb +0 -42
- data/spec/fixtures/heattest.rb +0 -22
- data/spec/heat_template_spec.rb +0 -5
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
cfndsl
|
2
2
|
======
|
3
3
|
|
4
|
-
[![Build Status](https://travis-ci.org/
|
4
|
+
[![Build Status](https://travis-ci.org/cfndsl/cfndsl.png?branch=master)](https://travis-ci.org/cfndsl/cfndsl)
|
5
5
|
[![Gem Version](https://badge.fury.io/rb/cfndsl.png)](http://badge.fury.io/rb/cfndsl)
|
6
|
-
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/
|
6
|
+
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/cfndsl/cfndsl?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![Join the chat at https://gitter.im/cfndsl/cfndsl](https://badges.gitter.im/cfndsl/cfndsl.svg)](https://gitter.im/cfndsl/cfndsl?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
7
7
|
|
8
8
|
[AWS Cloudformation](http://docs.amazonwebservices.com/AWSCloudFormation/latest/UserGuide/GettingStarted.html) templates are an incredibly powerful way to build
|
9
9
|
sets of resources in Amazon's AWS environment. Unfortunately, because
|
@@ -24,8 +24,22 @@ templates by running ruby.
|
|
24
24
|
|
25
25
|
## Getting Started
|
26
26
|
|
27
|
+
ruby version > 2.4 is required to run cfndsl, you should look at using rbenv example for installing with rbenv
|
28
|
+
|
29
|
+
rbenv exec gem install cfndsl
|
30
|
+
|
31
|
+
Example for doing it system wide Ruby
|
32
|
+
|
27
33
|
sudo gem install cfndsl
|
28
34
|
|
35
|
+
Update the the cloudformation specification to the latest version.
|
36
|
+
|
37
|
+
cfndsl -u
|
38
|
+
|
39
|
+
or update to a specific version
|
40
|
+
|
41
|
+
cfndsl -u 7.1.0
|
42
|
+
|
29
43
|
Now write a template in the dsl
|
30
44
|
|
31
45
|
```ruby
|
@@ -288,7 +302,7 @@ end
|
|
288
302
|
|
289
303
|
### Template Resources
|
290
304
|
|
291
|
-
Cfndsl creates accessor methods for all of the resources listed [here](https://github.com/
|
305
|
+
Cfndsl creates accessor methods for all of the resources listed [here](https://github.com/cfndsl/cfndsl/blob/master/lib/cfndsl/aws/types.yaml) and [here](https://github.com/cfndsl/cfndsl/blob/master/lib/cfndsl/os/types.yaml). If a resource is missing, or if you prefer to explicitly enter a resource in a template, you can do so. Keep in mind that since you are using the generic `Resource` class, you will also need to explicitly set the `Type` and that you no longer have access to the helper methods defined on that particular class, so you will have to use the `Property` method to set them.
|
292
306
|
|
293
307
|
```ruby
|
294
308
|
CloudFormation do
|
@@ -428,16 +442,15 @@ The cfndsl command line program now accepts some command line options.
|
|
428
442
|
Usage: cfndsl [options] FILE
|
429
443
|
-o, --output FILE Write output to file
|
430
444
|
-y, --yaml FILE Import yaml file as local variables
|
431
|
-
-r, --ruby FILE Evaluate ruby file before template
|
432
445
|
-j, --json FILE Import json file as local variables
|
433
446
|
-p, --pretty Pretty-format output JSON
|
434
447
|
-f, --format FORMAT Specify the output format (JSON default)
|
435
448
|
-D, --define "VARIABLE=VALUE" Directly set local VARIABLE as VALUE
|
436
449
|
-v, --verbose Turn on verbose ouptut
|
437
|
-
-b, --disable-binding Disable binding configuration
|
438
450
|
-m, --disable-deep-merge Disable deep merging of yaml
|
439
451
|
-s, --specification-file FILE Location of Cloudformation Resource Specification file
|
440
|
-
-u,
|
452
|
+
-u [VERSION], Update the Resource Specification file to latest, or specific version
|
453
|
+
--update-specification
|
441
454
|
-g RESOURCE_TYPE,RESOURCE_LOGICAL_NAME,
|
442
455
|
--generate Add resource type and logical name
|
443
456
|
-l, --list List supported resources
|
@@ -554,38 +567,87 @@ would generate a template with 5 instances declared.
|
|
554
567
|
Specifying multiple -y options will default deep_merge all the yaml in the order specified.
|
555
568
|
You can disable this with -m.
|
556
569
|
|
557
|
-
Finally, the -r option gives you the opportunity to execute some
|
558
|
-
arbitrary ruby code in the evaluation context before the cloudformation
|
559
|
-
template is evaluated (this is not available if `--disable-binding` is used).
|
560
|
-
|
561
570
|
### Rake task
|
562
571
|
Simply add the following to your `Rakefile`:
|
563
572
|
|
564
573
|
```ruby
|
565
574
|
require 'cfndsl/rake_task'
|
566
575
|
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
576
|
+
namespace(:cfndsl) do
|
577
|
+
CfnDsl::RakeTask.new do |t|
|
578
|
+
# Use a custom specification file
|
579
|
+
t.specification(file: 'tmp/cloudformation_resources.json')
|
580
|
+
|
581
|
+
desc 'Generate CloudFormation Json'
|
582
|
+
t.json(name: :json, files: FileList.new('sample/*.rb'), pathmap: 'tmp/%f.json')
|
583
|
+
|
584
|
+
# Generate yaml output, loading an extra file that matches the source file
|
585
|
+
t.yaml(name: :yaml, files: 'sample/t1.rb', pathmap: 'tmp/%f.yaml', extras: '%X.yaml')
|
586
|
+
end
|
578
587
|
end
|
579
588
|
```
|
580
589
|
|
581
590
|
And then use rake to generate the cloudformation:
|
582
591
|
|
583
592
|
```bash
|
584
|
-
$ bin/rake generate
|
593
|
+
$ bin/rake cfndsl:generate
|
594
|
+
```
|
595
|
+
|
596
|
+
### Embedded Ruby
|
597
|
+
```ruby
|
598
|
+
|
599
|
+
# Optionally before requiring 'cfndsl' set global options
|
600
|
+
require `cfndsl/globals`
|
601
|
+
CfnDsl.specification_file(file) # Override location of json spec file
|
602
|
+
CfnDsl.disable_deep_merge # Prevent monkey patching of Hash with deep merge capabilities
|
603
|
+
|
604
|
+
require `cfndsl`
|
605
|
+
|
606
|
+
# As a function that takes a block of DSL
|
607
|
+
template = CloudFormation do
|
608
|
+
# Some CfnDsl
|
609
|
+
end
|
610
|
+
puts JSON.pretty_generate(template.validate)
|
611
|
+
|
612
|
+
# As a class that is a template
|
613
|
+
class MyTemplate < CfnDsl::CloudFormationTemplate
|
614
|
+
def initialize
|
615
|
+
super do
|
616
|
+
# Base DSL
|
617
|
+
end
|
618
|
+
end
|
619
|
+
|
620
|
+
def instance(logical_id)
|
621
|
+
this = self
|
622
|
+
EC2_Instance(logical_id) do
|
623
|
+
self.class.name # << 'CfnDsl::ResourceDefinition' not 'MyTemplate' !
|
624
|
+
InstanceType this.instance_type
|
625
|
+
end
|
626
|
+
end
|
627
|
+
|
628
|
+
#do not make this private!
|
629
|
+
def instance_type
|
630
|
+
't3.large'
|
631
|
+
end
|
632
|
+
end
|
633
|
+
|
634
|
+
# As a builder class
|
635
|
+
class Builder
|
636
|
+
include CfnDsl::CloudFormation
|
637
|
+
|
638
|
+
def model
|
639
|
+
this = self # the DSL blocks are executed via instance_eval
|
640
|
+
ref_param = Ref('param') # and other Fn::*
|
641
|
+
template = CloudFormation do
|
642
|
+
# Some DSL
|
643
|
+
end
|
644
|
+
template.validate.to_json
|
645
|
+
end
|
646
|
+
end
|
585
647
|
```
|
586
648
|
|
587
649
|
### Generating CloudFormation resources from cfndsl
|
588
|
-
By supplying the -g
|
650
|
+
By supplying the -g parameter you are now able to generate cloudformation resources for supported objects, for a list of supported resources run cfndsl -l
|
589
651
|
|
590
652
|
Example
|
591
653
|
```bash
|
data/Rakefile
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler/gem_tasks'
|
2
4
|
require 'rspec/core/rake_task'
|
3
5
|
require 'cfndsl/version'
|
4
6
|
require 'rubocop/rake_task'
|
5
7
|
require 'yamllint/rake_task'
|
6
8
|
require 'github_changelog_generator/task'
|
9
|
+
require 'cfndsl/rake_task'
|
7
10
|
|
8
11
|
RSpec::Core::RakeTask.new
|
9
12
|
RuboCop::RakeTask.new
|
@@ -16,16 +19,37 @@ end
|
|
16
19
|
|
17
20
|
YamlLint::RakeTask.new do |t|
|
18
21
|
t.paths = %w[
|
19
|
-
lib/cfndsl/aws/types.yaml
|
20
|
-
lib/cfndsl/os/types.yaml
|
21
22
|
sample/t1.yaml
|
22
23
|
.travis.yml
|
23
24
|
.rubocop.yml
|
24
25
|
]
|
25
26
|
end
|
26
27
|
|
27
|
-
task default: %i[spec rubocop yamllint]
|
28
|
+
task default: %i[clean spec rubocop yamllint samples:generate]
|
29
|
+
|
30
|
+
# Test our own rake task and samples
|
31
|
+
|
32
|
+
directory 'tmp'
|
28
33
|
|
34
|
+
namespace :samples do
|
35
|
+
source_files = FileList.new('sample/*.rb') { |fl| fl.exclude('**/circular.rb') }
|
36
|
+
|
37
|
+
CfnDsl::RakeTask.new do |t|
|
38
|
+
t.specification(file: 'tmp/cloudformation_resources.json')
|
39
|
+
desc 'Generate CloudFormation Json'
|
40
|
+
t.json(name: :json, files: source_files, pathmap: 'tmp/%f.json', pretty: true, extras: FileList.new('sample/*.yaml'))
|
41
|
+
t.yaml(name: :yaml, files: 'sample/t1.rb', pathmap: 'tmp/%f.yaml', extras: '%X.yaml')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
CLEAN.add 'tmp/*.rb.{json,yaml}', 'tmp/cloudformation_resources.json'
|
46
|
+
|
47
|
+
CfnDsl::RakeTask.new do |t|
|
48
|
+
desc 'Update Embedded Cloudformation specification'
|
49
|
+
t.specification(name: :update_cfn_spec, file: CfnDsl::LOCAL_SPEC_FILE, version: 'latest')
|
50
|
+
end
|
51
|
+
|
52
|
+
# TODO: Bump should ensure we have the latest upstream resource spec
|
29
53
|
task :bump, :type do |_, args|
|
30
54
|
type = args[:type].downcase
|
31
55
|
version_path = 'lib/cfndsl/version.rb'
|
@@ -35,9 +59,7 @@ task :bump, :type do |_, args|
|
|
35
59
|
|
36
60
|
raise unless types.include?(type)
|
37
61
|
|
38
|
-
if `git rev-parse --abbrev-ref HEAD`.strip != 'master'
|
39
|
-
raise "Looks like you're trying to create a release in a branch, you can only create one in 'master'"
|
40
|
-
end
|
62
|
+
raise "Looks like you're trying to create a release in a branch, you can only create one in 'master'" if `git rev-parse --abbrev-ref HEAD`.strip != 'master'
|
41
63
|
|
42
64
|
version_segments = CfnDsl::VERSION.split('.').map(&:to_i)
|
43
65
|
|
data/TODO.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# 1.0.0 Release Changes
|
2
|
+
|
3
|
+
## Prepare for Machine Ingestable Types
|
4
|
+
|
5
|
+
## ~~Remove OS Heat Support~~
|
6
|
+
|
7
|
+
## Remove Ruby/Constant Interpolation
|
8
|
+
|
9
|
+
## ~~Better Ruby Api~~
|
10
|
+
|
11
|
+
## 100% Test Coverage
|
12
|
+
|
13
|
+
## Use Ruby Contracts for Resource Validation
|
14
|
+
|
15
|
+
## Style Guide/Wiki/README/Examples Update
|
16
|
+
|
17
|
+
## Fully implement ExternalParameters as a Mash
|
18
|
+
|
data/UPGRADING.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Major version upgrades
|
2
|
+
|
3
|
+
## 0.x to 1.x
|
4
|
+
|
5
|
+
### Deprecations
|
6
|
+
|
7
|
+
* FnFormat => FnSub
|
8
|
+
* addTag => add_tag
|
9
|
+
* checkRefs => check_refs
|
10
|
+
* Ruby versions < 2.4
|
11
|
+
* Legacy cfndsl resource specification files
|
12
|
+
|
13
|
+
### Validation
|
14
|
+
|
15
|
+
* Tighter validation including for null values and cyclic references in Resources, Outputs, Rules and Conditions
|
16
|
+
* Tighter definition of duplicates. eg. Route must be EC2_Route because another service now has a Route resource.
|
17
|
+
* Requires the specification file to exist at the time it is explicitly set with CfnDsl.specification_file=
|
18
|
+
|
19
|
+
#### Spec version
|
20
|
+
|
21
|
+
The AWS cloudformation spec will be regularly updated on every release
|
22
|
+
|
data/cfndsl.gemspec
CHANGED
@@ -1,25 +1,26 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
lib = File.expand_path('
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
5
|
require 'cfndsl/version'
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
|
-
s.name
|
9
|
-
s.version
|
10
|
-
s.summary
|
11
|
-
s.description
|
12
|
-
s.authors
|
13
|
-
s.email
|
14
|
-
s.files
|
15
|
-
s.homepage
|
16
|
-
s.license
|
17
|
-
s.test_files
|
18
|
-
s.require_paths
|
8
|
+
s.name = 'cfndsl'
|
9
|
+
s.version = CfnDsl::VERSION
|
10
|
+
s.summary = 'AWS Cloudformation DSL'
|
11
|
+
s.description = 'DSL for creating AWS Cloudformation templates'
|
12
|
+
s.authors = ['Steven Jack', 'Chris Howe', 'Travis Dempsey', 'Greg Cockburn']
|
13
|
+
s.email = ['stevenmajack@gmail.com', 'chris@howeville.com', 'dempsey.travis@gmail.com', 'gergnz@gmail.com']
|
14
|
+
s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
15
|
+
s.homepage = 'https://github.com/cfndsl/cfndsl'
|
16
|
+
s.license = 'MIT'
|
17
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
s.bindir = 'exe'
|
20
|
+
s.required_ruby_version = '~> 2.3'
|
19
21
|
|
20
22
|
s.executables << 'cfndsl'
|
21
23
|
|
22
|
-
s.add_development_dependency 'bundler', '~> 1
|
23
|
-
|
24
|
-
s.post_install_message = "'addTag' is now deprecated in favour of 'add_tag'. 'addTag' will be removed in the next major version."
|
24
|
+
s.add_development_dependency 'bundler', '~> 2.1'
|
25
|
+
s.add_runtime_dependency 'hana', '~> 1.3'
|
25
26
|
end
|
data/exe/cfndsl
ADDED
data/lib/cfndsl.rb
CHANGED
@@ -1,114 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'json'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
require 'cfndsl/module'
|
7
|
-
require 'cfndsl/errors'
|
8
|
-
require 'cfndsl/ref_check'
|
9
|
-
require 'cfndsl/jsonable'
|
10
|
-
require 'cfndsl/properties'
|
11
|
-
require 'cfndsl/update_policy'
|
12
|
-
require 'cfndsl/creation_policy'
|
13
|
-
require 'cfndsl/conditions'
|
14
|
-
require 'cfndsl/mappings'
|
15
|
-
require 'cfndsl/resources'
|
16
|
-
require 'cfndsl/parameters'
|
17
|
-
require 'cfndsl/outputs'
|
18
|
-
require 'cfndsl/patches'
|
19
|
-
require 'cfndsl/specification'
|
20
|
-
require 'cfndsl/aws/cloud_formation_template'
|
21
|
-
require 'cfndsl/os/heat_template'
|
22
|
-
require 'cfndsl/external_parameters'
|
23
|
-
require 'cfndsl/version'
|
24
|
-
|
25
|
-
# CfnDsl
|
26
|
-
module CfnDsl
|
27
|
-
# This function handles the eval of the template file and returns the
|
28
|
-
# results. It does this with a ruby "eval", but it builds up a customized
|
29
|
-
# binding environment before it calls eval. The environment can be
|
30
|
-
# customized by passing a list of customizations in the extras parameter.
|
31
|
-
#
|
32
|
-
# These customizations are expressed as an array of pairs of
|
33
|
-
# (type,filename). They are evaluated in the order they appear in the
|
34
|
-
# extras array. The types are as follows
|
35
|
-
#
|
36
|
-
# :yaml - the second element is treated as a file name, which is loaded
|
37
|
-
# as a yaml file. The yaml file should contain a top level
|
38
|
-
# dictionary. Each of the keys of the top level dictionary is
|
39
|
-
# used as a local variable in the evalation context.
|
40
|
-
#
|
41
|
-
# :json - the second element is treated as a file name, which is loaded
|
42
|
-
# as a json file. The yaml file should contain a top level
|
43
|
-
# dictionary. Each of the keys of the top level dictionary is
|
44
|
-
# used as a local variable in the evalation context.
|
45
|
-
#
|
46
|
-
# :ruby - the second element is treated as a file name which is evaluated
|
47
|
-
# as a ruby file. Any assigments (or other binding affecting
|
48
|
-
# side effects) will persist into the context where the template
|
49
|
-
# is evaluated
|
50
|
-
#
|
51
|
-
# :raw - the second element is treated as a ruby statement and is
|
52
|
-
# evaluated in the binding context, similar to the contents of
|
53
|
-
# a ruby file.
|
54
|
-
#
|
55
|
-
# Note that the order is important, as later extra sections can overwrite
|
56
|
-
# or even undo things that were done by earlier sections.
|
57
|
-
|
58
|
-
# rubocop:disable all
|
59
|
-
def self.eval_file_with_extras(filename, extras = [], logstream = nil)
|
60
|
-
b = binding
|
61
|
-
params = CfnDsl::ExternalParameters.refresh!
|
62
|
-
extras.each do |type, file|
|
63
|
-
case type
|
64
|
-
when :yaml, :json
|
65
|
-
klass_name = type.to_s.upcase
|
66
|
-
logstream.puts("Loading #{klass_name} file #{file}") if logstream
|
67
|
-
params.load_file file
|
68
|
-
params.add_to_binding(b, logstream) unless disable_binding?
|
69
|
-
when :ruby
|
70
|
-
if disable_binding?
|
71
|
-
logstream.puts("Interpreting Ruby files was disabled. #{file} will not be read") if logstream
|
72
|
-
else
|
73
|
-
logstream.puts("Running ruby file #{file}") if logstream
|
74
|
-
b.eval(File.read(file), file)
|
75
|
-
end
|
76
|
-
when :raw
|
77
|
-
params.set_param(*file.split('='))
|
78
|
-
unless disable_binding?
|
79
|
-
logstream.puts("Running raw ruby code #{file}") if logstream
|
80
|
-
b.eval(file, 'raw code')
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
logstream.puts("Loading template file #{filename}") if logstream
|
86
|
-
b.eval(File.read(filename), filename)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def CloudFormation(&block)
|
91
|
-
x = CfnDsl::CloudFormationTemplate.new
|
92
|
-
x.declare(&block)
|
93
|
-
invalid_references = x.check_refs
|
94
|
-
if invalid_references
|
95
|
-
abort invalid_references.join("\n")
|
96
|
-
elsif CfnDsl::Errors.errors?
|
97
|
-
abort CfnDsl::Errors.errors.join("\n")
|
98
|
-
else
|
99
|
-
return x
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def Heat(&block)
|
104
|
-
x = CfnDsl::HeatTemplate.new
|
105
|
-
x.declare(&block)
|
106
|
-
invalid_references = x.check_refs
|
107
|
-
if invalid_references
|
108
|
-
abort invalid_references.join("\n")
|
109
|
-
elsif CfnDsl::Errors.errors?
|
110
|
-
abort CfnDsl::Errors.errors.join("\n")
|
111
|
-
else
|
112
|
-
return x
|
113
|
-
end
|
114
|
-
end
|
3
|
+
require_relative 'cfndsl/cloudformation'
|
4
|
+
require_relative 'cfndsl/cfnlego'
|