cfndk 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/sample/sg/sg.yaml ADDED
@@ -0,0 +1,51 @@
1
+ AWSTemplateFormatVersion: '2010-09-09'
2
+ Description: Security Groups Stack
3
+ Parameters:
4
+ VpcName:
5
+ Description: Name for this VPC
6
+ Type: String
7
+ Resources:
8
+ WebInstanceSg:
9
+ Type: AWS::EC2::SecurityGroup
10
+ Properties:
11
+ GroupName: !Sub ${VpcName}-Web-Instance-Sg
12
+ GroupDescription: EC2 Web Instance Acccess Security Group
13
+ VpcId:
14
+ Fn::ImportValue: !Sub ${VpcName}-VpcId
15
+ 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
+ - IpProtocol: tcp
22
+ FromPort: 80
23
+ ToPort: 80
24
+ CidrIp: 0.0.0.0/0
25
+ Description: Allow HTTP Access From Internet
26
+ Tags:
27
+ - Key: Name
28
+ Value: !Sub ${VpcName}-Web-Instance-Sg
29
+ DbSg:
30
+ Type: AWS::EC2::SecurityGroup
31
+ Properties:
32
+ GroupName: !Sub ${VpcName}-Db-Sg
33
+ GroupDescription: RDS Db Acccess Security Group
34
+ VpcId:
35
+ Fn::ImportValue: !Sub ${VpcName}-VpcId
36
+ SecurityGroupIngress:
37
+ - IpProtocol: tcp
38
+ FromPort: 3306
39
+ ToPort: 3306
40
+ SourceSecurityGroupId: !Ref WebInstanceSg
41
+ Outputs:
42
+ WebInstanceSg:
43
+ Description: WebInstance Security Group ID
44
+ Value: !Ref WebInstanceSg
45
+ Export:
46
+ Name: !Sub ${VpcName}-WebInstanceSg
47
+ DbSg:
48
+ Description: Db Security Group ID
49
+ Value: !Ref DbSg
50
+ Export:
51
+ Name: !Sub ${VpcName}-DbSg
@@ -0,0 +1,48 @@
1
+ {
2
+ "Parameters": [
3
+ {
4
+ "ParameterKey": "VpcName",
5
+ "ParameterValue": "sample"
6
+ },
7
+ {
8
+ "ParameterKey": "InternalDnsName",
9
+ "ParameterValue": "sample.local"
10
+ },
11
+ {
12
+ "ParameterKey": "AutoRecoveryMinutes",
13
+ "ParameterValue": "60"
14
+ },
15
+ {
16
+ "ParameterKey": "WebInstanceProfileName",
17
+ "ParameterValue": "WebInstanceProfile"
18
+ },
19
+ {
20
+ "ParameterKey": "AmiId1",
21
+ "ParameterValue": "ami-0a2de1c3b415889d2"
22
+ },
23
+ {
24
+ "ParameterKey": "AmiId2",
25
+ "ParameterValue": "ami-0a2de1c3b415889d2"
26
+ },
27
+ {
28
+ "ParameterKey": "HostName1",
29
+ "ParameterValue": "web1"
30
+ },
31
+ {
32
+ "ParameterKey": "HostName2",
33
+ "ParameterValue": "web2"
34
+ },
35
+ {
36
+ "ParameterKey": "KeyPair",
37
+ "ParameterValue": "CFnDKSampleKey"
38
+ },
39
+ {
40
+ "ParameterKey": "InstanceType",
41
+ "ParameterValue": "t3.nano"
42
+ },
43
+ {
44
+ "ParameterKey": "Environment",
45
+ "ParameterValue": "Prod"
46
+ }
47
+ ]
48
+ }
@@ -0,0 +1,132 @@
1
+ AWSTemplateFormatVersion: '2010-09-09'
2
+ Description: Bastion Stack
3
+ Parameters:
4
+ VpcName:
5
+ Type: String
6
+ AutoRecoveryMinutes:
7
+ Type: Number
8
+ InternalDnsName:
9
+ Type: String
10
+ WebInstanceProfileName:
11
+ Type: String
12
+ Environment:
13
+ Type: String
14
+ AmiId1:
15
+ Type: AWS::EC2::Image::Id
16
+ AmiId2:
17
+ Type: AWS::EC2::Image::Id
18
+ HostName1:
19
+ Type: String
20
+ HostName2:
21
+ Type: String
22
+ KeyPair:
23
+ Type: AWS::EC2::KeyPair::KeyName
24
+ InstanceType:
25
+ Type: String
26
+ Resources:
27
+ Web1Instance:
28
+ Type: AWS::EC2::Instance
29
+ Properties:
30
+ ImageId: !Ref AmiId1
31
+ InstanceType: !Ref InstanceType
32
+ KeyName: !Ref KeyPair
33
+ SourceDestCheck: false
34
+ BlockDeviceMappings:
35
+ - DeviceName: /dev/sda1
36
+ Ebs:
37
+ DeleteOnTermination: true
38
+ VolumeSize: 20
39
+ VolumeType: gp2
40
+ SubnetId:
41
+ Fn::ImportValue: !Sub ${VpcName}-${Environment}-Web-Subnet1
42
+ SecurityGroupIds:
43
+ - Fn::ImportValue: !Sub ${VpcName}-WebInstanceSg
44
+ IamInstanceProfile: !Ref WebInstanceProfileName
45
+ Tags:
46
+ - Key: Name
47
+ Value: !Sub ${VpcName}-${Environment}-Web1
48
+ Web2Instance:
49
+ Type: AWS::EC2::Instance
50
+ Properties:
51
+ ImageId: !Ref AmiId2
52
+ InstanceType: !Ref InstanceType
53
+ KeyName: !Ref KeyPair
54
+ SourceDestCheck: false
55
+ BlockDeviceMappings:
56
+ - DeviceName: /dev/sda1
57
+ Ebs:
58
+ DeleteOnTermination: true
59
+ VolumeSize: 20
60
+ VolumeType: gp2
61
+ SubnetId:
62
+ Fn::ImportValue: !Sub ${VpcName}-${Environment}-Web-Subnet2
63
+ SecurityGroupIds:
64
+ - Fn::ImportValue: !Sub ${VpcName}-WebInstanceSg
65
+ IamInstanceProfile: !Ref WebInstanceProfileName
66
+ Tags:
67
+ - Key: Name
68
+ Value: !Sub ${VpcName}-${Environment}-Web2
69
+ Web1RecordSet:
70
+ Type: AWS::Route53::RecordSet
71
+ Properties:
72
+ HostedZoneId:
73
+ Fn::ImportValue: !Sub ${VpcName}-InternalDns
74
+ Comment: DNS name for Web1
75
+ Name:
76
+ !Join
77
+ - '.'
78
+ - - !Ref HostName1
79
+ - Fn::ImportValue: !Sub ${VpcName}-InternalDnsName
80
+ Type: A
81
+ TTL: 60
82
+ ResourceRecords:
83
+ - !GetAtt Web1Instance.PrivateIp
84
+ Web2RecordSet:
85
+ Type: AWS::Route53::RecordSet
86
+ Properties:
87
+ HostedZoneId:
88
+ Fn::ImportValue: !Sub ${VpcName}-InternalDns
89
+ Comment: DNS name for Web2
90
+ Name:
91
+ !Join
92
+ - '.'
93
+ - - !Ref HostName2
94
+ - Fn::ImportValue: !Sub ${VpcName}-InternalDnsName
95
+ Type: A
96
+ TTL: 60
97
+ ResourceRecords:
98
+ - !GetAtt Web2Instance.PrivateIp
99
+ Web1RecoveryAlarm:
100
+ Type: AWS::CloudWatch::Alarm
101
+ Properties:
102
+ AlarmDescription: Trigger a Auto recovery when instance status check fails for 5 consecutive minutes.
103
+ Namespace: AWS/EC2
104
+ MetricName: StatusCheckFailed_System
105
+ Statistic: Minimum
106
+ Period: '60'
107
+ EvaluationPeriods: !Ref AutoRecoveryMinutes
108
+ ComparisonOperator: GreaterThanThreshold
109
+ Threshold: '0'
110
+ AlarmActions:
111
+ - !Sub "arn:aws:automate:${AWS::Region}:ec2:recover"
112
+ Dimensions:
113
+ - Name: InstanceId
114
+ Value: !Ref Web1Instance
115
+ DependsOn: Web1Instance
116
+ Web2RecoveryAlarm:
117
+ Type: AWS::CloudWatch::Alarm
118
+ Properties:
119
+ AlarmDescription: Trigger a Auto recovery when instance status check fails for 5 consecutive minutes.
120
+ Namespace: AWS/EC2
121
+ MetricName: StatusCheckFailed_System
122
+ Statistic: Minimum
123
+ Period: '60'
124
+ EvaluationPeriods: !Ref AutoRecoveryMinutes
125
+ ComparisonOperator: GreaterThanThreshold
126
+ Threshold: '0'
127
+ AlarmActions:
128
+ - !Sub "arn:aws:automate:${AWS::Region}:ec2:recover"
129
+ Dimensions:
130
+ - Name: InstanceId
131
+ Value: !Ref Web2Instance
132
+ DependsOn: Web2Instance
data/skel/cfndk.yml CHANGED
@@ -1,3 +1,7 @@
1
+
2
+ keypairs:
3
+ Key1:
4
+ key_file: key/key1<%= append_uuid %>.pem
1
5
  stacks:
2
6
  Stack1:
3
7
  template_file: stack1/stack1.yaml
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfndk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshihisa AMAKATA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-13 00:00:00.000000000 Z
11
+ date: 2019-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -106,18 +106,32 @@ files:
106
106
  - ".rubocop.yml"
107
107
  - Gemfile
108
108
  - LICENSE.txt
109
- - README-ja.md
110
109
  - README.md
111
110
  - Rakefile
112
111
  - bin/cfndk
113
112
  - cfndk.gemspec
114
113
  - lib/cfndk.rb
115
114
  - lib/cfndk/credential_provider_chain.rb
116
- - lib/cfndk/parameter_string.rb
115
+ - lib/cfndk/erb_string.rb
116
+ - lib/cfndk/key_pair.rb
117
+ - lib/cfndk/key_pairs.rb
117
118
  - lib/cfndk/stack.rb
118
119
  - lib/cfndk/stacks.rb
119
120
  - lib/cfndk/version.rb
120
121
  - sample/cfndk.yml
122
+ - sample/db/db.yaml
123
+ - sample/db/prod.json
124
+ - sample/elb/elb.yaml
125
+ - sample/elb/prod.json
126
+ - sample/iam/iam.yaml
127
+ - sample/iam/prod.json
128
+ - sample/key/.gitkeep
129
+ - sample/network/network.yaml
130
+ - sample/network/prod.json
131
+ - sample/sg/prod.json
132
+ - sample/sg/sg.yaml
133
+ - sample/web/prod.json
134
+ - sample/web/web.yaml
121
135
  - skel/cfndk.yml
122
136
  homepage: https://github.com/Amakata/cfndk
123
137
  licenses:
data/README-ja.md DELETED
@@ -1,282 +0,0 @@
1
- # AWS CloudFormation Development Kit
2
-
3
- このツールは、AWS CloudFromationのための簡単な運用/構築サポートツールです。
4
-
5
- ## インストール
6
-
7
- ```
8
- $ gem install cfndk
9
- ```
10
-
11
- ## Credentials設定
12
-
13
- 次の順番でCredentialsを評価して最初に有効なCredentialsを使用します。
14
-
15
- 1. access key、secret access key、session token環境変数よるCredentials
16
- * ACCESS_KEYで利用される環境変数名: AWS_ACCESS_KEY_ID AMAZON_ACCESS_KEY_ID AWS_ACCESS_KEY
17
- * SECRET_ACCESS_KEYで利用される環境変数名: AWS_SECRET_ACCESS_KEY AMAZON_SECRET_ACCESS_KEY AWS_SECRET_KEY
18
- * SESSION_TOKEで利用される環境変数名: AWS_SESSION_TOKEN AMAZON_SESSION_TOKEN
19
- 2. AWS_PROFILE環境変数によるProfileのaccess key、secret access key、session tokenによるCredentials
20
- * 環境変数が指定されない場合は、defaultが利用されます。
21
- 3. AWS_PROFILE環境変数によるProfileのcredential_processによるCredentials
22
- * 環境変数が指定されない場合は、defaultが利用されます。
23
- 4. EC2/ECS Instance ProfileによるCredentials
24
- * AWS_CONTAINER_CREDENTIALS_RELATIVE_URI環境変数が設定された場合のみECSが使われます。
25
-
26
- ## コマンド
27
-
28
- ```
29
- cfndk [cmd] [options]
30
- ```
31
-
32
- ### [cmd]
33
-
34
- #### 初期化
35
-
36
- カレントディレクトリにcfndk.yamlのひな形を作成します。
37
-
38
- ```
39
- cfndk init [option]
40
- ```
41
-
42
- #### スタックの作成
43
-
44
- cfndk.yamlで定義されているスタックを作成します。
45
-
46
- ```
47
- cfndk create [option]
48
- ```
49
-
50
- #### スタック更新
51
-
52
- cfndk.yamlで定義されているスタックを更新します。
53
-
54
- ```
55
- cfndk update [option]
56
- ```
57
-
58
- #### スタックの作成、changeset作成
59
-
60
- cfndk.yamlで定義されているスタックが存在しない場合は作成を、存在する場合はチェンジセットを作成します。
61
- チェンジセットの実行は行いません。
62
- コマンドを実行後に手動で実行する必要があります。
63
-
64
- ```
65
- cfndk create-or-changeset [option]
66
- ```
67
-
68
- #### スタックの破壊
69
-
70
- cfndk.yamlで定義されているスタックを削除します。
71
-
72
- ```
73
- cfndk destroy [option]
74
- ```
75
-
76
- #### UUIDの生成
77
-
78
- UUIDを生成して標準出力に出力します。
79
-
80
- ```
81
- cfndk generate-uuid
82
- ```
83
-
84
- 例えば次のような使い方をします。
85
-
86
- ```
87
- export CFNDK_UUID=`cfndk generate-uuid`
88
- cfndk create
89
- cfndk destroy
90
- ```
91
-
92
- #### スタックのイベントのレポート
93
-
94
- cfndk.yamlで定義されているスタックのイベント情報をレポートします。
95
-
96
- ```
97
- cfndk report-event [option]
98
- ```
99
-
100
- #### スタックのスタックのレポート
101
-
102
- cfndk.yamlで定義されているスタックの情報をレポートします。
103
-
104
- ```
105
- cfndk report-stack [option]
106
- ```
107
-
108
- #### スタックのスタックリソースのレポート
109
-
110
- cfndk.yamlで定義されているスタックのリソース情報をレポートします。
111
-
112
- ```
113
- cfndk report-stack-resource [option]
114
- ```
115
-
116
- ### [option]
117
-
118
- #### -v --verbose
119
-
120
- 実行時に詳細な情報を表示します。
121
-
122
- #### -c, --config_path <cfndi.yml>
123
-
124
- カレントディレクトリのcfndi.ymlの代わりに、ファイルを指定します。
125
-
126
- #### -p, --properties <name>=<value>
127
-
128
- プロパティを追加します。
129
- cfndi.ymlのparametersの値で参照することができます。
130
-
131
- #### -a, --auto-uuid
132
-
133
- UUIDを自動生成し使用します。
134
- UUIDが指定されるとスタック名に付加されます。
135
- またcfndi.ymlのparametersの値で参照することができます。
136
- ```-a```と```-u```は最後に指定されたものが有効になります。
137
-
138
- #### -u, --uuid <uuid>
139
-
140
- 指定されたUUIDを使用します。
141
- UUIDが指定されるとスタック名に付加されます。
142
- またcfndi.ymlのparametersの値で参照することができます。
143
- ```-a```と```-u```は最後に指定されたものが有効になります。
144
-
145
-
146
- ## 環境変数
147
-
148
- ### CFNDK_UUID
149
-
150
- この環境変数が指定されている場合、```--uuid $CFNDK_UUID```が指定されたものとして動作します。
151
- ```-a```や```-u```のほうが優先されます。
152
-
153
-
154
- ## cfndk.yaml
155
-
156
- * example
157
-
158
- ```
159
- stacks:
160
- Stack2:
161
- template_file: stack2/stack2.yaml
162
- parameter_input: stacn2/env.json
163
- parameters:
164
- VpcName: Prod<%= append_uuid %>
165
- capabilities:
166
- - CAPABILITY_IAM
167
- - CAPABILITY_NAMED_IAM
168
- depends:
169
- - Stack1
170
- timeout_in_minutes: 10
171
- ```
172
-
173
- ```
174
- stacks:
175
- [String]:
176
- template_file: [String]
177
- parameter_input: [String]
178
- parameters:
179
- [String]: [String]
180
- [String]: [String]
181
- capabilities:
182
- - [String]
183
- - [String]
184
- timeout_in_minutes: [Integer]
185
- depends:
186
- - [String]
187
- - [String]
188
- ```
189
-
190
- ### ```stacks:```
191
-
192
- ```
193
- stacks:
194
- [Stack Original Name]:
195
- ```
196
-
197
- cfndkで管理するスタックを定義します。
198
- stacksの配下には、管理するスタックのオリジナル名を定義します。
199
- 通常は、stackを作成するとこの名称が利用されます。
200
- UUIDを利用すると、```[Stack Original Name]-[UUID]```のような形式のスタック名が利用されます。
201
-
202
- #### template_file
203
-
204
- 必須。CloudFormationテンプレートファイルのパスをcfndk.yamlからの相対パスで指定します。
205
-
206
- #### parameter_input
207
-
208
- 必須。CloudFormationのパラメータJSONをcfndk.yamlからの相対パスで指定します。
209
-
210
- #### parameters
211
-
212
- parameter_inputのJSONの値を上書きした場合に指定します。
213
- 複数指定することができます。
214
-
215
- ```
216
- parameters:
217
- [Parameter Key1]: [Parameter Value1]
218
- [Parameter Key2]: [Parameter Value2]
219
- ```
220
-
221
- Parameter Valueではerbの記法が利用できます。
222
-
223
- ```
224
- parameters:
225
- VpcName: Prod<%= append_uuid %>
226
- ```
227
-
228
- ##### parametrsのerbで使用できるメソッド
229
-
230
- * ```append_uuid(glue='-')```
231
-
232
- UUIDガ指定されている場合、```[glueの文字列] + [UUID]```を返します。
233
- UUIDが指定されてい無い場合は空文字が返ります。
234
- glueで接続文字を置き換えることができます。
235
-
236
- * ```uuid```
237
-
238
- UUIDを返します。
239
- UUIDが指定されてい無い場合は空文字が返ります。
240
-
241
- * ```properties(key)```
242
-
243
- オプション```--properties```で指定したキーに対応する値を参照することができます。
244
-
245
- #### capabilities
246
-
247
- スタックを操作するcapabilitiesを指定します。
248
- 複数指定することができます。
249
-
250
- ```
251
- capabilities:
252
- - CAPABILITY_IAM
253
- - CAPABILITY_NAMED_IAM
254
- ```
255
-
256
- 以下の値を指定することができます。
257
-
258
- * CAPABILITY_IAM
259
- * CAPABILITY_NAMED_IAM
260
- * CAPABILITY_AUTO_EXPAND
261
-
262
-
263
- #### depends
264
-
265
- スタックに依存している別のスタックを指定します。
266
- 複数指定することができます。
267
- dependsを指定すると、create,update,create-or-changeset,destoryのコマンドを実行する際に、依存関係に従ってスタックを処理します。
268
- dependsが循環するような指定をすることはできません。
269
-
270
- ```
271
- depends:
272
- - Stack1
273
- - Stack2
274
- ```
275
-
276
- #### timeout_in_minutes (デフォルト: 1)
277
-
278
- スタックを作成する際などのタイムアウト時間を分で指定します。
279
-
280
- ```
281
- timeout_in_minutes: 5
282
- ```