forked from nilan3/cloudformation-ec2-cluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
master-stack.yml
95 lines (92 loc) · 3 KB
/
master-stack.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
AWSTemplateFormatVersion: 2010-09-09
Description: >-
Cluster Master Stack
Parameters:
Version:
Type: String
Default: "0.0.1"
Description: Version of the application
Environment:
Type: String
Default: dev
Description: Select the appropriate environment
AllowedValues:
- dev
- staging
- prod
S3CfnBucketName:
Type: String
Description: S3Bucket Path where the templates are stored
Default: aws-cloudformation-templates
Ec2KeyName:
Type: String
Description: EC2 Key Name
Ec2AmiId:
Type: String
Description: EC2 AMI ID
Resources:
VPCStack:
Type: "AWS::CloudFormation::Stack"
Properties:
TemplateURL: !Sub "https://s3.amazonaws.com/${S3CfnBucketName}-${Environment}-${AWS::Region}/templates/vpc-stack.yml"
Parameters:
Version: !Ref Version
Environment: !Ref Environment
AvZone1: !Sub "${AWS::Region}a"
AvZone2: !Sub "${AWS::Region}b"
NetworkAclStackTemplateURL: !Sub "https://s3.amazonaws.com/${S3CfnBucketName}-${Environment}-${AWS::Region}/templates/network-acl-stack.yml"
Tags:
- Key: Name
Value: VPCStack
- Key: Version
Value: !Ref Version
- Key: Environment
Value: !Ref Environment
InstanceSecurityGroupStack:
DependsOn:
- VPCStack
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: !Sub "https://s3.amazonaws.com/${S3CfnBucketName}-${Environment}-${AWS::Region}/templates/instance-security-group-stack.yml"
Parameters:
Environment:
Ref: Environment
VpcCIDR: !GetAtt VPCStack.Outputs.VpcCIDR
VPC: !GetAtt VPCStack.Outputs.VPC
TimeoutInMinutes: '15'
Tags:
- Key: Name
Value: InstanceSecurityGroupStack
- Key: Version
Value: !Ref Version
- Key: Environment
Value: !Ref Environment
Ec2InstancesStack:
DependsOn:
- VPCStack
- InstanceSecurityGroupStack
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: !Sub "https://s3.amazonaws.com/${S3CfnBucketName}-${Environment}-${AWS::Region}/templates/ec2-instances-stack.yml"
Parameters:
Environment:
Ref: Environment
KeyName:
Ref: Ec2KeyName
BaseImage:
Ref: Ec2AmiId
PrivateSubnet1Id: !GetAtt VPCStack.Outputs.PrivateSubnetAZ1
PrivateSubnet2Id: !GetAtt VPCStack.Outputs.PrivateSubnetAZ2
PublicSubnetId: !GetAtt VPCStack.Outputs.PublicSubnetAZ1
PrivateInstanceSG: !GetAtt InstanceSecurityGroupStack.Outputs.PrivInstSecurityGroup
PublicInstanceSG: !GetAtt InstanceSecurityGroupStack.Outputs.PubInstSecurityGroup
ClusterInstanceType: t3.medium
S3CfnBucketName: !Sub "${S3CfnBucketName}-${Environment}-${AWS::Region}"
TimeoutInMinutes: '15'
Tags:
- Key: Name
Value: Ec2InstancesStack
- Key: Version
Value: !Ref Version
- Key: Environment
Value: !Ref Environment