forked from mbj/stratosphere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrds-master-replica.hs
87 lines (78 loc) · 2.55 KB
/
rds-master-replica.hs
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
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
-- | This example creates a Postgres RDS master and slave with a parameter
-- group. Also note the DeletionPolicy of Retain, which will keep the resource
-- alive if you delete the stack.
module Main where
import Control.Lens
import qualified Data.ByteString.Lazy.Char8 as B
import Stratosphere
main :: IO ()
main = B.putStrLn $ encodeTemplate dbTemplate
dbTemplate :: Template
dbTemplate =
template
[ rdsParamGroup & resourceDeletionPolicy ?~ Retain
, rdsMaster & resourceDeletionPolicy ?~ Retain
, rdsReplica & resourceDeletionPolicy ?~ Retain
]
& templateDescription ?~ "Stack for and RDS master and replica"
& templateParameters ?~
[ parameter "RdsMasterPassword" "String"
, parameter "RdsSubnetGroup" "String"
, parameter "VpcId" "String"
]
rdsMaster :: Resource
rdsMaster =
resource "RDSMaster" $
rdsdbInstance
"db.t2.micro"
-- DBInstanceIdentifier is not present in the new schema for some reason
-- & rdsdbiDBInstanceIdentifier ?~ Literal "db-master"
& rdsdbiStorageType ?~ "gp2"
& rdsdbiAllocatedStorage ?~ "20"
& rdsdbiDBParameterGroupName ?~ toRef rdsParamGroup
& rdsdbiEngine ?~ "postgres"
& rdsdbiEngineVersion ?~ "9.3.10"
& rdsdbiMasterUsername ?~ "postgres"
& rdsdbiMasterUserPassword ?~ Ref "RdsMasterPassword"
& rdsdbiDBName ?~ "the_database"
& rdsdbiPreferredMaintenanceWindow ?~ "Sun:01:00-Sun:02:00"
& rdsdbiBackupRetentionPeriod ?~ Literal 30
& rdsdbiPreferredBackupWindow ?~ "08:00-09:00"
& rdsdbiPort ?~ "5432"
& rdsdbiTags ?~
[ tag "Role" "rds-master"
]
rdsReplica :: Resource
rdsReplica =
resource "RDSReplica" $
rdsdbInstance
"db.t2.micro"
-- DBInstanceIdentifier is not present in the new schema for some reason
-- & dbiDBInstanceIdentifier ?~ Literal "db-standby"
& rdsdbiSourceDBInstanceIdentifier ?~ toRef rdsMaster
& rdsdbiStorageType ?~ "gp2"
& rdsdbiTags ?~
[ tag "Role" "rds-standby"
]
rdsParamGroup :: Resource
rdsParamGroup =
resource "RDSParamGroup" $
rdsdbParameterGroup
"Parameter group for RDS instances"
"postgres9.3"
& rdsdbpgParameters ?~
[ ("checkpoint_segments", "32")
, ("effective_cache_size", "5584716")
, ("hot_standby_feedback", "1")
, ("log_connections", "1")
, ("log_disconnections", "1")
, ("log_min_duration_statement", "0")
, ("maintenance_work_mem", "2000000")
, ("max_connections", "100")
, ("max_standby_archive_delay", "3600000")
, ("max_standby_streaming_delay", "3600000")
, ("wal_buffers", "2000")
, ("work_mem", "400000")
]