-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathgreen.json
More file actions
147 lines (146 loc) · 4.92 KB
/
Copy pathgreen.json
File metadata and controls
147 lines (146 loc) · 4.92 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters" : {
"VpcId" : {
"Type" : "String"
},
"SubnetId" : {
"Type" : "String"
},
"KeyName" : {
"Description" : "Amazon EC2 Key Pair",
"Type" : "AWS::EC2::KeyPair::KeyName"
},
"ImageId" : {
"Description" : "Instance Image ID",
"Default" : "ami-eec1c380",
"Type" : "String"
},
"InstanceType" : {
"Type" : "String",
"Default" : "t2.micro",
"AllowedValues" : ["t2.nano", "t2.micro", "m2.small"],
"Description" : "Enter t2.nano, t2.micro or m2.small. Default is t2.micro."
},
"LbSecurityGroupId" : {
"Type" : "String",
"Description" : "Enter ID of LBSecurityGroup attached ELB."
},
"SshSecurityGroupId" : {
"Type" : "String",
"Description" : "Enter ID of SSHSecurityGroup attached CI server."
}
},
"Resources": {
"WebSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "Enable internal Web access",
"VpcId" : { "Ref" : "VpcId" },
"SecurityGroupIngress": [{
"IpProtocol" : "tcp",
"FromPort" : "8080",
"ToPort" : "8080",
"SourceSecurityGroupId" : { "Ref" : "LbSecurityGroupId" }
}]
}
},
"SshInnerSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "Enable SSH access via CI server",
"VpcId" : { "Ref" : "VpcId" },
"SecurityGroupIngress": [{
"IpProtocol" : "tcp",
"FromPort" : "22",
"ToPort" : "22",
"SourceSecurityGroupId" : { "Ref" : "SshSecurityGroupId" }
}]
}
},
"Web1Ec2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"ImageId" : { "Ref": "ImageId" },
"InstanceType" : { "Ref": "InstanceType" },
"KeyName" : { "Ref": "KeyName" },
"NetworkInterfaces": [{
"AssociatePublicIpAddress" : "true",
"DeleteOnTermination": "true",
"GroupSet":[
{ "Ref" : "WebSecurityGroup" },
{ "Ref" : "SshInnerSecurityGroup" }
],
"SubnetId": { "Ref": "SubnetId" },
"DeviceIndex": "0"
}],
"Tags" : [
{"Key" : "Name", "Value" : "green-web1"},
{"Key" : "Side", "Value" : "green"},
{"Key" : "ServerType", "Value" : "web"}
],
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"#! /bin/bash -v\n",
"getenforce\n",
"setenforce 0\n",
"sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config\n",
"echo '\n' >> /etc/ssh/sshd_config\n",
"echo 'Port 22' >> /etc/ssh/sshd_config\n",
"mkdir /home/centos/.ssh\n",
"curl -s https://raw.githubusercontent.com/devops-book/cloudformation/master/authorized_keys >> /home/centos/.ssh/authorized_keys\n",
"chmod 600 /home/centos/.ssh/authorized_keys\n",
"chmod 700 /home/centos/.ssh\n",
"chown centos:centos -R /home/centos/.ssh\n",
"shutdown -r now\n"
]]}}
}
},
"Web2Ec2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"ImageId" : { "Ref": "ImageId" },
"InstanceType" : { "Ref": "InstanceType" },
"KeyName" : { "Ref": "KeyName" },
"NetworkInterfaces": [{
"AssociatePublicIpAddress" : "true",
"DeleteOnTermination": "true",
"GroupSet":[
{ "Ref" : "WebSecurityGroup" },
{ "Ref" : "SshInnerSecurityGroup" }
],
"SubnetId": { "Ref": "SubnetId" },
"DeviceIndex": "0"
}],
"Tags" : [
{"Key" : "Name", "Value" : "green-web2"},
{"Key" : "Side", "Value" : "green"},
{"Key" : "ServerType", "Value" : "web"}
],
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"#! /bin/bash -v\n",
"getenforce\n",
"setenforce 0\n",
"sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config\n",
"echo '\n' >> /etc/ssh/sshd_config\n",
"echo 'Port 22' >> /etc/ssh/sshd_config\n",
"mkdir /home/centos/.ssh\n",
"curl -s https://raw.githubusercontent.com/devops-book/cloudformation/master/authorized_keys >> /home/centos/.ssh/authorized_keys\n",
"chmod 600 /home/centos/.ssh/authorized_keys\n",
"chmod 700 /home/centos/.ssh\n",
"chown centos:centos -R /home/centos/.ssh\n",
"shutdown -r now\n"
]]}}
}
}
},
"Outputs" : {
"GreenWeb1Ec2Instance" : {
"Description" : "Green Web1 Instance ID",
"Value" : { "Ref" : "Web1Ec2Instance" }
},
"GreenWeb2Ec2Instance" : {
"Description" : "Green Web2 Instance ID",
"Value" : { "Ref" : "Web2Ec2Instance" }
}
}
}