Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data...

139
Immutable Infrastructure Deployment Nick Hibberd

Transcript of Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data...

Page 1: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

Immutable Infrastructure Deployment

Nick Hibberd

Page 2: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

data lake

Page 3: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import
Page 4: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

Accidental chaos monkeys

Page 5: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import
Page 6: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import
Page 7: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import
Page 8: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import
Page 9: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

Solutions

Page 10: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import
Page 11: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

fib = 0 : scanl (+) 1 fib

Page 12: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 import Control.Monad.State 2 fib n = flip evalState (0,1) $ do 3 forM [0..(n-1)] $ \_ -> do 4 (a,b) <- get 5 put (b,a+b) 6 (a,b) <- get 7 return a

Page 13: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

0, 1, 1, 2, 3, 5, 8, …

Page 14: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import
Page 15: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 commission image itype role tags userData subnet name azs sg = 2 resp <- send $ runInstances image 1 1 3 & rInstanceType .~ Just itype 4 & rBlockDeviceMappings .~ instanceDeviceMappings it 5 & rIAMInstanceProfile .~ 6 fmap (\r -> iamInstanceProfileSpecification & iapsName .~ Just r)) role 7 & rUserData .~ Just (userDataBase64 userData) 8 & rSubnetId .~ fmap subnetId subnet 9 & rPlacement .~ 10 ((\az -> placement 11 & pAvailabilityZone .~ Just (availabilityZone az)) <$> azs) 12 & rSecurityGroupIds .~ [securityGroupIdText sg] 13 i <- maybe liftInvariant (pure . InstanceId) . listToMaybe . 14 fmap (view insInstanceId) . view rInstances $ resp 15 16 send $ createTags 17 & cTags .~ (fmap ec2Tag $ nameTag name : filterReservedTags tags) 18 & cResources .~ [instanceId i] 19 20 pure i

Page 16: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

Solving complex problems

with simple patterns

Page 17: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

Concepts

Page 18: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import
Page 19: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import
Page 20: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import
Page 21: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import
Page 22: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import
Page 23: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import
Page 24: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

v1

Page 25: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import
Page 26: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import
Page 27: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

v1 v2

?

Page 28: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

A

v1 v2

A

Page 29: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

v1 v2

A A A

Page 30: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

v1 v2

A A A

Page 31: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

v1 v2

A A A

Page 32: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

v1 v2

A A

Page 33: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

v2

Page 34: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import
Page 35: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 commission image itype role tags userData subnet name azs sg = 2 resp <- send $ runInstances image 1 1 3 & rInstanceType .~ Just itype 4 & rBlockDeviceMappings .~ instanceDeviceMappings it 5 & rIAMInstanceProfile .~ 6 fmap (\r -> iamInstanceProfileSpecification & iapsName .~ Just r)) role 7 & rUserData .~ Just (userDataBase64 userData) 8 & rSubnetId .~ fmap subnetId subnet 9 & rPlacement .~ 10 ((\az -> placement 11 & pAvailabilityZone .~ Just (availabilityZone az)) <$> azs) 12 & rSecurityGroupIds .~ [securityGroupIdText sg] 13 i <- maybe liftInvariant (pure . InstanceId) . listToMaybe . 14 fmap (view insInstanceId) . view rInstances $ resp 15 16 send $ createTags 17 & cTags .~ (fmap ec2Tag $ nameTag name : filterReservedTags tags) 18 & cResources .~ [instanceId i] 19 20 pure i

Page 36: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

data Configuration = Configuration { capacity :: DesiredInstances , availabilityZones :: NonEmpty AvailabilityZone , instanceType :: InstanceType , market :: Market , security :: [SecurityGroup] , iam :: IamRole , software :: [Software] , users :: [Users] , flavour :: Flavour , elb :: [LoadBalancer] , context :: Context , service :: ServiceName } deriving (Eq, Show)

Page 37: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

data Configuration = Configuration { capacity :: DesiredInstances , availabilityZones :: NonEmpty AvailabilityZone , instanceType :: InstanceType , market :: Market , security :: [SecurityGroup] , iam :: IamRole , software :: [Software] , users :: [Users] , flavour :: Flavour , elb :: [LoadBalancer] , context :: Context , service :: ServiceName } deriving (Eq, Show)

Page 38: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

data Configuration = Configuration { capacity :: DesiredInstances , availabilityZones :: NonEmpty AvailabilityZone , instanceType :: InstanceType , market :: Market , security :: [SecurityGroup] , iam :: IamRole , software :: [Software] , users :: [Users] , flavour :: Flavour , elb :: [LoadBalancer] , context :: Context , service :: ServiceName } deriving (Eq, Show)

Page 39: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

data Configuration = Configuration { capacity :: DesiredInstances , availabilityZones :: NonEmpty AvailabilityZone , instanceType :: InstanceType , market :: Market , security :: [SecurityGroup] , iam :: IamRole , software :: [Software] , users :: [Users] , flavour :: Flavour , elb :: [LoadBalancer] , context :: Context , service :: ServiceName } deriving (Eq, Show)

Page 40: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

data Configuration = Configuration { capacity :: DesiredInstances , availabilityZones :: NonEmpty AvailabilityZone , instanceType :: InstanceType , market :: Market , security :: [SecurityGroup] , iam :: IamRole , software :: [Software] , users :: [Users] , flavour :: Flavour , elb :: [LoadBalancer] , context :: Context , service :: ServiceName } deriving (Eq, Show)

Page 41: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import
Page 42: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

data Group = Group { groupName :: GroupName , groupConfiguration :: ConfigurationName , groupCreationTime :: UTCTime , groupCapacity :: DesiredInstances , groupAvailabilityZones :: NonEmpty AvailabilityZone , groupInstances :: [InstanceId] , groupInstanceHealth :: [InstanceHealth] , groupService :: ServiceName , groupLifeCycle :: LifeCycle , groupEnvironment :: Environment , groupELB :: [LoadBalancer] } deriving (Eq, Show)

Page 43: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

data Group = Group { groupName :: GroupName , groupConfiguration :: ConfigurationName , groupCreationTime :: UTCTime , groupCapacity :: DesiredInstances , groupAvailabilityZones :: NonEmpty AvailabilityZone , groupInstances :: [InstanceId] , groupInstanceHealth :: [InstanceHealth] , groupService :: ServiceName , groupLifeCycle :: LifeCycle , groupEnvironment :: Environment , groupELB :: [LoadBalancer] } deriving (Eq, Show)

Page 44: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

data Group = Group { groupName :: GroupName , groupConfiguration :: ConfigurationName , groupCreationTime :: UTCTime , groupCapacity :: DesiredInstances , groupAvailabilityZones :: NonEmpty AvailabilityZone , groupInstances :: [InstanceId] , groupInstanceHealth :: [InstanceHealth] , groupService :: ServiceName , groupLifeCycle :: LifeCycle , groupEnvironment :: Environment , groupELB :: [LoadBalancer] } deriving (Eq, Show)

Page 45: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

data Group = Group { groupName :: GroupName , groupConfiguration :: ConfigurationName , groupCreationTime :: UTCTime , groupCapacity :: DesiredInstances , groupAvailabilityZones :: NonEmpty AvailabilityZone , groupInstances :: [InstanceId] , groupInstanceHealth :: [InstanceHealth] , groupService :: ServiceName , groupLifeCycle :: LifeCycle , groupEnvironment :: Environment , groupELB :: [LoadBalancer] } deriving (Eq, Show)

Page 46: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

data Group = Group { groupName :: GroupName , groupConfiguration :: ConfigurationName , groupCreationTime :: UTCTime , groupCapacity :: DesiredInstances , groupAvailabilityZones :: NonEmpty AvailabilityZone , groupInstances :: [InstanceId] , groupInstanceHealth :: [InstanceHealth] , groupService :: ServiceName , groupLifeCycle :: LifeCycle , groupEnvironment :: Environment , groupELB :: [LoadBalancer] } deriving (Eq, Show)

Page 47: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

Deployment as a function

Page 48: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

Configuration -> [Group] -> ?

Page 49: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 commission image itype role tags userData subnet name azs sg = 2 resp <- send $ runInstances image 1 1 3 & rInstanceType .~ Just itype 4 & rBlockDeviceMappings .~ instanceDeviceMappings it 5 & rIAMInstanceProfile .~ 6 fmap (\r -> iamInstanceProfileSpecification & iapsName .~ Just r)) role 7 & rUserData .~ Just (userDataBase64 userData) 8 & rSubnetId .~ fmap subnetId subnet 9 & rPlacement .~ 10 ((\az -> placement 11 & pAvailabilityZone .~ Just (availabilityZone az)) <$> azs) 12 & rSecurityGroupIds .~ [securityGroupIdText sg] 13 i <- maybe liftInvariant (pure . InstanceId) . listToMaybe . 14 fmap (view insInstanceId) . view rInstances $ resp 15 16 send $ createTags 17 & cTags .~ (fmap ec2Tag $ nameTag name : filterReservedTags tags) 18 & cResources .~ [instanceId i] 19 20 pure i

Page 50: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

Configuration -> [Group] -> Goal

Page 51: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

data Goal = CreateGroup Configuration | SetCapacity GroupName DesiredInstances | SetLifeCycle GroupName Resolved LifeCycle | NotYetHealthy GroupName [InstanceHealth] | DoNothing

Page 52: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

data Goal = CreateGroup Configuration | SetCapacity GroupName DesiredInstances | SetLifeCycle GroupName Resolved LifeCycle | NotYetHealthy GroupName [InstanceHealth] | DoNothing

Page 53: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

Deployment tool

AA A

Page 54: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

A

AA A A A A A A

service x

A

Deployment tool

A

Page 55: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

A

service x

A

Deployment tool

A

AA A A A A A A

A A A A A A A

Page 56: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

AAdd 7

AA A A A A A A

A A

Page 57: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

A

A A A A A A A

A A A A A A A

A A A A A A A

AA A

Page 58: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

A

AA A A A A A A

A ASet total to 14

Page 59: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

AA A A A A A A

AA A

A A A A A A A

Page 60: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

Idempotent actions

data Goal = CreateGroup Configuration | SetCapacity GroupName DesiredInstances | SetLifeCycle GroupName Resolved LifeCycle | NotYetHealthy GroupName [InstanceHealth] | DoNothing

Page 61: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

data Goal = CreateGroup Configuration | SetCapacity GroupName DesiredInstances | SetLifeCycle GroupName Resolved LifeCycle | NotYetHealthy GroupName [InstanceHealth] | DoNothing

Page 62: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import
Page 63: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

data Goal = CreateGroup Configuration | SetCapacity GroupName DesiredInstances | SetLifeCycle GroupName Resolved LifeCycle | NotYetHealthy GroupName [InstanceHealth] | DoNothing

Page 64: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

data Goal = CreateGroup Resolved | SetCapacity GroupName DesiredInstances | SetLifeCycle GroupName Resolved LifeCycle | NotYetHealthy GroupName [InstanceHealth] | DoNothing

Page 65: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

data Goal = CreateGroup Resolved | SetCapacity GroupName DesiredInstances | SetLifeCycle GroupName Resolved LifeCycle | NotYetHealthy GroupName [InstanceHealth] | DoNothing

Page 66: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

Rules

Page 67: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

data Result a = TerminateFailure Error | TerminateSuccess Goal | Continue a

Page 68: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

data Result a = TerminateFailure Error | TerminateSuccess Goal | Continue a

Page 69: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

data Result a = TerminateFailure Error | TerminateSuccess Goal | Continue a

Page 70: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

data Result a = TerminateFailure Error | TerminateSuccess Goal | Continue a

Page 71: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

data Result a = TerminateFailure Error | TerminateSuccess Goal | Continue a

Page 72: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 instance Monad Result where 2 (>>=) ma f = 3 case ma of 4 TerminateSuccess p -> 5 TerminateSuccess p 6 TerminateFailure be -> 7 TerminateFailure be 8 Continue a -> 9 f a 10 11 return = 12 Continue

Page 73: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 instance Monad Result where 2 (>>=) ma f = 3 case ma of 4 TerminateSuccess p -> 5 TerminateSuccess p 6 TerminateFailure be -> 7 TerminateFailure be 8 Continue a -> 9 f a 10 11 return = 12 Continue

Page 74: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 instance Monad Result where 2 (>>=) ma f = 3 case ma of 4 TerminateSuccess p -> 5 TerminateSuccess p 6 TerminateFailure be -> 7 TerminateFailure be 8 Continue a -> 9 f a 10 11 return = 12 Continue

Page 75: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 instance Monad Result where 2 (>>=) ma f = 3 case ma of 4 TerminateSuccess p -> 5 TerminateSuccess p 6 TerminateFailure be -> 7 TerminateFailure be 8 Continue a -> 9 f a 10 11 return = 12 Continue

Page 76: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 success :: Goal -> Result () 2 success p = 3 TerminateSuccess p

Page 77: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 with :: Maybe a -> (a -> Result ()) -> Result () 2 with m f = 3 case m of 4 Just v -> 5 f v 6 Nothing -> 7 pure ()

Page 78: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

Create a server

Page 79: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 calculate :: Configuration -> [Group] -> Result () 2 calculate conf cs = do 3 4 when (noMatchingVersions conf cs) . 5 success $ CreateGroup conf 6 7 ...

Page 80: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

Aside

Page 81: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

if software /= software' then if users /= users' then if permissions /= permissions' then if metadata /= metadata' then if location /= location' then if market /= market' then DONT DEPLOY else DEPLOY else DEPLOY else DEPLOY else DEPLOY else DEPLOY else DEPLOY

Page 82: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

if software /= software' then if users /= users' then if permissions /= permissions' then if metadata /= metadata' then if location /= location' then if market /= market' then DONT DEPLOY else DEPLOY else DEPLOY else DEPLOY else DEPLOY else DEPLOY else DEPLOY

if users /= users' then if permissions /= permissions' then if metadata /= metadata' then if location /= location' then if market /= market' then DONT DEPLOY else DEPLOY else DEPLOY else DEPLOY else DEPLOY else DEPLOY

Page 83: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

Hash

#

Page 84: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

data HashPayload = HashPayload { hashSoftware :: [Software] , hashUsers :: [User] , hashSecurityGroups :: [SecurityGroup] , hashIam :: Iam , hashFlavour :: Flavour , hashInstanceType :: InstanceType , hashLoadBalancer :: [LoadBalancer] , hashRollover :: Maybe Rollover , hashMarket :: Market , hashClient :: Client , hashAvailabilityZone :: NonEmpty AvailabilityZone }

Page 85: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

HashPayload -> Text

Page 86: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

HashPayload -> Text

16848e7…137ec4

HashPayload [] [User "jimbob"] [SecurityGroup "ops"] (Iam "ops") (Flavour "base.image") T2_Nano [] None OnDemand (Client "ylj") (AvailabilityZone "ap-southeast-2c" :| [] )

Page 87: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 noMatchingVersions :: Configuration -> [Group] -> Bool 2 noMatchingVersions conf groups = 3 null $ filter (\g -> hash conf == groupHash g) groups

Page 88: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

Immutable infrastructure

Page 89: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

2016-04-29

Page 90: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

2016-04-29 -> 38651b2f9b047347a682eab7acc4a0459694fa22

2016-04-30 -> aa07113a5aab33559429223015bb90a33ce654f9

Page 91: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

Desired

Page 92: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 calculate :: Configuration -> [Group] -> Result () 2 calculate conf cs = do 3 ... 4 5 with (desiredGroup conf cs) $ \r -> do 6 7 with (underCapacity conf r) $ \i -> 8 success . 9 SetCapacity (groupName r) $ increaseInstances i

v1 v2

Page 93: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 calculate :: Configuration -> [Group] -> Result () 2 calculate conf cs = do 3 ... 4 5 with (desiredGroup conf cs) $ \r -> do 6 7 with (underCapacity conf r) $ \i -> 8 success . 9 SetCapacity (groupName r) $ increaseInstances i

Page 94: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 calculate :: Configuration -> [Group] -> Result () 2 calculate conf cs = do 3 ... 4 5 with (desiredGroup conf cs) $ \r -> do 6 7 with (underCapacity conf r) $ \i -> 8 success . 9 SetCapacity (groupName r) $ increaseInstances i

Page 95: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 calculate :: Configuration -> [Group] -> Result () 2 calculate conf cs = do 3 ... 4 5 with (desiredGroup conf cs) $ \r -> do 6 ... 7 8 with (overCapacity conf r) $ \i -> 9 success . 10 SetCapacity (groupName r) $ decreaseInstances i

Page 96: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 calculate :: Configuration -> [Group] -> Result () 2 calculate conf cs = do 3 ... 4 5 with (desiredGroup conf cs) $ \r -> do 6 ... 7 8 with (overCapacity conf r) $ \i -> 9 success . 10 SetCapacity (groupName r) $ decreaseInstances i

Page 97: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 calculate :: Configuration -> [Group] -> Result () 2 calculate conf cs = do 3 ... 4 5 with (desiredGroup conf cs) $ \r -> do 6 ... 7 8 when (not $ whenHealthy r) . 9 success $ NotYetHealthy (groupName r) (groupInstanceHealth r)

Page 98: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 calculate :: Configuration -> [Group] -> Result () 2 calculate conf cs = do 3 ... 4 5 with (desiredGroup conf cs) $ \r -> do 6 7 with (underCapacity conf r) $ \i -> 8 success . 9 SetCapacity (groupName r) $ increaseInstances i 10 11 with (overCapacity conf r) $ \i -> 12 success . 13 SetCapacity (groupName r) $ decreaseInstances i 14 15 when (not $ whenHealthy r) . 16 success $ NotYetHealthy (groupName r) (groupInstanceHealth r)

Page 99: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import
Page 100: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 calculate :: Configuration -> [Group] -> Result () 2 calculate conf cs = do 3 ... 4 5 with (leastDesirableGroup conf cs)

v1 v2

Page 101: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 calculate :: Configuration -> [Group] -> Result () 2 calculate conf cs = do 3 ... 4 5 with (leastDesirableGroup conf cs) $ \g -> do 6 7 when (active g) . 8 success . SetLifeCycle (groupResultName g) conf $ Inactive

Page 102: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 calculate :: Configuration -> [Group] -> Result () 2 calculate conf cs = do 3 ... 4 5 with (leastDesirableGroup conf cs) $ \g -> do 6 7 ... 8 9 when (inactive g) . 10 success . SetCapacity (groupResultName g) $ DesiredInstances 0

Page 103: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 calculate :: Configuration -> [Group] -> Result () 2 calculate conf cs = do 3 4 when (noMatchingVersions conf cs) . 5 success $ CreateGroup conf 6 7 with (desiredGroup conf cs) $ \r -> do 8 9 with (underCapacity conf r) $ \i -> 10 success . 11 SetCapacity (groupName r) $ increaseInstances i 12 13 with (leastDesirableGroup conf cs) $ \g -> do 14 15 when (active g) . 16 success . SetLifeCycle (groupResultName g) conf $ Inactive 17 18 when (inactive g) . 19 success . SetCapacity (groupResultName g) $ DesiredInstances 0

Page 104: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

Maintenance

Page 105: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 calculate :: Configuration -> [Group] -> Result () 2 calculate conf cs = do 3 4 when (noMatchingVersions conf cs) . 5 success $ CreateGroup conf 6 7 ...

Page 106: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

v1 v2

Page 107: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

v1 v2

Page 108: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

v1 v2 v3

Page 109: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

v1 v2 v3

Page 110: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

v1 v2 v3 v4

Page 111: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 calculate :: Configuration -> [Group] -> Result () 2 calculate conf cs = do 3 4 when (noMatchingVersions conf cs) . 5 success $ CreateGroup conf 6 7 ...

Page 112: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 calculate :: Configuration -> [Group] -> Result () 2 calculate conf cs = do 3 4 when (noMatchingVersions conf cs && length cs < 2) . 5 success $ CreateGroup conf 6 7 ...

Page 113: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

v1 v2

Page 114: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

v1 v2

Page 115: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

v1 v2

Page 116: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

v1 v2

Page 117: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

v1 v2

Page 118: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

v2

Page 119: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

v2 v4

Page 120: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import
Page 121: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

Loop School

Page 122: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

The perfect program with haskell syntax

value <- read

let answer = calculate value

doit answer

Page 123: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

The perfect Loop with haskell syntax

forever $ do

value <- read

let answer = calculate value

doit answer

Page 124: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

value <- IO

let goals = calculate conf groups

doit goals

Page 125: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

confs <- retrieveConfigurations

groups <- retrieveGroups

let goals = calculate conf groups

doit goals

Page 126: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

Goal -> IO ()

Page 127: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 runGoal :: Goal -> IO () 2 runGoal goal = 3 case goal of 4 CreateGroup b -> do 6 createGroup g 7

Page 128: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 createGroup g = 2 continueIfExists . void . send $ A.createAutoScalingGroup 3 (renderName $ groupName g) 4 0 5 10 6 & A.casgAvailabilityZones .~ 7 Just (availabilityZone <$> groupAvailabilityZones g) 8 & A.casgTags .~ 9 (groupTags g) 10 & A.casgLaunchConfigurationName .~ 11 Just (configurationName $ groupConfName g) 12 & A.casgDesiredCapacity .~ 13 Just (desiredInstances . minimumDesiredInstances $ groupDesiredInstances g) 14 & A.casgLoadBalancerNames .~ 15 (loadBalancer <$> groupELB g)

Page 129: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 runGoal :: Goal -> IO () 2 runGoal goal = 3 case goal of 4 CreateGroup b -> 5 ... 6 7 SetLifeCycle gn b l -> do 8 setLifeCycle gn l 9 when (l == Inactive) . lift $ 10 detachLoadBalancers gn

Page 130: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 runGoal :: Goal -> IO () 2 runGoal goal = 3 case goal of 4 ... 5 6 SetCapacity gn di -> do 7 setCapacity gn di

Page 131: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 runGoal :: Goal -> IO () 2 runGoal goal = 3 case goal of 4 ... 5 6 NotYetHealthy gn hs -> do 7 now <- getCurrentTime 8 case checkHealth now hs of 9 [] -> 10 pure () 11 unhealthy -> 12 interverene gn unhealthy

Page 132: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 runGoal :: Goal -> IO () 2 runGoal goal = 3 case goal of 4 ... 5 6 DoNothing -> 7 pure ()

Page 133: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 runGoal :: Goal -> IO () 2 runGoal goal = 3 case goal of 4 CreateGroup b -> do 5 createConfiguration c 6 createGroup g 7 8 SetLifeCycle gn b l -> do 9 setLifeCycle gn l 10 when (l == Inactive) . lift $ 11 detachLoadBalancers gn 12 13 SetCapacity gn di -> do 14 setCapacity gn di 15 16 NotYetHealthy gn hs -> do 17 now <- getCurrentTime 18 case checkHealth now hs of 19 [] -> 20 pure () 21 unhealthy -> 22 interverene gn unhealthy 23 24 DoNothing -> 25 pure ()

Page 134: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 work :: IO () 2 work = do 3 4 confs <- retrieveConfigurations 5 6 groups <- retrieveGroups 7 8 let goals = calculateAll confs groups 9 10 mapM runGoal goal

Page 135: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

1 workForever :: IO () 2 workForever = 3 forever $ work

Page 136: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import
Page 137: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import
Page 138: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import
Page 139: Immutable Infrastructure Deployment€¦ · Immutable Infrastructure Deployment Nick Hibberd. data lake. Accidental chaos monkeys. Solutions. fib = 0 : scanl (+) 1 fib . 1 import

Immutable Infrastructure Deployment