vpc+role.yaml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. AWSTemplateFormatVersion: 2010-09-09
  2. Resources:
  3. RootRole:
  4. Type: 'AWS::IAM::Role'
  5. Properties:
  6. AssumeRolePolicyDocument:
  7. Version: 2012-10-17
  8. Statement:
  9. - Effect: Allow
  10. Principal:
  11. Service:
  12. - lambda.amazonaws.com
  13. - ec2.amazonaws.com.cn
  14. - ecs-tasks.amazonaws.com
  15. - vpc-flow-logs.amazonaws.com
  16. Action:
  17. - 'sts:AssumeRole'
  18. Path: /
  19. RoleName: !Ref roleName
  20. Metadata:
  21. 'AWS::CloudFormation::Designer':
  22. id: 5a809822-8fad-40ca-bd0f-7aae64ae7b4a
  23. RolePolicies:
  24. Type: 'AWS::IAM::Policy'
  25. Properties:
  26. PolicyName: root
  27. PolicyDocument:
  28. Version: 2012-10-17
  29. Statement:
  30. - Effect: Allow
  31. Action: '*'
  32. Resource: '*'
  33. Roles:
  34. - Ref: RootRole
  35. Metadata:
  36. 'AWS::CloudFormation::Designer':
  37. id: 41ab1589-d187-45a1-99aa-379280c9f643
  38. vpc1:
  39. Type: 'AWS::EC2::VPC'
  40. Properties:
  41. CidrBlock: !Ref vpccidr
  42. EnableDnsHostnames: 'true'
  43. EnableDnsSupport: 'true'
  44. Tags:
  45. - Key: Name
  46. Value: vpc1
  47. Metadata:
  48. 'AWS::CloudFormation::Designer':
  49. id: 36050a81-2f2b-4482-9d6a-763dbad1b527
  50. pubnet1:
  51. Type: 'AWS::EC2::Subnet'
  52. Properties:
  53. AvailabilityZone: !Select
  54. - '0'
  55. - !GetAZs ''
  56. CidrBlock: !Ref pubnet1cidr
  57. Tags:
  58. - Key: Name
  59. Value: pubnet1
  60. VpcId: !Ref vpc1
  61. Metadata:
  62. 'AWS::CloudFormation::Designer':
  63. id: d00fad60-d71a-4bfc-988a-65236dea5a6f
  64. pubnet2:
  65. Type: 'AWS::EC2::Subnet'
  66. Properties:
  67. AvailabilityZone: !Select
  68. - '1'
  69. - !GetAZs ''
  70. CidrBlock: !Ref pubnet2cidr
  71. Tags:
  72. - Key: Name
  73. Value: pubnet2
  74. VpcId: !Ref vpc1
  75. Metadata:
  76. 'AWS::CloudFormation::Designer':
  77. id: dbc87cce-6f33-46fb-8684-24fc5008ad91
  78. webnet1:
  79. Type: 'AWS::EC2::Subnet'
  80. Properties:
  81. AvailabilityZone: !Select
  82. - '0'
  83. - !GetAZs ''
  84. CidrBlock: !Ref webnet1cidr
  85. Tags:
  86. - Key: Name
  87. Value: webnet1
  88. VpcId: !Ref vpc1
  89. Metadata:
  90. 'AWS::CloudFormation::Designer':
  91. id: 30f1713d-c319-4dcb-8730-c4baf0cb207a
  92. webnet2:
  93. Type: 'AWS::EC2::Subnet'
  94. Properties:
  95. AvailabilityZone: !Select
  96. - '1'
  97. - !GetAZs ''
  98. CidrBlock: !Ref webnet2cidr
  99. Tags:
  100. - Key: Name
  101. Value: webnet2
  102. VpcId: !Ref vpc1
  103. Metadata:
  104. 'AWS::CloudFormation::Designer':
  105. id: bd5423c4-721b-4194-a7ba-b8d4b437683a
  106. dbnet1:
  107. Type: 'AWS::EC2::Subnet'
  108. Properties:
  109. AvailabilityZone: !Select
  110. - '0'
  111. - !GetAZs ''
  112. CidrBlock: !Ref dbnet1cidr
  113. Tags:
  114. - Key: Name
  115. Value: dbnet1
  116. VpcId: !Ref vpc1
  117. Metadata:
  118. 'AWS::CloudFormation::Designer':
  119. id: d721de76-5cf2-416c-985d-2bd9d10d4c3c
  120. dbnet2:
  121. Type: 'AWS::EC2::Subnet'
  122. Properties:
  123. AvailabilityZone: !Select
  124. - '1'
  125. - !GetAZs ''
  126. CidrBlock: !Ref dbnet2cidr
  127. Tags:
  128. - Key: Name
  129. Value: dbnet2
  130. VpcId: !Ref vpc1
  131. Metadata:
  132. 'AWS::CloudFormation::Designer':
  133. id: d3655dff-3e6c-4e71-b429-782c249ead24
  134. table1:
  135. Type: 'AWS::EC2::RouteTable'
  136. Properties:
  137. Tags:
  138. - Key: Name
  139. Value: table1
  140. VpcId: !Ref vpc1
  141. Metadata:
  142. 'AWS::CloudFormation::Designer':
  143. id: 5a28c477-28f7-4f63-96e4-eba4f2af91c8
  144. table2:
  145. Type: 'AWS::EC2::RouteTable'
  146. Properties:
  147. Tags:
  148. - Key: Name
  149. Value: table2
  150. VpcId: !Ref vpc1
  151. Metadata:
  152. 'AWS::CloudFormation::Designer':
  153. id: e7cb3a54-60cc-4806-b6c5-51dd541555b2
  154. table3:
  155. Type: 'AWS::EC2::RouteTable'
  156. Properties:
  157. Tags:
  158. - Key: Name
  159. Value: table3
  160. VpcId: !Ref vpc1
  161. Metadata:
  162. 'AWS::CloudFormation::Designer':
  163. id: b031b8a3-c571-4e9b-967f-e777ca927d08
  164. igw1:
  165. Type: 'AWS::EC2::InternetGateway'
  166. Properties: {}
  167. Metadata:
  168. 'AWS::CloudFormation::Designer':
  169. id: 4f2d896c-333a-4e40-acf1-a4d29c7f1e04
  170. EC2VPCG2BPGG:
  171. Type: 'AWS::EC2::VPCGatewayAttachment'
  172. Properties:
  173. InternetGatewayId: !Ref igw1
  174. VpcId: !Ref vpc1
  175. Metadata:
  176. 'AWS::CloudFormation::Designer':
  177. id: 544c5488-107f-4d4f-99d7-f22003afd889
  178. natgateway1:
  179. Type: 'AWS::EC2::NatGateway'
  180. Properties:
  181. AllocationId: !GetAtt
  182. - eip1
  183. - AllocationId
  184. SubnetId: !Ref pubnet1
  185. Metadata:
  186. 'AWS::CloudFormation::Designer':
  187. id: df5bea53-45ac-47d0-ae9e-32e7d54a37a5
  188. natgateway2:
  189. Type: 'AWS::EC2::NatGateway'
  190. Properties:
  191. AllocationId: !GetAtt
  192. - eip2
  193. - AllocationId
  194. SubnetId: !Ref pubnet2
  195. Metadata:
  196. 'AWS::CloudFormation::Designer':
  197. id: b8570bf1-7fe5-4d58-8fb9-83e3660f2170
  198. eip1:
  199. Type: 'AWS::EC2::EIP'
  200. Properties: {}
  201. Metadata:
  202. 'AWS::CloudFormation::Designer':
  203. id: d77dbe47-fc90-4338-8ff2-af4000405dde
  204. eip2:
  205. Type: 'AWS::EC2::EIP'
  206. Properties: {}
  207. Metadata:
  208. 'AWS::CloudFormation::Designer':
  209. id: e8777cd9-8375-401a-ad6f-52051c09dc89
  210. EC2SRTA51E2B:
  211. Type: 'AWS::EC2::SubnetRouteTableAssociation'
  212. Properties:
  213. SubnetId: !Ref pubnet1
  214. RouteTableId: !Ref table1
  215. Metadata:
  216. 'AWS::CloudFormation::Designer':
  217. id: 72574f43-a5f8-4c3b-bcf7-f8b199887e9c
  218. EC2SRTA2YHOD:
  219. Type: 'AWS::EC2::SubnetRouteTableAssociation'
  220. Properties:
  221. SubnetId: !Ref pubnet2
  222. RouteTableId: !Ref table1
  223. Metadata:
  224. 'AWS::CloudFormation::Designer':
  225. id: f7e5fe7c-a1c1-48e0-8743-daa1f0e3fb06
  226. EC2SRTA2VWB8:
  227. Type: 'AWS::EC2::SubnetRouteTableAssociation'
  228. Properties:
  229. RouteTableId: !Ref table2
  230. SubnetId: !Ref webnet1
  231. Metadata:
  232. 'AWS::CloudFormation::Designer':
  233. id: 5b9f52cd-7dd4-4a0e-88d2-ebd48368e2a4
  234. EC2SRTA26CTN:
  235. Type: 'AWS::EC2::SubnetRouteTableAssociation'
  236. Properties:
  237. SubnetId: !Ref dbnet1
  238. RouteTableId: !Ref table2
  239. Metadata:
  240. 'AWS::CloudFormation::Designer':
  241. id: 3cedd898-d918-44c1-938d-cfc6512301ea
  242. EC2SRTAH6LA:
  243. Type: 'AWS::EC2::SubnetRouteTableAssociation'
  244. Properties:
  245. SubnetId: !Ref webnet2
  246. RouteTableId: !Ref table3
  247. Metadata:
  248. 'AWS::CloudFormation::Designer':
  249. id: 91524a30-078a-41c2-a34e-0f16b37b3691
  250. EC2SRTA1VSM:
  251. Type: 'AWS::EC2::SubnetRouteTableAssociation'
  252. Properties:
  253. SubnetId: !Ref dbnet2
  254. RouteTableId: !Ref table3
  255. Metadata:
  256. 'AWS::CloudFormation::Designer':
  257. id: 1220e1c3-e8c3-4f7a-998d-e60203564b8d
  258. route1:
  259. Type: 'AWS::EC2::Route'
  260. Properties:
  261. DestinationCidrBlock: 0.0.0.0/0
  262. GatewayId: !Ref igw1
  263. RouteTableId: !Ref table1
  264. Metadata:
  265. 'AWS::CloudFormation::Designer':
  266. id: d037ea69-ec83-4c36-92f7-12c199349fd9
  267. route2:
  268. Type: 'AWS::EC2::Route'
  269. Properties:
  270. DestinationCidrBlock: 0.0.0.0/0
  271. NatGatewayId: !Ref natgateway1
  272. RouteTableId: !Ref table2
  273. Metadata:
  274. 'AWS::CloudFormation::Designer':
  275. id: 64d213ca-d8f7-45f3-a53b-6001ad55ba0a
  276. route3:
  277. Type: 'AWS::EC2::Route'
  278. Properties:
  279. DestinationCidrBlock: 0.0.0.0/0
  280. NatGatewayId: !Ref natgateway2
  281. RouteTableId: !Ref table3
  282. Metadata:
  283. 'AWS::CloudFormation::Designer':
  284. id: c5cec4ea-e367-424f-9e78-92220722b760
  285. elbgroup:
  286. Type: 'AWS::EC2::SecurityGroup'
  287. Properties:
  288. GroupDescription: sg_elb
  289. GroupName: sg_elb
  290. Tags:
  291. - Key: Name
  292. Value: sg_elb
  293. SecurityGroupIngress:
  294. - IpProtocol: tcp
  295. FromPort: 80
  296. ToPort: 80
  297. CidrIp: 0.0.0.0/0
  298. SecurityGroupEgress:
  299. - CidrIp: 0.0.0.0/0
  300. IpProtocol: '-1'
  301. VpcId: !Ref vpc1
  302. Metadata:
  303. 'AWS::CloudFormation::Designer':
  304. id: 41ff46eb-edb8-456f-9183-4d7eea31e49a
  305. webgroup:
  306. Type: 'AWS::EC2::SecurityGroup'
  307. Properties:
  308. GroupDescription: !Ref sgName
  309. GroupName: !Ref sgName
  310. Tags:
  311. - Key: Name
  312. Value: !Ref sgName
  313. SecurityGroupIngress:
  314. - IpProtocol: tcp
  315. FromPort: 7777
  316. ToPort: 7777
  317. CidrIp: 0.0.0.0/0
  318. - IpProtocol: tcp
  319. FromPort: 22
  320. ToPort: 22
  321. CidrIp: 0.0.0.0/0
  322. SecurityGroupEgress:
  323. - CidrIp: 0.0.0.0/0
  324. IpProtocol: '-1'
  325. VpcId: !Ref vpc1
  326. Metadata:
  327. 'AWS::CloudFormation::Designer':
  328. id: 3d3c83e4-c428-4628-a0e2-d4415ec6cfd6
  329. dbgroup:
  330. Type: 'AWS::EC2::SecurityGroup'
  331. Properties:
  332. GroupDescription: dbgroup
  333. GroupName: elasticache_memcache
  334. Tags:
  335. - Key: Name
  336. Value: elasticache_memcache
  337. SecurityGroupIngress:
  338. - SourceSecurityGroupId: !Ref webgroup
  339. FromPort: !Ref cacheport
  340. ToPort: !Ref cacheport
  341. IpProtocol: tcp
  342. - SourceSecurityGroupId: !Ref webgroup
  343. FromPort: '2049'
  344. ToPort: '2049'
  345. IpProtocol: tcp
  346. - SourceSecurityGroupId: !Ref webgroup
  347. FromPort: '5432'
  348. ToPort: '5432'
  349. IpProtocol: tcp
  350. SecurityGroupEgress:
  351. - CidrIp: 0.0.0.0/0
  352. IpProtocol: '-1'
  353. VpcId: !Ref vpc1
  354. Metadata:
  355. 'AWS::CloudFormation::Designer':
  356. id: 6efe5731-b5ea-4e23-9b48-1353eaea32a1
  357. redissg:
  358. Type: 'AWS::EC2::SecurityGroup'
  359. Properties:
  360. GroupDescription: redissg
  361. GroupName: elasticache_redis
  362. Tags:
  363. - Key: Name
  364. Value: elasticache_redis
  365. SecurityGroupIngress:
  366. - SourceSecurityGroupId: !Ref webgroup
  367. FromPort: '6379'
  368. ToPort: '6379'
  369. IpProtocol: tcp
  370. - SourceSecurityGroupId: !Ref webgroup
  371. FromPort: '2049'
  372. ToPort: '2049'
  373. IpProtocol: tcp
  374. SecurityGroupEgress:
  375. - CidrIp: 0.0.0.0/0
  376. IpProtocol: '-1'
  377. VpcId: !Ref vpc1
  378. Metadata:
  379. 'AWS::CloudFormation::Designer':
  380. id: e2fe8abf-7e4a-472a-88e6-52c5b75b9924
  381. efssg:
  382. Type: 'AWS::EC2::SecurityGroup'
  383. Properties:
  384. GroupDescription: sgefs
  385. GroupName: sg_efs
  386. Tags:
  387. - Key: Name
  388. Value: sg_efs
  389. SecurityGroupIngress:
  390. - SourceSecurityGroupId: !Ref webgroup
  391. FromPort: '2049'
  392. ToPort: '2049'
  393. IpProtocol: tcp
  394. - SourceSecurityGroupId: !Ref lambdasg
  395. FromPort: '2049'
  396. ToPort: '2049'
  397. IpProtocol: tcp
  398. SecurityGroupEgress:
  399. - CidrIp: 0.0.0.0/0
  400. IpProtocol: '-1'
  401. VpcId: !Ref vpc1
  402. Metadata:
  403. 'AWS::CloudFormation::Designer':
  404. id: a2a71bad-d448-4630-ae7a-ac51d0366306
  405. cachegroup:
  406. Type: 'AWS::ElastiCache::SubnetGroup'
  407. Properties:
  408. CacheSubnetGroupName: cachegroup
  409. Description: cachegroup
  410. SubnetIds:
  411. - !Ref dbnet1
  412. - !Ref dbnet2
  413. Metadata:
  414. 'AWS::CloudFormation::Designer':
  415. id: 4c252f4a-8901-40df-b0a2-386cee29c258
  416. rdsgroup:
  417. Type: 'AWS::RDS::DBSubnetGroup'
  418. Properties:
  419. DBSubnetGroupDescription: rdsgroup
  420. DBSubnetGroupName: rdsgroup
  421. Tags:
  422. - Key: Name
  423. Value: rdsgroup
  424. SubnetIds:
  425. - !Ref dbnet1
  426. - !Ref dbnet2
  427. Metadata:
  428. 'AWS::CloudFormation::Designer':
  429. id: 00338a06-280d-4c12-9255-b77136a19138
  430. rdssg:
  431. Type: 'AWS::EC2::SecurityGroup'
  432. Properties:
  433. GroupDescription: sg_rds
  434. GroupName: sg_rds
  435. Tags:
  436. - Key: Name
  437. Value: sg_rds
  438. SecurityGroupIngress:
  439. - SourceSecurityGroupId: !Ref webgroup
  440. FromPort: '3306'
  441. ToPort: '3306'
  442. IpProtocol: tcp
  443. - SourceSecurityGroupId: !Ref webgroup
  444. FromPort: '5432'
  445. ToPort: '5432'
  446. IpProtocol: tcp
  447. - SourceSecurityGroupId: !Ref lambdasg
  448. FromPort: '5432'
  449. ToPort: '5432'
  450. IpProtocol: tcp
  451. - SourceSecurityGroupId: !Ref lambdasg
  452. FromPort: '3306'
  453. ToPort: '3306'
  454. IpProtocol: tcp
  455. SecurityGroupEgress:
  456. - CidrIp: 0.0.0.0/0
  457. IpProtocol: '-1'
  458. VpcId: !Ref vpc1
  459. Metadata:
  460. 'AWS::CloudFormation::Designer':
  461. id: 6efe5731-b5ea-4e23-9b48-1353eaea32a1
  462. lambdasg:
  463. Type: 'AWS::EC2::SecurityGroup'
  464. Properties:
  465. GroupDescription: sg_lambda
  466. GroupName: sg_lambda
  467. Tags:
  468. - Key: Name
  469. Value: sg_lambda
  470. SecurityGroupEgress:
  471. - CidrIp: 0.0.0.0/0
  472. IpProtocol: '-1'
  473. VpcId: !Ref vpc1
  474. Metadata:
  475. 'AWS::CloudFormation::Designer':
  476. id: 6efe5731-b5ea-4e23-9b48-1353eaea32a1
  477. Parameters:
  478. vpccidr:
  479. Type: String
  480. Default: 192.168.0.0/16
  481. pubnet1cidr:
  482. Type: String
  483. Default: 192.168.1.0/24
  484. pubnet2cidr:
  485. Type: String
  486. Default: 192.168.2.0/24
  487. webnet1cidr:
  488. Type: String
  489. Default: 192.168.3.0/24
  490. webnet2cidr:
  491. Type: String
  492. Default: 192.168.4.0/24
  493. dbnet1cidr:
  494. Type: String
  495. Default: 192.168.5.0/24
  496. dbnet2cidr:
  497. Type: String
  498. Default: 192.168.6.0/24
  499. cacheport:
  500. Type: String
  501. Default: '11211'
  502. sgName:
  503. Type: String
  504. Default: sg_ai
  505. roleName:
  506. Type: String
  507. Default: BaseRole
  508. Outputs:
  509. PUBnet1id:
  510. Value: !Ref pubnet1
  511. PUBnet2id:
  512. Value: !Ref pubnet2
  513. WEBbnet1id:
  514. Value: !Ref webnet1
  515. WEBnet2id:
  516. Value: !Ref webnet2
  517. DBnet1id:
  518. Value: !Ref dbnet1
  519. DBnet2id:
  520. Value: !Ref dbnet2
  521. Vpcid:
  522. Value: !Ref vpc1
  523. ELBsg:
  524. Value: !Ref elbgroup
  525. ServerSG:
  526. Value: !Ref webgroup
  527. MemSg:
  528. Value: !Ref dbgroup
  529. EFSsg:
  530. Value: !Ref efssg
  531. RedisSg:
  532. Value: !Ref redissg