cfndsl 0.17.5 → 1.0.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +4 -4
- data/.travis.yml +6 -1
- data/CHANGELOG.md +32 -34
- data/README.md +68 -21
- data/Rakefile +25 -3
- data/TODO.md +18 -0
- data/UPGRADING.md +22 -0
- data/cfndsl.gemspec +3 -3
- data/exe/cfndsl +5 -0
- data/lib/cfndsl.rb +2 -116
- data/lib/cfndsl/aws/cloud_formation_template.rb +8 -1
- data/lib/cfndsl/aws/patches/000_sam.spec.json +574 -0
- data/lib/cfndsl/aws/patches/100_sam.spec_DeploymentPreference_patch.json +64 -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_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/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 +35809 -11627
- data/lib/cfndsl/aws/types.rb +3 -3
- data/lib/cfndsl/cfnlego.rb +34 -0
- data/lib/{cfnlego → cfndsl/cfnlego}/cloudformation.erb +0 -0
- data/lib/{cfnlego → cfndsl/cfnlego}/cloudformation.rb +0 -0
- data/lib/{cfnlego → cfndsl/cfnlego}/resource.rb +3 -8
- data/lib/cfndsl/cloudformation.rb +107 -0
- data/lib/cfndsl/conditions.rb +11 -1
- data/lib/cfndsl/creation_policy.rb +1 -1
- data/lib/cfndsl/deep_merge.rb +4 -0
- data/lib/cfndsl/external_parameters.rb +4 -13
- data/lib/cfndsl/globals.rb +48 -9
- data/lib/cfndsl/jsonable.rb +22 -60
- data/lib/cfndsl/mappings.rb +1 -1
- data/lib/cfndsl/module.rb +16 -5
- data/lib/cfndsl/orchestration_template.rb +185 -83
- data/lib/cfndsl/outputs.rb +5 -1
- data/lib/cfndsl/parameters.rb +1 -1
- data/lib/cfndsl/plurals.rb +12 -1
- data/lib/cfndsl/properties.rb +1 -1
- data/lib/cfndsl/rake_task.rb +206 -12
- data/lib/cfndsl/ref_check.rb +19 -11
- data/lib/cfndsl/resources.rb +6 -19
- data/lib/cfndsl/rules.rb +1 -1
- data/lib/cfndsl/runner.rb +143 -0
- data/lib/cfndsl/specification.rb +80 -95
- data/lib/cfndsl/types.rb +205 -91
- data/lib/cfndsl/update_policy.rb +1 -1
- data/lib/cfndsl/version.rb +1 -1
- data/sample/autoscale.rb +0 -1
- data/sample/autoscale2.rb +0 -1
- data/sample/config_service.rb +2 -2
- data/sample/t1.rb +1 -1
- data/sample/vpc_example.rb +1 -1
- data/sample/vpc_with_vpn_example.rb +1 -1
- data/spec/aws/list_type_patches_spec.rb +35 -0
- data/spec/aws/nested_arrays_spec.rb +155 -3
- data/spec/aws/serverless_spec.rb +0 -2
- data/spec/cfndsl_spec.rb +94 -78
- data/spec/cli_spec.rb +16 -54
- data/spec/cloud_formation_template_spec.rb +233 -0
- data/spec/condition_spec.rb +24 -0
- data/spec/direct_ruby_spec.rb +19 -0
- data/spec/external_parameters_spec.rb +2 -15
- data/spec/fixtures/condition-assertion.json +1 -0
- data/spec/fixtures/test.rb +2 -1
- data/spec/generate_spec.rb +4 -2
- data/spec/resources_spec.rb +0 -7
- data/spec/spec_helper.rb +2 -7
- data/spec/support/shared_examples/orchestration_template.rb +15 -2
- data/spec/types_definition_spec.rb +3 -6
- metadata +52 -23
- data/bin/cfndsl +0 -160
- data/lib/cfndsl/errors.rb +0 -31
- data/lib/cfndsl/os/heat_template.rb +0 -18
- data/lib/cfndsl/os/types.rb +0 -14
- data/lib/cfndsl/os/types.yaml +0 -2423
- data/lib/cfndsl/patches.rb +0 -226
- data/lib/cfnlego.rb +0 -44
- data/spec/fixtures/heattest.rb +0 -24
- data/spec/heat_template_spec.rb +0 -7
data/spec/generate_spec.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
2
3
|
require 'spec_helper'
|
4
|
+
|
3
5
|
describe Cfnlego do
|
4
6
|
let(:template) { Cfnlego.run(resources: ['AWS::EC2::EIP,EIP']) }
|
5
7
|
|
@@ -9,9 +11,9 @@ describe Cfnlego do
|
|
9
11
|
output << " EC2_EIP('EIP') do\n Domain String "
|
10
12
|
output << '# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-eip.html#cfn-ec2-eip-domain'
|
11
13
|
output << "\n InstanceId String # http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-eip.html#cfn-ec2-eip-instanceid"
|
14
|
+
output << "\n PublicIpv4Pool String # http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-eip.html#cfn-ec2-eip-publicipv4pool"
|
12
15
|
output << "\n end\nend\n"
|
13
16
|
expect(template).to eq output
|
14
17
|
end
|
15
18
|
end
|
16
19
|
end
|
17
|
-
# rubocop:enable Style/FrozenStringLiteralComment
|
data/spec/resources_spec.rb
CHANGED
@@ -5,13 +5,6 @@ require 'spec_helper'
|
|
5
5
|
describe CfnDsl::ResourceDefinition do
|
6
6
|
subject { CfnDsl::CloudFormationTemplate.new.AutoScalingGroup(:web_servers) }
|
7
7
|
|
8
|
-
context '#addTag' do
|
9
|
-
it 'is a pass-through method to add_tag' do
|
10
|
-
expect(subject).to receive(:add_tag).with('role', 'web-server', true)
|
11
|
-
subject.addTag('role', 'web-server', true)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
8
|
context '#add_tag' do
|
16
9
|
it 'adds a Tag for the resource' do
|
17
10
|
subject.add_tag('role', 'web-server', true)
|
data/spec/spec_helper.rb
CHANGED
@@ -12,12 +12,7 @@ if ENV['CFNDSL_COV']
|
|
12
12
|
end
|
13
13
|
|
14
14
|
require 'cfndsl/globals'
|
15
|
-
CfnDsl.specification_file File.expand_path('../lib/cfndsl/aws/resource_specification.json', __dir__)
|
16
15
|
# use local fixture for tests
|
16
|
+
CfnDsl.specification_file CfnDsl::LOCAL_SPEC_FILE
|
17
17
|
require 'cfndsl'
|
18
|
-
require
|
19
|
-
|
20
|
-
bindir = File.expand_path('../bin', __dir__)
|
21
|
-
ENV['PATH'] = [ENV['PATH'], bindir].join(':')
|
22
|
-
|
23
|
-
Dir[File.expand_path('support/**/*.rb', __dir__)].sort.each { |f| require f }
|
18
|
+
Dir[File.expand_path('support/**/*.rb', __dir__)].each { |f| require f }
|
@@ -1,6 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
shared_examples 'an orchestration template' do
|
4
|
+
context '#initialize with block' do
|
5
|
+
subject do
|
6
|
+
described_class.new { Resource(:foo) { Type :bar } }
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'evaluates the block' do
|
10
|
+
resources = subject.instance_variable_get('@Resources')
|
11
|
+
expect(resources).to_not be_empty
|
12
|
+
foo = resources.first[1]
|
13
|
+
expect(foo.instance_variable_get('@Type')).to eql(:bar)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
4
17
|
context '#valid_ref?' do
|
5
18
|
it 'returns true if ref is global' do
|
6
19
|
expect(subject.valid_ref?('AWS::Region')).to eq(true)
|
@@ -27,7 +40,7 @@ shared_examples 'an orchestration template' do
|
|
27
40
|
context '#check_resource_refs' do
|
28
41
|
it 'returns an array with an error message if invalid refs are present' do
|
29
42
|
subject.EC2_Instance(:foo) { UserData Ref(:bar) }
|
30
|
-
expect(subject.check_resource_refs).to
|
43
|
+
expect(subject.check_resource_refs.first).to match(/^Invalid Reference:.*foo.*bar/)
|
31
44
|
end
|
32
45
|
|
33
46
|
it 'returns an empty array ' do
|
@@ -40,7 +53,7 @@ shared_examples 'an orchestration template' do
|
|
40
53
|
it 'returns an array with an error message if invalid refs are present' do
|
41
54
|
subject.EC2_Instance(:foo)
|
42
55
|
subject.Output(:baz) { Value Ref(:bar) }
|
43
|
-
expect(subject.check_output_refs).to
|
56
|
+
expect(subject.check_output_refs.first).to match(/Invalid Reference:.*baz.*bar/)
|
44
57
|
end
|
45
58
|
|
46
59
|
it 'returns an empty array' do
|
@@ -2,14 +2,10 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
# This is a somewhat temporary test class to compare functionality
|
6
|
-
# between the AWS, OS and new ways of defining types
|
7
5
|
RSpec.describe 'Type Definitions' do
|
8
|
-
|
9
|
-
os_spec = YAML.load_file File.expand_path('../lib/cfndsl/os/types.yaml', __dir__)
|
10
|
-
new_spec = CfnDsl::Specification.extract_from_resource_spec!
|
6
|
+
new_spec = CfnDsl::Types.extract_from_resource_spec(fail_patches: true)
|
11
7
|
|
12
|
-
{ '
|
8
|
+
{ 'New' => new_spec }.each_pair do |cloud, specdef|
|
13
9
|
context cloud do
|
14
10
|
resources = specdef['Resources']
|
15
11
|
types = specdef['Types']
|
@@ -29,6 +25,7 @@ RSpec.describe 'Type Definitions' do
|
|
29
25
|
context 'Types' do
|
30
26
|
types.each do |name, type|
|
31
27
|
it "#{name} has all property types defined" do
|
28
|
+
type = type['Properties'] if type.is_a?(Hash) && type.key?('Properties')
|
32
29
|
type = type.first if type.is_a?(Array)
|
33
30
|
if type.is_a?(String)
|
34
31
|
expect(types).to have_key(type)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cfndsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0.pre.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Jack
|
@@ -9,9 +9,9 @@ authors:
|
|
9
9
|
- Travis Dempsey
|
10
10
|
- Greg Cockburn
|
11
11
|
autorequire:
|
12
|
-
bindir:
|
12
|
+
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date: 2019-
|
14
|
+
date: 2019-10-27 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -19,14 +19,28 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - "~>"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '2.
|
22
|
+
version: '2.0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '2.
|
29
|
+
version: '2.0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: hana
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - "~>"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '1.3'
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1.3'
|
30
44
|
description: DSL for creating AWS Cloudformation templates
|
31
45
|
email:
|
32
46
|
- stevenmajack@gmail.com
|
@@ -46,16 +60,35 @@ files:
|
|
46
60
|
- LICENSE
|
47
61
|
- README.md
|
48
62
|
- Rakefile
|
49
|
-
-
|
63
|
+
- TODO.md
|
64
|
+
- UPGRADING.md
|
50
65
|
- cfndsl.gemspec
|
66
|
+
- exe/cfndsl
|
51
67
|
- lib/cfndsl.rb
|
52
68
|
- lib/cfndsl/aws/cloud_formation_template.rb
|
69
|
+
- lib/cfndsl/aws/patches/000_sam.spec.json
|
70
|
+
- lib/cfndsl/aws/patches/100_sam.spec_DeploymentPreference_patch.json
|
71
|
+
- lib/cfndsl/aws/patches/500_Cognito_IdentityPoolRoleAttachment_patches.json
|
72
|
+
- lib/cfndsl/aws/patches/500_IoT1Click_patch_PlacementTemplate_DeviceTemplates.json
|
73
|
+
- lib/cfndsl/aws/patches/500_SAM_Serverless_Function_S3Event_Events_patch.json
|
74
|
+
- lib/cfndsl/aws/patches/500_SAM_Serverless_Function_S3Location_Version_patch.json
|
75
|
+
- lib/cfndsl/aws/patches/500_SSM_AssociationName_patch.json
|
76
|
+
- lib/cfndsl/aws/patches/500_VPCEndpoint_patch.json
|
77
|
+
- lib/cfndsl/aws/patches/510_ElasticSearch_Domain_patches.json
|
78
|
+
- lib/cfndsl/aws/patches/600_RefKinds_patch.json
|
79
|
+
- lib/cfndsl/aws/patches/700_SAM_Serverless_Function_InlineCode_patch.json
|
80
|
+
- lib/cfndsl/aws/patches/800_List_types_patch.json
|
53
81
|
- lib/cfndsl/aws/resource_specification.json
|
54
82
|
- lib/cfndsl/aws/types.rb
|
55
83
|
- lib/cfndsl/aws/types.yaml
|
84
|
+
- lib/cfndsl/cfnlego.rb
|
85
|
+
- lib/cfndsl/cfnlego/cloudformation.erb
|
86
|
+
- lib/cfndsl/cfnlego/cloudformation.rb
|
87
|
+
- lib/cfndsl/cfnlego/resource.rb
|
88
|
+
- lib/cfndsl/cloudformation.rb
|
56
89
|
- lib/cfndsl/conditions.rb
|
57
90
|
- lib/cfndsl/creation_policy.rb
|
58
|
-
- lib/cfndsl/
|
91
|
+
- lib/cfndsl/deep_merge.rb
|
59
92
|
- lib/cfndsl/external_parameters.rb
|
60
93
|
- lib/cfndsl/globals.rb
|
61
94
|
- lib/cfndsl/json_serialisable_object.rb
|
@@ -64,26 +97,19 @@ files:
|
|
64
97
|
- lib/cfndsl/module.rb
|
65
98
|
- lib/cfndsl/names.rb
|
66
99
|
- lib/cfndsl/orchestration_template.rb
|
67
|
-
- lib/cfndsl/os/heat_template.rb
|
68
|
-
- lib/cfndsl/os/types.rb
|
69
|
-
- lib/cfndsl/os/types.yaml
|
70
100
|
- lib/cfndsl/outputs.rb
|
71
101
|
- lib/cfndsl/parameters.rb
|
72
|
-
- lib/cfndsl/patches.rb
|
73
102
|
- lib/cfndsl/plurals.rb
|
74
103
|
- lib/cfndsl/properties.rb
|
75
104
|
- lib/cfndsl/rake_task.rb
|
76
105
|
- lib/cfndsl/ref_check.rb
|
77
106
|
- lib/cfndsl/resources.rb
|
78
107
|
- lib/cfndsl/rules.rb
|
108
|
+
- lib/cfndsl/runner.rb
|
79
109
|
- lib/cfndsl/specification.rb
|
80
110
|
- lib/cfndsl/types.rb
|
81
111
|
- lib/cfndsl/update_policy.rb
|
82
112
|
- lib/cfndsl/version.rb
|
83
|
-
- lib/cfnlego.rb
|
84
|
-
- lib/cfnlego/cloudformation.erb
|
85
|
-
- lib/cfnlego/cloudformation.rb
|
86
|
-
- lib/cfnlego/resource.rb
|
87
113
|
- lib/deep_merge/core.rb
|
88
114
|
- lib/deep_merge/deep_merge.rb
|
89
115
|
- sample/autoscale.rb
|
@@ -106,6 +132,7 @@ files:
|
|
106
132
|
- spec/aws/ecs_task_definition_spec.rb
|
107
133
|
- spec/aws/iam_managed_policy_spec.rb
|
108
134
|
- spec/aws/kms_alias_spec.rb
|
135
|
+
- spec/aws/list_type_patches_spec.rb
|
109
136
|
- spec/aws/logs_log_group_spec.rb
|
110
137
|
- spec/aws/nested_arrays_spec.rb
|
111
138
|
- spec/aws/rds_db_instance_spec.rb
|
@@ -113,9 +140,11 @@ files:
|
|
113
140
|
- spec/cfndsl_spec.rb
|
114
141
|
- spec/cli_spec.rb
|
115
142
|
- spec/cloud_formation_template_spec.rb
|
143
|
+
- spec/condition_spec.rb
|
116
144
|
- spec/deep_merge_spec.rb
|
145
|
+
- spec/direct_ruby_spec.rb
|
117
146
|
- spec/external_parameters_spec.rb
|
118
|
-
- spec/fixtures/
|
147
|
+
- spec/fixtures/condition-assertion.json
|
119
148
|
- spec/fixtures/params.json
|
120
149
|
- spec/fixtures/params.yaml
|
121
150
|
- spec/fixtures/params_struct1.yaml
|
@@ -125,7 +154,6 @@ files:
|
|
125
154
|
- spec/fixtures/serverless-function.json
|
126
155
|
- spec/fixtures/test.rb
|
127
156
|
- spec/generate_spec.rb
|
128
|
-
- spec/heat_template_spec.rb
|
129
157
|
- spec/jsonable_spec.rb
|
130
158
|
- spec/metadata_spec.rb
|
131
159
|
- spec/names_spec.rb
|
@@ -141,8 +169,7 @@ homepage: https://github.com/cfndsl/cfndsl
|
|
141
169
|
licenses:
|
142
170
|
- MIT
|
143
171
|
metadata: {}
|
144
|
-
post_install_message:
|
145
|
-
will be removed in the next major version."
|
172
|
+
post_install_message:
|
146
173
|
rdoc_options: []
|
147
174
|
require_paths:
|
148
175
|
- lib
|
@@ -153,9 +180,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
180
|
version: '2.3'
|
154
181
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
182
|
requirements:
|
156
|
-
- - "
|
183
|
+
- - ">"
|
157
184
|
- !ruby/object:Gem::Version
|
158
|
-
version:
|
185
|
+
version: 1.3.1
|
159
186
|
requirements: []
|
160
187
|
rubyforge_project:
|
161
188
|
rubygems_version: 2.7.7
|
@@ -167,6 +194,7 @@ test_files:
|
|
167
194
|
- spec/aws/ecs_task_definition_spec.rb
|
168
195
|
- spec/aws/iam_managed_policy_spec.rb
|
169
196
|
- spec/aws/kms_alias_spec.rb
|
197
|
+
- spec/aws/list_type_patches_spec.rb
|
170
198
|
- spec/aws/logs_log_group_spec.rb
|
171
199
|
- spec/aws/nested_arrays_spec.rb
|
172
200
|
- spec/aws/rds_db_instance_spec.rb
|
@@ -174,9 +202,11 @@ test_files:
|
|
174
202
|
- spec/cfndsl_spec.rb
|
175
203
|
- spec/cli_spec.rb
|
176
204
|
- spec/cloud_formation_template_spec.rb
|
205
|
+
- spec/condition_spec.rb
|
177
206
|
- spec/deep_merge_spec.rb
|
207
|
+
- spec/direct_ruby_spec.rb
|
178
208
|
- spec/external_parameters_spec.rb
|
179
|
-
- spec/fixtures/
|
209
|
+
- spec/fixtures/condition-assertion.json
|
180
210
|
- spec/fixtures/params.json
|
181
211
|
- spec/fixtures/params.yaml
|
182
212
|
- spec/fixtures/params_struct1.yaml
|
@@ -186,7 +216,6 @@ test_files:
|
|
186
216
|
- spec/fixtures/serverless-function.json
|
187
217
|
- spec/fixtures/test.rb
|
188
218
|
- spec/generate_spec.rb
|
189
|
-
- spec/heat_template_spec.rb
|
190
219
|
- spec/jsonable_spec.rb
|
191
220
|
- spec/metadata_spec.rb
|
192
221
|
- spec/names_spec.rb
|
data/bin/cfndsl
DELETED
@@ -1,160 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'cfndsl/globals'
|
5
|
-
require 'cfndsl/version'
|
6
|
-
require 'fileutils'
|
7
|
-
require 'json'
|
8
|
-
require 'open-uri'
|
9
|
-
require 'optparse'
|
10
|
-
require 'cfnlego'
|
11
|
-
|
12
|
-
options = { resources: [] }
|
13
|
-
|
14
|
-
optparse = OptionParser.new do |opts|
|
15
|
-
Version = CfnDsl::VERSION
|
16
|
-
opts.banner = 'Usage: cfndsl [options] FILE'
|
17
|
-
|
18
|
-
# Define the options, and what they do
|
19
|
-
options[:output] = '-'
|
20
|
-
opts.on('-o', '--output FILE', 'Write output to file') do |file|
|
21
|
-
options[:output] = file
|
22
|
-
end
|
23
|
-
|
24
|
-
options[:extras] = []
|
25
|
-
opts.on('-y', '--yaml FILE', 'Import yaml file as local variables') do |file|
|
26
|
-
options[:extras].push([:yaml, File.expand_path(file)])
|
27
|
-
end
|
28
|
-
|
29
|
-
opts.on('-r', '--ruby FILE', 'Evaluate ruby file before template') do |file|
|
30
|
-
options[:extras].push([:ruby, File.expand_path(file)])
|
31
|
-
end
|
32
|
-
|
33
|
-
opts.on('-j', '--json FILE', 'Import json file as local variables') do |file|
|
34
|
-
options[:extras].push([:json, File.expand_path(file)])
|
35
|
-
end
|
36
|
-
|
37
|
-
opts.on('-p', '--pretty', 'Pretty-format output JSON') do
|
38
|
-
options[:pretty] = true
|
39
|
-
end
|
40
|
-
|
41
|
-
opts.on('-f', '--format FORMAT', 'Specify the output format (JSON default)') do |format|
|
42
|
-
raise "Format #{format} not supported" unless %w[json yaml].include?(format)
|
43
|
-
|
44
|
-
options[:outformat] = format
|
45
|
-
end
|
46
|
-
|
47
|
-
opts.on('-D', '--define "VARIABLE=VALUE"', 'Directly set local VARIABLE as VALUE') do |file|
|
48
|
-
options[:extras].push([:raw, file])
|
49
|
-
end
|
50
|
-
|
51
|
-
options[:verbose] = false
|
52
|
-
opts.on('-v', '--verbose', 'Turn on verbose ouptut') do
|
53
|
-
options[:verbose] = true
|
54
|
-
end
|
55
|
-
|
56
|
-
opts.on('-b', '--disable-binding', 'Disable binding configuration') do
|
57
|
-
CfnDsl.disable_binding
|
58
|
-
end
|
59
|
-
|
60
|
-
opts.on('-m', '--disable-deep-merge', 'Disable deep merging of yaml') do
|
61
|
-
CfnDsl.disable_deep_merge
|
62
|
-
end
|
63
|
-
|
64
|
-
opts.on('-s', '--specification-file FILE', 'Location of Cloudformation Resource Specification file') do |file|
|
65
|
-
CfnDsl.specification_file File.expand_path(file)
|
66
|
-
end
|
67
|
-
|
68
|
-
opts.on('-u', '--update-specification [VERSION]', 'Update the Resource Specification file to latest, or specific version') do |file|
|
69
|
-
options[:spec_version] = file || 'latest'
|
70
|
-
options[:update_spec] = true
|
71
|
-
end
|
72
|
-
|
73
|
-
opts.on('-g', '--generate RESOURCE_TYPE,RESOURCE_LOGICAL_NAME', 'Add resource type and logical name') do |r|
|
74
|
-
options[:lego] = true
|
75
|
-
options[:resources] << r
|
76
|
-
end
|
77
|
-
|
78
|
-
opts.on('-a', '--assetversion', 'Print out the specification version') do
|
79
|
-
options[:assetversion] = true
|
80
|
-
end
|
81
|
-
|
82
|
-
opts.on('-l', '--list', 'List supported resources') do
|
83
|
-
puts Cfnlego.Resources.sort
|
84
|
-
exit
|
85
|
-
end
|
86
|
-
|
87
|
-
# This displays the help screen, all programs are
|
88
|
-
# assumed to have this option.
|
89
|
-
opts.on('-h', '--help', 'Display this screen') do
|
90
|
-
puts opts
|
91
|
-
exit
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
optparse.parse!
|
96
|
-
|
97
|
-
if options[:update_spec]
|
98
|
-
warn 'Updating specification file'
|
99
|
-
FileUtils.mkdir_p File.dirname(CfnDsl.specification_file)
|
100
|
-
begin
|
101
|
-
content = open("https://d1uauaxba7bl26.cloudfront.net/#{options[:spec_version]}/gzip/CloudFormationResourceSpecification.json").read
|
102
|
-
rescue OpenURI::HTTPError
|
103
|
-
warn "Resource Specification version #{options[:spec_version]} not found, defaulting to 'latest'"
|
104
|
-
content = open('https://d1uauaxba7bl26.cloudfront.net/latest/gzip/CloudFormationResourceSpecification.json').read
|
105
|
-
end
|
106
|
-
File.open(CfnDsl.specification_file, 'w') { |f| f.puts content }
|
107
|
-
warn "Specification successfully written to #{CfnDsl.specification_file}"
|
108
|
-
end
|
109
|
-
|
110
|
-
if options[:assetversion]
|
111
|
-
spec_file = JSON.parse File.read(CfnDsl.specification_file)
|
112
|
-
warn spec_file['ResourceSpecificationVersion']
|
113
|
-
end
|
114
|
-
|
115
|
-
if options[:lego]
|
116
|
-
puts Cfnlego.run(options)
|
117
|
-
exit
|
118
|
-
end
|
119
|
-
|
120
|
-
if ARGV.empty?
|
121
|
-
if options[:update_spec] || options[:assetversion]
|
122
|
-
exit 0
|
123
|
-
else
|
124
|
-
puts optparse.help
|
125
|
-
exit 1
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
filename = File.expand_path(ARGV[0])
|
130
|
-
verbose = options[:verbose] && STDERR
|
131
|
-
|
132
|
-
unless CfnDsl.disable_binding?
|
133
|
-
warn <<-MSG.gsub(/^\s*/, '')
|
134
|
-
The creation of constants as config is deprecated!
|
135
|
-
Please switch to the #external_parameters method within your templates to access variables
|
136
|
-
See https://github.com/cfndsl/cfndsl/issues/170
|
137
|
-
Use the --disable-binding flag to suppress this message
|
138
|
-
MSG
|
139
|
-
end
|
140
|
-
|
141
|
-
warn "Using specification file #{CfnDsl.specification_file}" if verbose
|
142
|
-
|
143
|
-
require 'cfndsl'
|
144
|
-
|
145
|
-
model = CfnDsl.eval_file_with_extras(filename, options[:extras], verbose)
|
146
|
-
|
147
|
-
output = STDOUT
|
148
|
-
if options[:output] != '-'
|
149
|
-
puts("Writing to #{options[:output]}") if verbose
|
150
|
-
output = File.open(File.expand_path(options[:output]), 'w')
|
151
|
-
elsif verbose
|
152
|
-
verbose.puts('Writing to STDOUT')
|
153
|
-
end
|
154
|
-
|
155
|
-
if options[:outformat] == 'yaml'
|
156
|
-
data = model.to_json
|
157
|
-
output.puts JSON.parse(data).to_yaml
|
158
|
-
else
|
159
|
-
output.puts options[:pretty] ? JSON.pretty_generate(model) : model.to_json
|
160
|
-
end
|