cfndk 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32c22522a1cc1e7dfc9ca0aba8493db5f8db8eb8
4
- data.tar.gz: 769e02185ab86037a82889853ecfd93c3a3f912a
3
+ metadata.gz: b3c4548d36709c0c878369059819c9c458907a90
4
+ data.tar.gz: 2174f779691dfcf915aa1c6385c77b86556ca8eb
5
5
  SHA512:
6
- metadata.gz: 0d53377bb67a1f2b93a161353172b9984ec462f3ea430867b69ccd88cac81e237d4832fc247f6c7e83f16481636e45e79f9f6c80c7d95ea7e8adc6b6ffd10627
7
- data.tar.gz: 891db997bc6e5c174592f4fc6c98cd8b54572422417244ba7789b5d15228fba9dc0fd8cdc5e8429f3042725c27de88aa5f398de98469c40a9966fbb8d8721003
6
+ metadata.gz: 2922c25d64ec5264c56aad0488945bf24513e3d8cdae007c936494cf6fd96283a514b16a3c9bb91a3cc0cf82c8f0a614c4c6cf3adbed1c21f9701b5f95ae571f
7
+ data.tar.gz: e141aa53962fc3c3fd80f4f532583b90acef8f09429a841186973efb82c2947adbd06ac12c5f4d9fc7d4655a523d2d3d3f54cd0255cb095865cc654629cc3ae4
data/README.md CHANGED
@@ -138,11 +138,11 @@ cfndk report-stack-resource [option]
138
138
 
139
139
  実行時に詳細な情報を表示します。
140
140
 
141
- #### ```-c, --config_path <cfndi.yml>```
141
+ #### ```-c, --config_path cfndi.yml```
142
142
 
143
143
  カレントディレクトリのcfndi.ymlの代わりに、ファイルを指定します。
144
144
 
145
- #### ```-p, --properties <name>=<value>```
145
+ #### ```-p, --properties name=value```
146
146
 
147
147
  プロパティを追加します。
148
148
  cfndi.ymlのparametersのerb内で値で参照することができます。
@@ -154,13 +154,24 @@ UUIDが指定されるとスタック名に付加されます。
154
154
  またcfndi.ymlのparametersの値で参照することができます。
155
155
  ```-a```と```-u```は最後に指定されたものが有効になります。
156
156
 
157
- #### ```-u, --uuid <uuid>```
157
+ #### ```-u, --uuid uuid```
158
158
 
159
159
  指定されたUUIDを使用します。
160
160
  UUIDが指定されるとスタック名に付加されます。
161
161
  またcfndi.ymlのparametersの値で参照することができます。
162
162
  ```-a```と```-u```は最後に指定されたものが有効になります。
163
163
 
164
+ #### ```-s, --stack-names name1,name2```
165
+
166
+ create,update,destroy,create_or_changesetのコマンドで、指定されたスタック名のみを操作します。
167
+
168
+ #### ```--no-color```
169
+
170
+ メッセージ出力でカラーを抑制します。
171
+
172
+ ### ```-f, --force```
173
+
174
+ 動作の確認メッセージと入力をスキップします。
164
175
 
165
176
  ## 環境変数
166
177
 
data/bin/cfndk CHANGED
@@ -15,6 +15,20 @@ require 'securerandom'
15
15
 
16
16
  require 'cfndk.rb'
17
17
 
18
+ def do_destroy(option)
19
+ return true if option[:force]
20
+ loop do
21
+ print 'destroy? [yes|no]:'
22
+ res = STDIN.gets
23
+ case res
24
+ when /^yes/
25
+ return true
26
+ when /^no/, /^$/
27
+ return false
28
+ end
29
+ end
30
+ end
31
+
18
32
  $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
19
33
 
20
34
  cur_dir = Dir.getwd
@@ -23,12 +37,14 @@ option = {
23
37
  config_path: "#{cur_dir}/cfndk.yml",
24
38
  uuid: ENV['CFNDK_UUID'] || nil,
25
39
  properties: {},
40
+ stack_names: nil,
41
+ force: false,
26
42
  }
27
43
 
28
44
  opt = OptionParser.new do |o|
29
45
  o.version = CFnDK::VERSION
30
46
  o.summary_indent = ' ' * 4
31
- o.banner = 'Usage: cfndk [cmd] [options]'
47
+ o.banner = "Version: #{CFnDK::VERSION} \nUsage: cfndk [cmd] [options]"
32
48
  o.on_head('[cmd]',
33
49
  ' init create config YAML file',
34
50
  ' create create stacks',
@@ -49,8 +65,8 @@ opt = OptionParser.new do |o|
49
65
  " AWS_CONTAINER_CREDENTIALS_RELATIVE_URI: #{ENV['AWS_CONTAINER_CREDENTIALS_RELATIVE_URI']}",
50
66
  '[options]')
51
67
  o.on('-v', '--verbose', 'verbose mode') { |v| option[:v] = v }
52
- o.on('-c', '--config_path <cfndi.yml>', "config path (default: #{option[:config_path]})") { |v| option[:config_path] = v }
53
- o.on('-p', '--properties <name>=<value>', 'properties') do |v|
68
+ o.on('-c', '--config_path cfndi.yml', "config path (default: #{option[:config_path]})") { |v| option[:config_path] = v }
69
+ o.on('-p', '--properties name=value', 'properties') do |v|
54
70
  md = v.match(/^([a-zA-Z_]+[a-zA-Z0-9_]*)=(.*)$/)
55
71
  if md
56
72
  option[:properties][md[0]] = md[1]
@@ -59,7 +75,10 @@ opt = OptionParser.new do |o|
59
75
  end
60
76
  end
61
77
  o.on('-a', '--auto-uuid') { option[:uuid] = SecureRandom.uuid }
62
- o.on('-u', '--uuid <uuid>') { |v| option[:uuid] = v }
78
+ o.on('-u', '--uuid uuid') { |v| option[:uuid] = v }
79
+ o.on('-n', '--stack-names name1,name2') { |v| option[:stack_names] = v.split(/\s*,\s*/) }
80
+ o.on('--no-color') { |b| Rainbow.enabled = false }
81
+ o.on('-f', '--force') { |b| option[:force] = true }
63
82
  o.permute!(ARGV)
64
83
  end
65
84
 
@@ -92,18 +111,23 @@ keypairs = CFnDK::KeyPairs.new(data, option, credentials)
92
111
 
93
112
  if ARGV[0] == 'create'
94
113
  puts 'create...'.color :green
114
+ stacks.validate
95
115
  keypairs.create
96
116
  stacks.create
97
117
  elsif ARGV[0] == 'update'
98
118
  puts 'update...'.color :green
119
+ stacks.validate
99
120
  stacks.update
100
121
  elsif ARGV[0] == 'create-or-changeset'
101
122
  puts 'create or changeset...'.color :green
123
+ stacks.validate
102
124
  stacks.create_or_changeset
103
125
  elsif ARGV[0] == 'destroy'
104
126
  puts 'destroy...'.color :green
105
- stacks.destroy
106
- keypairs.destroy
127
+ if do_destroy(option)
128
+ stacks.destroy
129
+ keypairs.destroy
130
+ end
107
131
  elsif ARGV[0] == 'validate'
108
132
  puts 'validate...'.color :green
109
133
  stacks.validate
@@ -7,10 +7,12 @@ module CFnDK
7
7
  end
8
8
 
9
9
  def create
10
+ return if @option[:stack_names].instance_of?(Array)
10
11
  @keypairs.each_value(&:create)
11
12
  end
12
13
 
13
14
  def destroy
15
+ return if @option[:stack_names].instance_of?(Array)
14
16
  @keypairs.each_value(&:destroy)
15
17
  end
16
18
 
data/lib/cfndk/stacks.rb CHANGED
@@ -8,9 +8,9 @@ module CFnDK
8
8
  end
9
9
 
10
10
  def create
11
- validate
12
11
  @sequence.each do |stacks|
13
12
  stacks.each do |name|
13
+ next if @option[:stack_names].instance_of?(Array) && !@option[:stack_names].include?(name)
14
14
  puts(('creating ' + name).color(:green))
15
15
  puts('Name :' + @stacks[name].name) if @option[:v]
16
16
  puts('Parametres :' + @stacks[name].parameters.inspect) if @option[:v]
@@ -25,6 +25,7 @@ module CFnDK
25
25
  )
26
26
  end
27
27
  stacks.each do |name|
28
+ next if @option[:stack_names].instance_of?(Array) && !@option[:stack_names].include?(name)
28
29
  begin
29
30
  @cfn_client.wait_until(
30
31
  :stack_create_complete,
@@ -41,10 +42,10 @@ module CFnDK
41
42
  end
42
43
 
43
44
  def update
44
- validate
45
45
  @sequence.each do |stacks|
46
46
  updating_stacks = []
47
47
  stacks.each do |name|
48
+ next if @option[:stack_names].instance_of?(Array) && !@option[:stack_names].include?(name)
48
49
  puts(('updating ' + name).color(:green))
49
50
  puts('Name :' + @stacks[name].name) if @option[:v]
50
51
  puts('Parametres :' + @stacks[name].parameters.inspect) if @option[:v]
@@ -63,6 +64,7 @@ module CFnDK
63
64
  end
64
65
  end
65
66
  updating_stacks.each do |name|
67
+ next if @option[:stack_names].instance_of?(Array) && !@option[:stack_names].include?(name)
66
68
  @cfn_client.wait_until(
67
69
  :stack_update_complete,
68
70
  stack_name: @stacks[name].name
@@ -73,11 +75,11 @@ module CFnDK
73
75
  end
74
76
 
75
77
  def create_or_changeset
76
- validate
77
78
  @sequence.each do |stacks|
78
79
  create_stacks = []
79
80
  changeset_stacks = []
80
81
  stacks.each do |name|
82
+ next if @option[:stack_names].instance_of?(Array) && !@option[:stack_names].include?(name)
81
83
  begin
82
84
  @cfn_client.describe_stacks(
83
85
  stack_name: @stacks[name].name
@@ -111,6 +113,7 @@ module CFnDK
111
113
  end
112
114
  end
113
115
  create_stacks.each do |name|
116
+ next if @option[:stack_names].instance_of?(Array) && !@option[:stack_names].include?(name)
114
117
  @cfn_client.wait_until(
115
118
  :stack_create_complete,
116
119
  stack_name: @stacks[name].name
@@ -118,6 +121,7 @@ module CFnDK
118
121
  puts(('created ' + name).color(:green))
119
122
  end
120
123
  changeset_stacks.each do |name|
124
+ next if @option[:stack_names].instance_of?(Array) && !@option[:stack_names].include?(name)
121
125
  begin
122
126
  @cfn_client.wait_until(
123
127
  :change_set_create_complete,
@@ -266,6 +270,7 @@ module CFnDK
266
270
  def destroy
267
271
  @sequence.reverse_each do |stacks|
268
272
  stacks.each do |name|
273
+ next if @option[:stack_names].instance_of?(Array) && !@option[:stack_names].include?(name)
269
274
  puts(('deleting ' + name).color(:green))
270
275
  puts('Name :' + @stacks[name].name) if @option[:v]
271
276
  @cfn_client.delete_stack(
@@ -273,6 +278,7 @@ module CFnDK
273
278
  )
274
279
  end
275
280
  stacks.each do |name|
281
+ next if @option[:stack_names].instance_of?(Array) && !@option[:stack_names].include?(name)
276
282
  @cfn_client.wait_until(
277
283
  :stack_delete_complete,
278
284
  stack_name: @stacks[name].name
@@ -285,6 +291,7 @@ module CFnDK
285
291
  def validate
286
292
  @sequence.each do |stacks|
287
293
  stacks.each do |name|
294
+ next if @option[:stack_names].instance_of?(Array) && !@option[:stack_names].include?(name)
288
295
  puts(('validate ' + name).color(:green))
289
296
  puts('Name :' + @stacks[name].name) if @option[:v]
290
297
  @cfn_client.validate_template(
data/lib/cfndk/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CFnDK
2
- VERSION = '0.0.3'.freeze
2
+ VERSION = '0.0.4'.freeze
3
3
  end
data/sample/cfndk.yml CHANGED
@@ -41,6 +41,16 @@ stacks:
41
41
  - CFnDKSampleSg
42
42
  - CFnDKSampleIam
43
43
  timeout_in_minutes: 2
44
+ CFnDKSampleElb:
45
+ template_file: elb/elb.yaml
46
+ parameter_input: elb/prod.json
47
+ parameters:
48
+ VpcName: Sample<%= append_uuid %>
49
+ InternalDnsName: sample<%= append_uuid %>.local
50
+ depends:
51
+ - CFnDKSampleWeb
52
+ - CFnDKSampleSg
53
+ timeout_in_minutes: 5
44
54
  CFnDKSampleDb:
45
55
  template_file: db/db.yaml
46
56
  parameter_input: db/prod.json
data/sample/elb/elb.yaml CHANGED
@@ -1,8 +1,77 @@
1
1
  AWSTemplateFormatVersion: '2010-09-09'
2
2
  Description: ELB Stack
3
-
4
3
  Parameters:
5
-
4
+ VpcName:
5
+ Description: Name for this VPC
6
+ Type: String
7
+ InternalDnsName:
8
+ Description: Internal DNS name
9
+ Type: String
10
+ Environment:
11
+ Description: Name for this Environment
12
+ Type: String
13
+ WebElbHostName:
14
+ Description: Local DNS Name for ELB
15
+ Type: String
6
16
  Resources:
7
-
8
- Outputs:
17
+ WebLoadBalancer:
18
+ Type: "AWS::ElasticLoadBalancingV2::LoadBalancer"
19
+ Properties:
20
+ Type: application
21
+ Scheme: internet-facing
22
+ Subnets:
23
+ - Fn::ImportValue: !Sub ${VpcName}-${Environment}-Public-Subnet1
24
+ - Fn::ImportValue: !Sub ${VpcName}-${Environment}-Public-Subnet2
25
+ SecurityGroups:
26
+ - Fn::ImportValue: !Sub ${VpcName}-${Environment}-Web-ElbSg
27
+ Tags:
28
+ - Key: Name
29
+ Value: !Sub ${VpcName}-${Environment}-Web-Elb
30
+ WebLoadBalancerRecordSet:
31
+ Type: AWS::Route53::RecordSet
32
+ Properties:
33
+ HostedZoneId:
34
+ Fn::ImportValue: !Sub ${VpcName}-InternalDns
35
+ Comment: DNS name for ELB
36
+ Name:
37
+ !Join
38
+ - '.'
39
+ - - !Ref WebElbHostName
40
+ - Fn::ImportValue: !Sub ${VpcName}-InternalDnsName
41
+ Type: CNAME
42
+ TTL: '60'
43
+ ResourceRecords:
44
+ - !GetAtt WebLoadBalancer.DNSName
45
+ WebTargetGroup:
46
+ Type: AWS::ElasticLoadBalancingV2::TargetGroup
47
+ Properties:
48
+ HealthCheckIntervalSeconds: 30
49
+ HealthCheckPath: /
50
+ HealthCheckPort: "80"
51
+ HealthCheckProtocol: HTTP
52
+ HealthCheckTimeoutSeconds: 5
53
+ HealthyThresholdCount: 2
54
+ Port: 80
55
+ Protocol: HTTP
56
+ UnhealthyThresholdCount: 5
57
+ VpcId:
58
+ Fn::ImportValue: !Sub ${VpcName}-VpcId
59
+ Targets:
60
+ - Id:
61
+ Fn::ImportValue: !Sub ${VpcName}-${Environment}-Web1
62
+ Port: 80
63
+ - Id:
64
+ Fn::ImportValue: !Sub ${VpcName}-${Environment}-Web2
65
+ Port: 80
66
+ Tags:
67
+ - Key: Name
68
+ Value: !Sub ${VpcName}-Web-Tg
69
+ WebListener:
70
+ Type: AWS::ElasticLoadBalancingV2::Listener
71
+ Properties:
72
+ DefaultActions:
73
+ - Type: forward
74
+ TargetGroupArn: !Ref WebTargetGroup
75
+ LoadBalancerArn: !Ref WebLoadBalancer
76
+ Port: 80
77
+ Protocol: HTTP
data/sample/elb/prod.json CHANGED
@@ -0,0 +1,20 @@
1
+ {
2
+ "Parameters": [
3
+ {
4
+ "ParameterKey": "VpcName",
5
+ "ParameterValue": "sample"
6
+ },
7
+ {
8
+ "ParameterKey": "Environment",
9
+ "ParameterValue": "Prod"
10
+ },
11
+ {
12
+ "ParameterKey": "WebElbHostName",
13
+ "ParameterValue": "elb"
14
+ },
15
+ {
16
+ "ParameterKey": "InternalDnsName",
17
+ "ParameterValue": "sample.local"
18
+ }
19
+ ]
20
+ }
data/sample/sg/prod.json CHANGED
@@ -3,6 +3,10 @@
3
3
  {
4
4
  "ParameterKey": "VpcName",
5
5
  "ParameterValue": "sample"
6
- }
6
+ },
7
+ {
8
+ "ParameterKey": "Environment",
9
+ "ParameterValue": "Prod"
10
+ }
7
11
  ]
8
12
  }
data/sample/sg/sg.yaml CHANGED
@@ -4,7 +4,31 @@ Parameters:
4
4
  VpcName:
5
5
  Description: Name for this VPC
6
6
  Type: String
7
+ Environment:
8
+ Description: Name for this Environment
9
+ Type: String
7
10
  Resources:
11
+ WebElbSg:
12
+ Type: AWS::EC2::SecurityGroup
13
+ Properties:
14
+ GroupName: !Sub ${VpcName}-Web-Elb-Sg
15
+ GroupDescription: Web ELB Acccess Security Group
16
+ VpcId:
17
+ Fn::ImportValue: !Sub ${VpcName}-VpcId
18
+ SecurityGroupIngress:
19
+ - IpProtocol: tcp
20
+ FromPort: 80
21
+ ToPort: 80
22
+ CidrIp: 0.0.0.0/0
23
+ Description: Allow HTTP Access From Internet
24
+ - IpProtocol: tcp
25
+ FromPort: 443
26
+ ToPort: 443
27
+ CidrIp: 0.0.0.0/0
28
+ Description: Allow HTTPS Access From Internet
29
+ Tags:
30
+ - Key: Name
31
+ Value: !Sub ${VpcName}-Web-Elb-Sg
8
32
  WebInstanceSg:
9
33
  Type: AWS::EC2::SecurityGroup
10
34
  Properties:
@@ -13,16 +37,11 @@ Resources:
13
37
  VpcId:
14
38
  Fn::ImportValue: !Sub ${VpcName}-VpcId
15
39
  SecurityGroupIngress:
16
- - IpProtocol: tcp
17
- FromPort: 22
18
- ToPort: 22
19
- CidrIp: 0.0.0.0/0
20
- Description: Allow SSH Access From Internet
21
40
  - IpProtocol: tcp
22
41
  FromPort: 80
23
42
  ToPort: 80
24
- CidrIp: 0.0.0.0/0
25
- Description: Allow HTTP Access From Internet
43
+ SourceSecurityGroupId: !Ref WebElbSg
44
+ Description: Allow HTTP Access From ELB
26
45
  Tags:
27
46
  - Key: Name
28
47
  Value: !Sub ${VpcName}-Web-Instance-Sg
@@ -39,6 +58,11 @@ Resources:
39
58
  ToPort: 3306
40
59
  SourceSecurityGroupId: !Ref WebInstanceSg
41
60
  Outputs:
61
+ WebElbSg:
62
+ Description: ELB Security Group ID
63
+ Value: !Ref WebElbSg
64
+ Export:
65
+ Name: !Sub ${VpcName}-${Environment}-Web-ElbSg
42
66
  WebInstanceSg:
43
67
  Description: WebInstance Security Group ID
44
68
  Value: !Ref WebInstanceSg
@@ -48,4 +72,4 @@ Outputs:
48
72
  Description: Db Security Group ID
49
73
  Value: !Ref DbSg
50
74
  Export:
51
- Name: !Sub ${VpcName}-DbSg
75
+ Name: !Sub ${VpcName}-DbSg
data/sample/web/web.yaml CHANGED
@@ -129,4 +129,15 @@ Resources:
129
129
  Dimensions:
130
130
  - Name: InstanceId
131
131
  Value: !Ref Web2Instance
132
- DependsOn: Web2Instance
132
+ DependsOn: Web2Instance
133
+ Outputs:
134
+ Web1Instance:
135
+ Description: EC2 ID
136
+ Value: !Ref Web1Instance
137
+ Export:
138
+ Name: !Sub ${VpcName}-${Environment}-Web1
139
+ Web2Instance:
140
+ Description: EC2 ID
141
+ Value: !Ref Web2Instance
142
+ Export:
143
+ Name: !Sub ${VpcName}-${Environment}-Web2
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfndk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshihisa AMAKATA