Skip to content

Commit

Permalink
[stack-deploy] Add readEnvStackValueFromStack to public interface
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Jul 2, 2024
1 parent 60fbca1 commit 40a9d9b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion stack-deploy/src/StackDeploy/EnvSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module StackDeploy.EnvSpec
, envSpecValue
, readEnvSpecFromEnvironment
, readEnvSpecFromStack
, readEnvSpecValueFromStack
)
where

Expand Down Expand Up @@ -143,7 +144,20 @@ envSpecPosixEnvironment stack = traverse render . List.sortOn (.name)
-- >>> value
-- "test-stack"
readEnvSpecFromStack :: forall m . MonadIO m => CF.Stack -> EnvSpec -> m Text
readEnvSpecFromStack stack EnvSpec{..} = case value of
readEnvSpecFromStack stack EnvSpec{..} = readEnvSpecValueFromStack stack value

-- | Read an env spec value as AWS resources would do
--
-- Primary use case is to initialize operations CLI to the same state an equivalent AWS resource would have.
--
-- >>> let envSpecValue = StackDeploy.EnvSpecStackName
-- >>> let epochTime = Time.posixSecondsToUTCTime 0
-- >>> let stack = CF.newStack "test-stack" epochTime CF.StackStatus_UPDATE_COMPLETE
-- >>> value <- StackDeploy.readEnvSpecValueFromStack stack envSpecValue
-- >>> value
-- "test-stack"
readEnvSpecValueFromStack :: forall m . MonadIO m => CF.Stack -> EnvSpecValue -> m Text
readEnvSpecValueFromStack stack = \case
EnvSpecStackId -> maybe failAbsentStackId pure stack.stackId
EnvSpecStackName -> pure stack.stackName
EnvSpecStackOutput output -> liftIO $ StackDeploy.fetchStackOutput stack output
Expand Down

0 comments on commit 40a9d9b

Please sign in to comment.