cfndk 0.0.7 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +79 -0
  3. data/.gitignore +1 -1
  4. data/.rspec +2 -0
  5. data/.rspec_parallel +6 -0
  6. data/.simplecov +9 -0
  7. data/Gemfile +11 -1
  8. data/Gemfile.lock +815 -0
  9. data/README.md +269 -76
  10. data/bin/cfndk +3 -18
  11. data/cfndk.gemspec +15 -6
  12. data/docker/Dockerfile +8 -0
  13. data/docker/build.sh +3 -0
  14. data/docker/cfndk.sh +14 -0
  15. data/lib/cfndk.rb +36 -0
  16. data/lib/cfndk/change_set_command.rb +103 -0
  17. data/lib/cfndk/command.rb +125 -119
  18. data/lib/cfndk/config_file_loadable.rb +13 -0
  19. data/lib/cfndk/credential_provider_chain.rb +12 -42
  20. data/lib/cfndk/credential_resolvable.rb +10 -0
  21. data/lib/cfndk/diff.rb +38 -0
  22. data/lib/cfndk/global_config.rb +46 -0
  23. data/lib/cfndk/key_pair.rb +66 -14
  24. data/lib/cfndk/key_pair_command.rb +60 -0
  25. data/lib/cfndk/key_pairs.rb +22 -5
  26. data/lib/cfndk/logger.rb +12 -3
  27. data/lib/cfndk/stack.rb +427 -126
  28. data/lib/cfndk/stack_command.rb +128 -0
  29. data/lib/cfndk/stacks.rb +48 -22
  30. data/lib/cfndk/subcommand_help_returnable.rb +16 -0
  31. data/lib/cfndk/template_packager.rb +210 -0
  32. data/lib/cfndk/uuid.rb +10 -0
  33. data/lib/cfndk/version.rb +1 -1
  34. data/skel/cfndk.yml +4 -0
  35. data/spec/.gitignore +1 -0
  36. data/spec/cfndk_change_set_create_spec.rb +436 -0
  37. data/spec/cfndk_change_set_destroy_spec.rb +160 -0
  38. data/spec/cfndk_change_set_execute_spec.rb +179 -0
  39. data/spec/cfndk_change_set_report_spec.rb +107 -0
  40. data/spec/cfndk_change_set_spec.rb +37 -0
  41. data/spec/cfndk_create_spec.rb +504 -0
  42. data/spec/cfndk_destroy_spec.rb +148 -0
  43. data/spec/cfndk_keypiar_spec.rb +397 -0
  44. data/spec/cfndk_report_spec.rb +164 -0
  45. data/spec/cfndk_spec.rb +103 -0
  46. data/spec/cfndk_stack_create_spec.rb +814 -0
  47. data/spec/cfndk_stack_destroy_spec.rb +225 -0
  48. data/spec/cfndk_stack_report_spec.rb +181 -0
  49. data/spec/cfndk_stack_spec.rb +133 -0
  50. data/spec/cfndk_stack_update_spec.rb +553 -0
  51. data/spec/fixtures/big_vpc.yaml +533 -0
  52. data/spec/fixtures/empty_resource.yaml +2 -0
  53. data/spec/fixtures/iam.json +8 -0
  54. data/spec/fixtures/iam.yaml +38 -0
  55. data/spec/fixtures/iam_different.json +8 -0
  56. data/spec/fixtures/invalid_vpc.yaml +21 -0
  57. data/spec/fixtures/lambda_function/index.js +4 -0
  58. data/spec/fixtures/lambda_function/lambda_function.json +4 -0
  59. data/spec/fixtures/lambda_function/lambda_function.yaml +28 -0
  60. data/spec/fixtures/nested_stack.json +35 -0
  61. data/spec/fixtures/nested_stack.yaml +20 -0
  62. data/spec/fixtures/serverless_function/index.js +4 -0
  63. data/spec/fixtures/serverless_function/serverless_function.json +4 -0
  64. data/spec/fixtures/serverless_function/serverless_function.yaml +21 -0
  65. data/spec/fixtures/sg.json +8 -0
  66. data/spec/fixtures/sg.yaml +27 -0
  67. data/spec/fixtures/sg_different.yaml +22 -0
  68. data/spec/fixtures/stack.json +8 -0
  69. data/spec/fixtures/stack.template.json +39 -0
  70. data/spec/fixtures/stack.yaml +22 -0
  71. data/spec/fixtures/vpc.json +8 -0
  72. data/spec/fixtures/vpc.template.json +40 -0
  73. data/spec/fixtures/vpc.yaml +21 -0
  74. data/spec/fixtures/vpc_different.yaml +21 -0
  75. data/spec/spec_helper.rb +14 -0
  76. data/spec/support/aruba.rb +6 -0
  77. data/vagrant/Vagrantfile +89 -0
  78. metadata +259 -31
@@ -0,0 +1,164 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'CFnDK', type: :aruba do
4
+ before(:each) { setup_aruba }
5
+ before(:each) { set_environment_variable('AWS_REGION', ENV['AWS_REGION']) }
6
+ before(:each) { set_environment_variable('AWS_PROFILE', ENV['AWS_PROFILE']) }
7
+ before(:each) { set_environment_variable('AWS_ACCESS_KEY_ID', ENV["AWS_ACCESS_KEY_ID#{ENV['TEST_ENV_NUMBER']}"]) }
8
+ before(:each) { set_environment_variable('AWS_SECRET_ACCESS_KEY', ENV["AWS_SECRET_ACCESS_KEY#{ENV['TEST_ENV_NUMBER']}"]) }
9
+
10
+ describe 'bin/cfndk' do
11
+ describe 'report', report: true do
12
+ context 'without cfndk.yml' do
13
+ before(:each) { run_command('cfndk report') }
14
+ it 'displays file does not exist error and status code = 1' do
15
+ aggregate_failures do
16
+ expect(last_command_started).to have_exit_status(1)
17
+ expect(last_command_started).to have_output(/ERROR RuntimeError: File does not exist./)
18
+ end
19
+ end
20
+ end
21
+ context 'with cfndk2.yml' do
22
+ context 'when -c cfndk2.yml and empty keyparis and stacks' do
23
+ yaml = <<-"YAML"
24
+ keypairs:
25
+ stacks:
26
+ YAML
27
+ before(:each) { write_file('cfndk2.yml', yaml) }
28
+ before(:each) { run_command('cfndk report -c=cfndk2.yml') }
29
+ it 'displays empty stacks and keypairs report' do
30
+ aggregate_failures do
31
+ expect(last_command_started).to be_successfully_executed
32
+ expect(last_command_started).to have_output(/INFO report.../)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ context 'with cfndk.yml' do
38
+ context 'when cfndk.yml is empty' do
39
+ before(:each) { touch('cfndk.yml') }
40
+ before(:each) { run_command('cfndk report') }
41
+ it 'displays File is empty error and status code = 1' do
42
+ aggregate_failures do
43
+ expect(last_command_started).to have_exit_status(1)
44
+ expect(last_command_started).to have_output(/ERROR File is empty./)
45
+ end
46
+ end
47
+ end
48
+
49
+ context 'with empty keypairs and stacks' do
50
+ yaml = <<-"YAML"
51
+ keypairs:
52
+ stacks:
53
+ YAML
54
+ before(:each) { write_file('cfndk.yml', yaml) }
55
+ before(:each) { run_command('cfndk report') }
56
+ it 'displays empty stacks and keypairs report' do
57
+ aggregate_failures do
58
+ expect(last_command_started).to be_successfully_executed
59
+ expect(last_command_started).to have_output(/INFO report.../)
60
+ end
61
+ end
62
+ end
63
+
64
+ context 'with keypairs and stacks' do
65
+ yaml = <<-"YAML"
66
+ keypairs:
67
+ Key1:
68
+ Key2:
69
+ stacks:
70
+ Test:
71
+ template_file: vpc.yaml
72
+ parameter_input: vpc.json
73
+ timeout_in_minutes: 2
74
+ Test2:
75
+ template_file: sg.yaml
76
+ parameter_input: sg.json
77
+ depends:
78
+ - Test
79
+ YAML
80
+ context 'without UUID' do
81
+ before(:each) { write_file('cfndk.yml', yaml) }
82
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
83
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
84
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
85
+ before(:each) { copy('%/sg.json', 'sg.json') }
86
+ before(:each) { run_command_and_stop('cfndk create') }
87
+ context 'without option' do
88
+ before(:each) { run_command('cfndk report') }
89
+ it 'displays stacks report' do
90
+ aggregate_failures do
91
+ expect(last_command_started).to be_successfully_executed
92
+ expect(last_command_started).to have_output(/INFO stack: Test$/)
93
+ expect(last_command_started).to have_output(/INFO stack: Test2$/)
94
+ end
95
+ end
96
+ end
97
+ context 'when --stack-names Test2' do
98
+ before(:each) { run_command('cfndk report --stack-names Test2') }
99
+ it 'displays stacks report' do
100
+ aggregate_failures do
101
+ expect(last_command_started).to be_successfully_executed
102
+ expect(last_command_started).not_to have_output(/INFO stack: Test$/)
103
+ expect(last_command_started).to have_output(/INFO stack: Test2$/)
104
+ end
105
+ end
106
+ end
107
+ context 'when --stack-names Test3' do
108
+ before(:each) { run_command('cfndk report --stack-names Test3') }
109
+ it 'displays stacks report' do
110
+ aggregate_failures do
111
+ expect(last_command_started).to be_successfully_executed
112
+ expect(last_command_started).not_to have_output(/INFO stack: Test$/)
113
+ expect(last_command_started).not_to have_output(/INFO stack: Test2$/)
114
+ expect(last_command_started).not_to have_output(/INFO stack: Test3$/)
115
+ end
116
+ end
117
+ end
118
+ after(:each) { run_command('cfndk destroy -f') }
119
+ end
120
+ context 'with UUID' do
121
+ before(:each) { write_file('cfndk.yml', yaml) }
122
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
123
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
124
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
125
+ before(:each) { copy('%/sg.json', 'sg.json') }
126
+ before(:each) { run_command_and_stop('cfndk create -u 38437346-c75c-47c5-83b4-d504f85e275b') }
127
+ context 'without option' do
128
+ before(:each) { run_command('cfndk report -u 38437346-c75c-47c5-83b4-d504f85e275b') }
129
+ it 'displays stacks report' do
130
+ aggregate_failures do
131
+ expect(last_command_started).to be_successfully_executed
132
+ expect(last_command_started).to have_output(/INFO stack: Test-38437346-c75c-47c5-83b4-d504f85e275b$/)
133
+ expect(last_command_started).to have_output(/INFO stack: Test2-38437346-c75c-47c5-83b4-d504f85e275b$/)
134
+ end
135
+ end
136
+ end
137
+ context 'when --stack-names Test2' do
138
+ before(:each) { run_command('cfndk report -u 38437346-c75c-47c5-83b4-d504f85e275b --stack-names Test2') }
139
+ it 'displays stacks report' do
140
+ aggregate_failures do
141
+ expect(last_command_started).to be_successfully_executed
142
+ expect(last_command_started).not_to have_output(/INFO stack: Test-38437346-c75c-47c5-83b4-d504f85e275b$/)
143
+ expect(last_command_started).to have_output(/INFO stack: Test2-38437346-c75c-47c5-83b4-d504f85e275b$/)
144
+ end
145
+ end
146
+ end
147
+ context 'when --stack-names Test3' do
148
+ before(:each) { run_command('cfndk report -u 38437346-c75c-47c5-83b4-d504f85e275b --stack-names Test3') }
149
+ it 'displays stacks report' do
150
+ aggregate_failures do
151
+ expect(last_command_started).to be_successfully_executed
152
+ expect(last_command_started).not_to have_output(/INFO stack: Test-/)
153
+ expect(last_command_started).not_to have_output(/INFO stack: Test2-/)
154
+ expect(last_command_started).not_to have_output(/INFO stack: Test3-/)
155
+ end
156
+ end
157
+ end
158
+ after(:each) { run_command('cfndk destroy -f -u 38437346-c75c-47c5-83b4-d504f85e275b') }
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,103 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'CFnDK', type: :aruba do
4
+ before(:each) { set_environment_variable('AWS_REGION', ENV['AWS_REGION']) }
5
+ before(:each) { set_environment_variable('AWS_PROFILE', ENV['AWS_PROFILE']) }
6
+ before(:each) { set_environment_variable('AWS_ACCESS_KEY_ID', ENV["AWS_ACCESS_KEY_ID#{ENV['TEST_ENV_NUMBER']}"]) }
7
+ before(:each) { set_environment_variable('AWS_SECRET_ACCESS_KEY', ENV["AWS_SECRET_ACCESS_KEY#{ENV['TEST_ENV_NUMBER']}"]) }
8
+ describe 'bin/cfndk' do
9
+ before(:each) { setup_aruba }
10
+ let(:file) { 'cfndk.yml' }
11
+ let(:file2) { 'cfndk2.yml' }
12
+ let(:pem) { 'test.pem' }
13
+ let(:uuid) { '38437346-c75c-47c5-83b4-d504f85e275b' }
14
+
15
+ context 'without command', help: true do
16
+ before(:each) { run_command('cfndk') }
17
+ it 'displays help and status code = 2' do
18
+ aggregate_failures do
19
+ expect(last_command_started).to have_exit_status(2)
20
+ end
21
+ end
22
+ end
23
+
24
+ context 'invalid command' do
25
+ before(:each) { run_command('cfndk sstack') }
26
+ it 'displays help and status code = 1' do
27
+ aggregate_failures do
28
+ expect(last_command_started).to have_exit_status(1)
29
+ expect(last_command_started).to have_output(/Could not find command "sstack"\./)
30
+ end
31
+ end
32
+ end
33
+
34
+ describe 'version', help: true do
35
+ before(:each) { run_command('cfndk version') }
36
+ it 'displays version' do
37
+ aggregate_failures do
38
+ expect(last_command_started).to be_successfully_executed
39
+ expect(last_command_started).to have_output(/0.1.2/)
40
+ end
41
+ end
42
+ end
43
+
44
+ describe 'generate-uuid', uuid: true do
45
+ before(:each) { run_command('cfndk generate-uuid') }
46
+ it 'displays UUID' do
47
+ aggregate_failures do
48
+ expect(last_command_started).to be_successfully_executed
49
+ expect(last_command_started).to have_output(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/)
50
+ end
51
+ end
52
+ end
53
+
54
+ describe 'help', help: true do
55
+ context 'without subcommand' do
56
+ before(:each) { run_command('cfndk help') }
57
+ it 'displays help and status code = 2' do
58
+ aggregate_failures do
59
+ expect(last_command_started).to have_exit_status(2)
60
+ end
61
+ end
62
+ end
63
+
64
+ describe 'version' do
65
+ before(:each) { run_command('cfndk help version') }
66
+ it 'displays help of version and status code = 2' do
67
+ aggregate_failures do
68
+ expect(last_command_started).to have_exit_status(2)
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ describe 'init', init: true do
75
+ context 'without cfndk.yml' do
76
+ before(:each) { run_command('cfndk init') }
77
+ it do
78
+ aggregate_failures do
79
+ expect(last_command_started).to be_successfully_executed
80
+ expect(last_command_started).to have_output(/INFO init\.\.\..+INFO create .+cfndk.yml$/m)
81
+ expect('cfndk.yml').to be_an_existing_file
82
+ expect('web/web.yaml').to be_an_existing_file
83
+ expect('web/prod.json').to be_an_existing_file
84
+ expect('network/network.yaml').to be_an_existing_file
85
+ expect('web/prod.json').to be_an_existing_file
86
+ end
87
+ end
88
+ end
89
+
90
+ context 'with cfndk.yml' do
91
+ before(:each) { touch(file) }
92
+ before(:each) { run_command('cfndk init') }
93
+ it do
94
+ aggregate_failures do
95
+ expect(last_command_started).to have_exit_status(1)
96
+ expect(last_command_started).to have_output(/ERROR File exist./)
97
+ expect('web/web.yaml').to_not be_an_existing_file
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,814 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'CFnDK', type: :aruba do
4
+ before(:each) { set_environment_variable('AWS_REGION', ENV['AWS_REGION']) }
5
+ before(:each) { set_environment_variable('AWS_PROFILE', ENV['AWS_PROFILE']) }
6
+ before(:each) { set_environment_variable('AWS_ACCESS_KEY_ID', ENV["AWS_ACCESS_KEY_ID#{ENV['TEST_ENV_NUMBER']}"]) }
7
+ before(:each) { set_environment_variable('AWS_SECRET_ACCESS_KEY', ENV["AWS_SECRET_ACCESS_KEY#{ENV['TEST_ENV_NUMBER']}"]) }
8
+ describe 'bin/cfndk' do
9
+ before(:each) { setup_aruba }
10
+ let(:file) { 'cfndk.yml' }
11
+ let(:file2) { 'cfndk2.yml' }
12
+ let(:pem) { 'test.pem' }
13
+ let(:uuid) { '38437346-c75c-47c5-83b4-d504f85e275b' }
14
+
15
+ describe 'stack' do
16
+ describe 'create', create: true do
17
+ context 'without cfndk.yml' do
18
+ before(:each) { run_command('cfndk stack create') }
19
+ it 'displays file does not exist error and status code = 1' do
20
+ aggregate_failures do
21
+ expect(last_command_started).to have_exit_status(1)
22
+ expect(last_command_started).to have_output(/ERROR RuntimeError: File does not exist./)
23
+ end
24
+ end
25
+ end
26
+
27
+ context 'with cfndk2.yml' do
28
+ yaml = <<-"YAML"
29
+ keypairs:
30
+ YAML
31
+ before(:each) { write_file(file2, yaml) }
32
+ context 'when -c cfndk2.yml and empty stacks' do
33
+ before(:each) { run_command("cfndk stack create -c=#{file2}") }
34
+ it 'displays empty stack log' do
35
+ aggregate_failures do
36
+ expect(last_command_started).to be_successfully_executed
37
+ expect(last_command_started).to have_output(/INFO create.../)
38
+ end
39
+ end
40
+ end
41
+
42
+ context 'when --config-path cfndk2.yml and empty stacks' do
43
+ before(:each) { run_command("cfndk stack create --config-path=#{file2}") }
44
+ it 'displays empty stack log' do
45
+ aggregate_failures do
46
+ expect(last_command_started).to be_successfully_executed
47
+ expect(last_command_started).to have_output(/INFO create.../)
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ context 'with cfndk.yml' do
54
+ context 'when cfndk.yml is empty' do
55
+ before(:each) { touch(file) }
56
+ before(:each) { run_command('cfndk stack create') }
57
+ it 'displays File is empty error and status code = 1' do
58
+ aggregate_failures do
59
+ expect(last_command_started).to have_exit_status(1)
60
+ expect(last_command_started).to have_output(/ERROR File is empty./)
61
+ end
62
+ end
63
+ end
64
+
65
+ context 'with stacks:' do
66
+ context 'without stack' do
67
+ before(:each) { write_file(file, 'stacks:') }
68
+ before(:each) { run_command('cfndk stack create') }
69
+ it do
70
+ aggregate_failures do
71
+ expect(last_command_started).to be_successfully_executed
72
+ expect(last_command_started).to have_output(/INFO create.../)
73
+ end
74
+ end
75
+ end
76
+
77
+ context 'with a stack' do
78
+ yaml = <<-"YAML"
79
+ global:
80
+ stacks:
81
+ Test:
82
+ template_file: vpc.yaml
83
+ parameter_input: vpc.json
84
+ timeout_in_minutes: 2
85
+ YAML
86
+ before(:each) { write_file(file, yaml) }
87
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
88
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
89
+ before(:each) { run_command('cfndk stack create') }
90
+ it do
91
+ aggregate_failures do
92
+ expect(last_command_started).to be_successfully_executed
93
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
94
+ expect(last_command_started).to have_output(/INFO creating stack: Test$/)
95
+ expect(last_command_started).to have_output(/INFO created stack: Test$/)
96
+ end
97
+ end
98
+ after(:each) { run_command('cfndk destroy -f') }
99
+ end
100
+ context 'with a stack and enabled is true', enabled: true do
101
+ yaml = <<-"YAML"
102
+ global:
103
+ stacks:
104
+ Test:
105
+ template_file: vpc.yaml
106
+ parameter_input: vpc.json
107
+ timeout_in_minutes: 2
108
+ enabled: true
109
+ YAML
110
+ before(:each) { write_file(file, yaml) }
111
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
112
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
113
+ before(:each) { run_command('cfndk stack create') }
114
+ it do
115
+ aggregate_failures do
116
+ expect(last_command_started).to be_successfully_executed
117
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
118
+ expect(last_command_started).to have_output(/INFO creating stack: Test$/)
119
+ expect(last_command_started).to have_output(/INFO created stack: Test$/)
120
+ end
121
+ end
122
+ after(:each) { run_command('cfndk destroy -f') }
123
+ end
124
+ context 'with a stack and enabled is false', enabled: true do
125
+ yaml = <<-"YAML"
126
+ global:
127
+ stacks:
128
+ Test:
129
+ template_file: vpc.yaml
130
+ parameter_input: vpc.json
131
+ timeout_in_minutes: 2
132
+ enabled: false
133
+ YAML
134
+ before(:each) { write_file(file, yaml) }
135
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
136
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
137
+ before(:each) { run_command('cfndk stack create') }
138
+ it do
139
+ aggregate_failures do
140
+ expect(last_command_started).to be_successfully_executed
141
+ expect(last_command_started).to have_output(/INFO create.../)
142
+ expect(last_command_started).not_to have_output(/INFO validate stack: Test$/)
143
+ expect(last_command_started).not_to have_output(/INFO creating stack: Test$/)
144
+ expect(last_command_started).not_to have_output(/INFO created stack: Test$/)
145
+ end
146
+ end
147
+ after(:each) { run_command('cfndk destroy -f') }
148
+ end
149
+ context 'with a 51200byte template stack' do
150
+ yaml = <<-"YAML"
151
+ global:
152
+ stacks:
153
+ Test:
154
+ template_file: vpc.yaml
155
+ parameter_input: vpc.json
156
+ timeout_in_minutes: 2
157
+ YAML
158
+ before(:each) { write_file(file, yaml) }
159
+ before(:each) { copy('%/big_vpc.yaml', 'vpc.yaml') }
160
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
161
+ before(:each) { run_command('cfndk stack create') }
162
+ it 'displays created stack log' do
163
+ aggregate_failures do
164
+ expect(last_command_started).to be_successfully_executed
165
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
166
+ expect(last_command_started).to have_output(/INFO creating stack: Test$/)
167
+ expect(last_command_started).to have_output(/INFO created stack: Test$/)
168
+ expect(last_command_started).not_to have_output(%r{INFO Put S3 object: https://s3.amazonaws.com/[0-9]+-ap-northeast-1-cfndk-templates})
169
+ end
170
+ end
171
+ after(:each) { run_command('cfndk destroy -f') }
172
+ end
173
+ context 'with a 51201byte template stack', big: true, bigbig: true do
174
+ yaml = <<-"YAML"
175
+ global:
176
+ stacks:
177
+ Test:
178
+ template_file: vpc.yaml
179
+ parameter_input: vpc.json
180
+ timeout_in_minutes: 2
181
+ YAML
182
+ before(:each) { write_file(file, yaml) }
183
+ before(:each) { copy('%/big_vpc.yaml', 'vpc.yaml') }
184
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
185
+ before(:each) { append_to_file('vpc.yaml', '1') }
186
+ before(:each) { run_command('cfndk stack create') }
187
+ it 'displays created stack log' do
188
+ aggregate_failures do
189
+ expect(last_command_started).to be_successfully_executed
190
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
191
+ expect(last_command_started).to have_output(/INFO creating stack: Test$/)
192
+ expect(last_command_started).to have_output(/INFO created stack: Test$/)
193
+ expect(last_command_started).to have_output(%r{INFO Put S3 object: https://s3.amazonaws.com/[0-9]+-ap-northeast-1-cfndk-templates})
194
+ end
195
+ end
196
+ after(:each) { run_command('cfndk destroy -f') }
197
+ end
198
+ context 'with stack and nested stack', nested: true do
199
+ yaml = <<-"YAML"
200
+ global:
201
+ stacks:
202
+ Test:
203
+ template_file: vpc.yaml
204
+ parameter_input: vpc.json
205
+ timeout_in_minutes: 2
206
+ package: true
207
+ YAML
208
+ before(:each) { write_file(file, yaml) }
209
+ before(:each) { copy('%/stack.yaml', 'vpc.yaml') }
210
+ before(:each) { copy('%/stack.json', 'vpc.json') }
211
+ before(:each) { copy('%/nested_stack.yaml', 'nested_stack.yaml') }
212
+ before(:each) { run_command('cfndk stack create') }
213
+ it 'displays created stack log' do
214
+ aggregate_failures do
215
+ expect(last_command_started).to be_successfully_executed
216
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
217
+ expect(last_command_started).to have_output(/INFO creating stack: Test$/)
218
+ expect(last_command_started).to have_output(/INFO created stack: Test$/)
219
+ expect(last_command_started).to have_output(%r{INFO Put S3 object: https://s3.amazonaws.com/[0-9]+-ap-northeast-1-cfndk-templates/.+/nested_stack.yaml})
220
+ end
221
+ end
222
+ after(:each) { run_command('cfndk destroy -f') }
223
+ end
224
+ context 'with stack with directory and nested stack', directory_nested: true do
225
+ yaml = <<-"YAML"
226
+ global:
227
+ stacks:
228
+ Test:
229
+ template_file: vpc/vpc.yaml
230
+ parameter_input: vpc/vpc.json
231
+ timeout_in_minutes: 2
232
+ package: true
233
+ YAML
234
+ before(:each) { write_file(file, yaml) }
235
+ before(:each) { copy('%/stack.yaml', 'vpc/vpc.yaml') }
236
+ before(:each) { copy('%/stack.json', 'vpc/vpc.json') }
237
+ before(:each) { copy('%/nested_stack.yaml', 'vpc/nested_stack.yaml') }
238
+ before(:each) { run_command('cfndk stack create') }
239
+ it 'displays created stack log' do
240
+ aggregate_failures do
241
+ expect(last_command_started).to be_successfully_executed
242
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
243
+ expect(last_command_started).to have_output(/INFO creating stack: Test$/)
244
+ expect(last_command_started).to have_output(/INFO created stack: Test$/)
245
+ expect(last_command_started).to have_output(%r{INFO Put S3 object: https://s3.amazonaws.com/[0-9]+-ap-northeast-1-cfndk-templates/.+/nested_stack.yaml})
246
+ end
247
+ end
248
+ after(:each) { run_command('cfndk destroy -f') }
249
+ end
250
+ context 'with a 51201byte template stack and nested stack', nested: true, big: true, nested_big: true do
251
+ yaml = <<-"YAML"
252
+ global:
253
+ stacks:
254
+ Test:
255
+ template_file: vpc.yaml
256
+ parameter_input: vpc.json
257
+ timeout_in_minutes: 2
258
+ package: true
259
+ YAML
260
+ before(:each) { write_file(file, yaml) }
261
+ before(:each) { copy('%/stack.yaml', 'vpc.yaml') }
262
+ before(:each) { copy('%/stack.json', 'vpc.json') }
263
+ before(:each) { copy('%/nested_stack.yaml', 'nested_stack.yaml') }
264
+ before(:each) {
265
+ append_to_file('vpc.yaml', "\nOutputs:\n")
266
+ for number in 1..40 do
267
+ stack_append = <<-"YAML"
268
+ VpcId012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345#{number.to_s}:
269
+ Description: 01234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678901234567890123
270
+ Value: !Ref Vpc
271
+ Export:
272
+ Name: !Sub ${VpcName}-VpcId012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345#{number.to_s}
273
+ YAML
274
+ append_to_file('vpc.yaml', stack_append)
275
+ # p read('vpc.yaml').join("\n").length
276
+ end
277
+ }
278
+ before(:each) { append_to_file('nested_stack.yaml', "\n" + '#' * (51200 + 1 - 2 - file_size('nested_stack.yaml').to_i)) }
279
+ before(:each) { run_command('cfndk stack create') }
280
+ it 'displays created stack log' do
281
+ aggregate_failures do
282
+ expect(last_command_started).to be_successfully_executed
283
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
284
+ expect(last_command_started).to have_output(/INFO creating stack: Test$/)
285
+ expect(last_command_started).to have_output(/INFO created stack: Test$/)
286
+ expect(last_command_started).to have_output(%r{INFO Put S3 object: https://s3.amazonaws.com/[0-9]+-ap-northeast-1-cfndk-templates/.+/vpc.yaml})
287
+ expect(last_command_started).to have_output(%r{INFO Put S3 object: https://s3.amazonaws.com/[0-9]+-ap-northeast-1-cfndk-templates/.+/nested_stack.yaml})
288
+ end
289
+ end
290
+ after(:each) { run_command('cfndk destroy -f') }
291
+ end
292
+ context 'with json stack and json nested stack', nested: true, json: true do
293
+ yaml = <<-"YAML"
294
+ global:
295
+ stacks:
296
+ Test:
297
+ template_file: vpc.template.json
298
+ parameter_input: vpc.json
299
+ timeout_in_minutes: 2
300
+ package: true
301
+ YAML
302
+ before(:each) { write_file(file, yaml) }
303
+ before(:each) { copy('%/stack.template.json', 'vpc.template.json') }
304
+ before(:each) { copy('%/stack.json', 'vpc.json') }
305
+ before(:each) { copy('%/nested_stack.json', 'nested_stack.json') }
306
+ before(:each) { run_command('cfndk stack create') }
307
+ it 'displays created stack log' do
308
+ aggregate_failures do
309
+ expect(last_command_started).to be_successfully_executed
310
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
311
+ expect(last_command_started).to have_output(/INFO creating stack: Test$/)
312
+ expect(last_command_started).to have_output(/INFO created stack: Test$/)
313
+ expect(last_command_started).to have_output(%r{INFO Put S3 object: https://s3.amazonaws.com/[0-9]+-ap-northeast-1-cfndk-templates/.+/nested_stack.json})
314
+ end
315
+ end
316
+ after(:each) { run_command('cfndk destroy -f') }
317
+ end
318
+ context 'with lambda function and zip file', lambda_function: true do
319
+ yaml = <<-"YAML"
320
+ global:
321
+ stacks:
322
+ Test:
323
+ template_file: lambda_function.yaml
324
+ parameter_input: lambda_function.json
325
+ timeout_in_minutes: 2
326
+ capabilities:
327
+ - CAPABILITY_IAM
328
+ package: true
329
+ YAML
330
+ before(:each) { write_file(file, yaml) }
331
+ before(:each) { copy('%/lambda_function/lambda_function.yaml', 'lambda_function.yaml') }
332
+ before(:each) { copy('%/lambda_function/lambda_function.json', 'lambda_function.json') }
333
+ before(:each) { copy('%/lambda_function/index.js', 'lambda_function/index.js') }
334
+ before(:each) { run_command('cfndk stack create') }
335
+ it 'displays created stack log' do
336
+ aggregate_failures do
337
+ expect(last_command_started).to be_successfully_executed
338
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
339
+ expect(last_command_started).to have_output(/INFO creating stack: Test$/)
340
+ expect(last_command_started).to have_output(/INFO created stack: Test$/)
341
+ expect(last_command_started).to have_output(%r{INFO Put S3 object: https://s3.amazonaws.com/[0-9]+-ap-northeast-1-cfndk-templates/.+/lambda_function.zip})
342
+ end
343
+ end
344
+ after(:each) { run_command('cfndk destroy -f') }
345
+ end
346
+ context 'with serverless function and zip file', serverless_function: true do
347
+ yaml = <<-"YAML"
348
+ global:
349
+ stacks:
350
+ Test:
351
+ template_file: serverless_function.yaml
352
+ parameter_input: serverless_function.json
353
+ timeout_in_minutes: 2
354
+ capabilities:
355
+ - CAPABILITY_AUTO_EXPAND
356
+ - CAPABILITY_IAM
357
+ package: true
358
+ YAML
359
+ before(:each) { write_file(file, yaml) }
360
+ before(:each) { copy('%/serverless_function/serverless_function.yaml', 'serverless_function.yaml') }
361
+ before(:each) { copy('%/serverless_function/serverless_function.json', 'serverless_function.json') }
362
+ before(:each) { copy('%/serverless_function/index.js', 'serverless_function/index.js') }
363
+ before(:each) { run_command('cfndk stack create') }
364
+ it 'displays created stack log' do
365
+ aggregate_failures do
366
+ expect(last_command_started).to be_successfully_executed
367
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
368
+ expect(last_command_started).to have_output(/INFO creating stack: Test$/)
369
+ expect(last_command_started).to have_output(/INFO created stack: Test$/)
370
+ expect(last_command_started).to have_output(%r{INFO Put S3 object: https://s3.amazonaws.com/[0-9]+-ap-northeast-1-cfndk-templates/.+/serverless_function.zip})
371
+ end
372
+ end
373
+ after(:each) { run_command('cfndk destroy -f') }
374
+ end
375
+ context 'with two stacks' do
376
+ yaml = <<-"YAML"
377
+ stacks:
378
+ Test:
379
+ template_file: vpc.yaml
380
+ parameter_input: vpc.json
381
+ timeout_in_minutes: 2
382
+ Test2:
383
+ template_file: sg.yaml
384
+ parameter_input: sg.json
385
+ depends:
386
+ - Test
387
+ YAML
388
+
389
+ before(:each) { write_file(file, yaml) }
390
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
391
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
392
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
393
+ before(:each) { copy('%/sg.json', 'sg.json') }
394
+ before(:each) { run_command('cfndk stack create') }
395
+ it do
396
+ aggregate_failures do
397
+ expect(last_command_started).to be_successfully_executed
398
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
399
+ expect(last_command_started).to have_output(/INFO creating stack: Test$/)
400
+ expect(last_command_started).to have_output(/INFO created stack: Test$/)
401
+ expect(last_command_started).to have_output(/INFO validate stack: Test2$/)
402
+ expect(last_command_started).to have_output(/INFO creating stack: Test2$/)
403
+ expect(last_command_started).to have_output(/INFO created stack: Test2$/)
404
+ end
405
+ end
406
+ after(:each) { run_command('cfndk destroy -f') }
407
+ end
408
+ context 'with stack and command', global_pre_command: true, global_post_command: true, pre_command: true, post_command: true do
409
+ yaml = <<-"YAML"
410
+ global:
411
+ pre_command: echo "global pre command"
412
+ post_command: echo "global post command"
413
+ stacks:
414
+ Test:
415
+ template_file: vpc.yaml
416
+ parameter_input: vpc.json
417
+ timeout_in_minutes: 2
418
+ pre_command: echo "Test pre command"
419
+ post_command: echo "Test post command"
420
+ YAML
421
+
422
+ before(:each) { write_file(file, yaml) }
423
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
424
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
425
+ before(:each) { run_command('cfndk stack create') }
426
+ it do
427
+ aggregate_failures do
428
+ expect(last_command_started).to be_successfully_executed
429
+ expect(last_command_started).to have_output(/INFO execute global pre command: echo "global pre command"$/)
430
+ expect(last_command_started).to have_output(/INFO global pre command$/)
431
+ expect(last_command_started).to have_output(/INFO execute pre command: echo "Test pre command"$/)
432
+ expect(last_command_started).to have_output(/INFO Test pre command$/)
433
+ expect(last_command_started).to have_output(/INFO validate stack: Test$/)
434
+ expect(last_command_started).to have_output(/INFO creating stack: Test$/)
435
+ expect(last_command_started).to have_output(/INFO created stack: Test$/)
436
+ expect(last_command_started).to have_output(/INFO execute post command: echo "Test post command"$/)
437
+ expect(last_command_started).to have_output(/INFO Test post command$/)
438
+ expect(last_command_started).to have_output(/INFO execute global post command: echo "global post command"$/)
439
+ expect(last_command_started).to have_output(/INFO global post command$/)
440
+ end
441
+ end
442
+ after(:each) { run_command('cfndk destroy -f') }
443
+ end
444
+
445
+ context 'with stack and error global pre command', global_pre_command: true do
446
+ yaml = <<-"YAML"
447
+ global:
448
+ pre_command: exit 1
449
+ stacks:
450
+ Test:
451
+ template_file: vpc.yaml
452
+ parameter_input: vpc.json
453
+ timeout_in_minutes: 2
454
+ YAML
455
+
456
+ before(:each) { write_file(file, yaml) }
457
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
458
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
459
+ before(:each) { run_command('cfndk stack create') }
460
+ it do
461
+ aggregate_failures do
462
+ expect(last_command_started).not_to be_successfully_executed
463
+ expect(last_command_started).to have_output(/INFO execute global pre command: exit 1$/)
464
+ expect(last_command_started).to have_output(/ERROR RuntimeError: global pre command is error. status: 1 command: exit 1$/)
465
+ end
466
+ end
467
+ after(:each) { run_command('cfndk destroy -f') }
468
+ end
469
+
470
+ context 'with stack and error global post command', global_post_command: true do
471
+ yaml = <<-"YAML"
472
+ global:
473
+ post_command: exit 1
474
+ stacks:
475
+ Test:
476
+ template_file: vpc.yaml
477
+ parameter_input: vpc.json
478
+ timeout_in_minutes: 2
479
+ YAML
480
+
481
+ before(:each) { write_file(file, yaml) }
482
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
483
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
484
+ before(:each) { run_command('cfndk stack create') }
485
+ it do
486
+ aggregate_failures do
487
+ expect(last_command_started).not_to be_successfully_executed
488
+ expect(last_command_started).to have_output(/INFO execute global post command: exit 1$/)
489
+ expect(last_command_started).to have_output(/ERROR RuntimeError: global post command is error. status: 1 command: exit 1$/)
490
+ end
491
+ end
492
+ after(:each) { run_command('cfndk destroy -f') }
493
+ end
494
+
495
+ context 'with stack and error pre command', pre_command: true do
496
+ yaml = <<-"YAML"
497
+ stacks:
498
+ Test:
499
+ template_file: vpc.yaml
500
+ parameter_input: vpc.json
501
+ timeout_in_minutes: 2
502
+ pre_command: exit 1
503
+ YAML
504
+
505
+ before(:each) { write_file(file, yaml) }
506
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
507
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
508
+ before(:each) { run_command('cfndk stack create') }
509
+ it do
510
+ aggregate_failures do
511
+ expect(last_command_started).not_to be_successfully_executed
512
+ expect(last_command_started).to have_output(/INFO execute pre command: exit 1$/)
513
+ expect(last_command_started).to have_output(/ERROR RuntimeError: pre command is error. status: 1 command: exit 1$/)
514
+ end
515
+ end
516
+ after(:each) { run_command('cfndk destroy -f') }
517
+ end
518
+
519
+ context 'with stack and error post command', post_command: true do
520
+ yaml = <<-"YAML"
521
+ stacks:
522
+ Test:
523
+ template_file: vpc.yaml
524
+ parameter_input: vpc.json
525
+ timeout_in_minutes: 2
526
+ post_command: exit 1
527
+ YAML
528
+
529
+ before(:each) { write_file(file, yaml) }
530
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
531
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
532
+ before(:each) { run_command('cfndk stack create') }
533
+ it do
534
+ aggregate_failures do
535
+ expect(last_command_started).not_to be_successfully_executed
536
+ expect(last_command_started).to have_output(/INFO execute post command: exit 1$/)
537
+ expect(last_command_started).to have_output(/ERROR RuntimeError: post command is error. status: 1 command: exit 1$/)
538
+ end
539
+ end
540
+ after(:each) { run_command('cfndk destroy -f') }
541
+ end
542
+
543
+ context 'when invalid dependency', dependency: true do
544
+ yaml = <<-"YAML"
545
+ stacks:
546
+ Test:
547
+ template_file: vpc.yaml
548
+ parameter_input: vpc.json
549
+ timeout_in_minutes: 2
550
+ depends:
551
+ - Test2
552
+ Test2:
553
+ template_file: sg.yaml
554
+ parameter_input: sg.json
555
+ YAML
556
+
557
+ before(:each) { write_file(file, yaml) }
558
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
559
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
560
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
561
+ before(:each) { copy('%/sg.json', 'sg.json') }
562
+ before(:each) { run_command('cfndk stack create') }
563
+ it do
564
+ aggregate_failures do
565
+ expect(last_command_started).to have_exit_status(1)
566
+ expect(last_command_started).to have_output(/ERROR Aws::Waiters::Errors::FailureStateError: stopped waiting, encountered a failure state$/)
567
+ end
568
+ end
569
+ after(:each) { run_command('cfndk destroy -f') }
570
+ end
571
+ context 'when cyclic dependency', dependency: true do
572
+ yaml = <<-"YAML"
573
+ stacks:
574
+ Test:
575
+ template_file: vpc.yaml
576
+ parameter_input: vpc.json
577
+ timeout_in_minutes: 2
578
+ depends:
579
+ - Test2
580
+ Test2:
581
+ template_file: sg.yaml
582
+ parameter_input: sg.json
583
+ depends:
584
+ - Test
585
+ YAML
586
+
587
+ before(:each) { write_file(file, yaml) }
588
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
589
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
590
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
591
+ before(:each) { copy('%/sg.json', 'sg.json') }
592
+ before(:each) { run_command('cfndk stack create') }
593
+ it do
594
+ aggregate_failures do
595
+ expect(last_command_started).to have_exit_status(1)
596
+ expect(last_command_started).to have_output(/ERROR RuntimeError: There are cyclic dependency or stack doesn't exist. unprocessed_stack: Test,Test2$/)
597
+ end
598
+ end
599
+ after(:each) { run_command('cfndk destroy -f') }
600
+ end
601
+ context 'when requires capabilities without capabilities', capabilities: true do
602
+ yaml = <<-"YAML"
603
+ stacks:
604
+ Test:
605
+ template_file: iam.yaml
606
+ parameter_input: iam.json
607
+ timeout_in_minutes: 2
608
+ YAML
609
+
610
+ before(:each) { write_file(file, yaml) }
611
+ before(:each) { copy('%/iam.yaml', 'iam.yaml') }
612
+ before(:each) { copy('%/iam.json', 'iam.json') }
613
+ before(:each) { run_command('cfndk stack create') }
614
+ it do
615
+ aggregate_failures do
616
+ expect(last_command_started).to have_exit_status(1)
617
+ expect(last_command_started).to have_output(/ERROR Aws::CloudFormation::Errors::InsufficientCapabilitiesException: Requires capabilities : \[CAPABILITY_NAMED_IAM\]/)
618
+ end
619
+ end
620
+ after(:each) { run_command('cfndk destroy -f') }
621
+ end
622
+ context 'when success with capabilities', capabilities: true do
623
+ yaml = <<-"YAML"
624
+ stacks:
625
+ Test:
626
+ template_file: iam.yaml
627
+ parameter_input: iam.json
628
+ capabilities:
629
+ - CAPABILITY_NAMED_IAM
630
+ timeout_in_minutes: 3
631
+ YAML
632
+
633
+ before(:each) { write_file(file, yaml) }
634
+ before(:each) { copy('%/iam.yaml', 'iam.yaml') }
635
+ before(:each) { copy('%/iam.json', 'iam.json') }
636
+ before(:each) { run_command('cfndk stack create') }
637
+ it do
638
+ aggregate_failures do
639
+ expect(last_command_started).to be_successfully_executed
640
+ expect(last_command_started).to have_output(/INFO created stack: Test$/)
641
+ end
642
+ end
643
+ after(:each) { run_command('cfndk destroy -f') }
644
+ end
645
+ context 'with UUID', uuid: true do
646
+ context 'when -u 38437346-c75c-47c5-83b4-d504f85e275b' do
647
+ yaml = <<-"YAML"
648
+ stacks:
649
+ Test:
650
+ template_file: vpc.yaml
651
+ parameter_input: vpc.json
652
+ parameters:
653
+ VpcName: sample<%= append_uuid%>
654
+ timeout_in_minutes: 2
655
+ Test2:
656
+ template_file: sg.yaml
657
+ parameter_input: sg.json
658
+ parameters:
659
+ VpcName: sample<%= append_uuid%>
660
+ depends:
661
+ - Test
662
+ YAML
663
+ before(:each) { write_file(file, yaml) }
664
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
665
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
666
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
667
+ before(:each) { copy('%/sg.json', 'sg.json') }
668
+ before(:each) { run_command("cfndk stack create -u=#{uuid}") }
669
+ it do
670
+ aggregate_failures do
671
+ expect(last_command_started).to be_successfully_executed
672
+ expect(last_command_started).to have_output(/INFO validate stack: Test-#{uuid}$/)
673
+ expect(last_command_started).to have_output(/INFO creating stack: Test-#{uuid}$/)
674
+ expect(last_command_started).to have_output(/INFO created stack: Test-#{uuid}$/)
675
+ expect(last_command_started).to have_output(/INFO validate stack: Test2-#{uuid}$/)
676
+ expect(last_command_started).to have_output(/INFO creating stack: Test2-#{uuid}$/)
677
+ expect(last_command_started).to have_output(/INFO created stack: Test2-#{uuid}$/)
678
+ end
679
+ end
680
+ after(:each) { run_command("cfndk destroy -f -u=#{uuid}") }
681
+ end
682
+ context 'when env CFNDK_UUID=38437346-c75c-47c5-83b4-d504f85e275b' do
683
+ before(:each) { set_environment_variable('CFNDK_UUID', uuid) }
684
+ context 'with two stacks' do
685
+ yaml = <<-"YAML"
686
+ stacks:
687
+ Test:
688
+ template_file: vpc.yaml
689
+ parameter_input: vpc.json
690
+ parameters:
691
+ VpcName: sample<%= append_uuid%>
692
+ timeout_in_minutes: 2
693
+ Test2:
694
+ template_file: sg.yaml
695
+ parameter_input: sg.json
696
+ parameters:
697
+ VpcName: sample<%= append_uuid%>
698
+ depends:
699
+ - Test
700
+ YAML
701
+ before(:each) { write_file(file, yaml) }
702
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
703
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
704
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
705
+ before(:each) { copy('%/sg.json', 'sg.json') }
706
+ before(:each) { run_command('cfndk stack create') }
707
+ it do
708
+ aggregate_failures do
709
+ expect(last_command_started).to be_successfully_executed
710
+ expect(last_command_started).to have_output(/INFO validate stack: Test-#{uuid}$/)
711
+ expect(last_command_started).to have_output(/INFO creating stack: Test-#{uuid}$/)
712
+ expect(last_command_started).to have_output(/INFO created stack: Test-#{uuid}$/)
713
+ expect(last_command_started).to have_output(/INFO validate stack: Test2-#{uuid}$/)
714
+ expect(last_command_started).to have_output(/INFO creating stack: Test2-#{uuid}$/)
715
+ expect(last_command_started).to have_output(/INFO created stack: Test2-#{uuid}$/)
716
+ end
717
+ end
718
+ after(:each) { run_command('cfndk destroy -f') }
719
+ end
720
+ context 'when --stack-names=Test' do
721
+ yaml = <<-"YAML"
722
+ stacks:
723
+ Test:
724
+ template_file: vpc.yaml
725
+ parameter_input: vpc.json
726
+ parameters:
727
+ VpcName: sample<%= append_uuid%>
728
+ timeout_in_minutes: 2
729
+ Test2:
730
+ template_file: sg.yaml
731
+ parameter_input: sg.json
732
+ parameters:
733
+ VpcName: sample<%= append_uuid%>
734
+ depends:
735
+ - Test
736
+ YAML
737
+ before(:each) { write_file(file, yaml) }
738
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
739
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
740
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
741
+ before(:each) { copy('%/sg.json', 'sg.json') }
742
+ before(:each) { run_command('cfndk stack create --stack-names=Test') }
743
+ it do
744
+ aggregate_failures do
745
+ expect(last_command_started).to be_successfully_executed
746
+ expect(last_command_started).to have_output(/INFO create.../)
747
+ expect(last_command_started).to have_output(/INFO validate stack: Test-#{uuid}$/)
748
+ expect(last_command_started).to have_output(/INFO creating stack: Test-#{uuid}$/)
749
+ expect(last_command_started).to have_output(/INFO created stack: Test-#{uuid}$/)
750
+ expect(last_command_started).not_to have_output(/INFO validate stack: Test2-#{uuid}$/)
751
+ expect(last_command_started).not_to have_output(/INFO creating stack: Test2-#{uuid}$/)
752
+ expect(last_command_started).not_to have_output(/INFO created stack: Test2-#{uuid}$/)
753
+ end
754
+ end
755
+ after(:each) { run_command('cfndk destroy -f') }
756
+ end
757
+ context 'when --stack-names=Test Test2' do
758
+ yaml = <<-"YAML"
759
+ stacks:
760
+ Test:
761
+ template_file: vpc.yaml
762
+ parameter_input: vpc.json
763
+ parameters:
764
+ VpcName: sample<%= append_uuid%>
765
+ timeout_in_minutes: 2
766
+ Test2:
767
+ template_file: sg.yaml
768
+ parameter_input: sg.json
769
+ parameters:
770
+ VpcName: sample<%= append_uuid%>
771
+ depends:
772
+ - Test
773
+ Test3:
774
+ template_file: iam.yaml
775
+ parameter_input: iam.json
776
+ parameters:
777
+ WebRoleName: WebhRole<%= append_uuid%>
778
+ capabilities:
779
+ - CAPABILITY_NAMED_IAM
780
+ timeout_in_minutes: 3
781
+ YAML
782
+ before(:each) { write_file(file, yaml) }
783
+ before(:each) { copy('%/vpc.yaml', 'vpc.yaml') }
784
+ before(:each) { copy('%/vpc.json', 'vpc.json') }
785
+ before(:each) { copy('%/sg.yaml', 'sg.yaml') }
786
+ before(:each) { copy('%/sg.json', 'sg.json') }
787
+ before(:each) { copy('%/iam.yaml', 'iam.yaml') }
788
+ before(:each) { copy('%/iam.json', 'iam.json') }
789
+ before(:each) { run_command('cfndk stack create --stack-names=Test Test2') }
790
+ it do
791
+ aggregate_failures do
792
+ expect(last_command_started).to be_successfully_executed
793
+ expect(last_command_started).to have_output(/INFO create.../)
794
+ expect(last_command_started).to have_output(/INFO validate stack: Test-#{uuid}$/)
795
+ expect(last_command_started).to have_output(/INFO creating stack: Test-#{uuid}$/)
796
+ expect(last_command_started).to have_output(/INFO created stack: Test-#{uuid}$/)
797
+ expect(last_command_started).to have_output(/INFO validate stack: Test2-#{uuid}$/)
798
+ expect(last_command_started).to have_output(/INFO creating stack: Test2-#{uuid}$/)
799
+ expect(last_command_started).to have_output(/INFO created stack: Test2-#{uuid}$/)
800
+ expect(last_command_started).not_to have_output(/INFO validate stack: Test3-#{uuid}$/)
801
+ expect(last_command_started).not_to have_output(/INFO creating stack: Test3-#{uuid}$/)
802
+ expect(last_command_started).not_to have_output(/INFO created stack: Test3-#{uuid}$/)
803
+ end
804
+ end
805
+ after(:each) { run_command('cfndk destroy -f') }
806
+ end
807
+ end
808
+ end
809
+ end
810
+ end
811
+ end
812
+ end
813
+ end
814
+ end