{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.OpsWorks.Types.DeploymentCommand
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.OpsWorks.Types.DeploymentCommand where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.OpsWorks.Types.DeploymentCommandName
import qualified Amazonka.Prelude as Prelude

-- | Used to specify a stack or deployment command.
--
-- /See:/ 'newDeploymentCommand' smart constructor.
data DeploymentCommand = DeploymentCommand'
  { -- | The arguments of those commands that take arguments. It should be set to
    -- a JSON object with the following format:
    --
    -- @{\"arg_name1\" : [\"value1\", \"value2\", ...], \"arg_name2\" : [\"value1\", \"value2\", ...], ...}@
    --
    -- The @update_dependencies@ command takes two arguments:
    --
    -- -   @upgrade_os_to@ - Specifies the desired Amazon Linux version for
    --     instances whose OS you want to upgrade, such as
    --     @Amazon Linux 2016.09@. You must also set the @allow_reboot@
    --     argument to true.
    --
    -- -   @allow_reboot@ - Specifies whether to allow AWS OpsWorks Stacks to
    --     reboot the instances if necessary, after installing the updates.
    --     This argument can be set to either @true@ or @false@. The default
    --     value is @false@.
    --
    -- For example, to upgrade an instance to Amazon Linux 2016.09, set @Args@
    -- to the following.
    --
    -- @ { \"upgrade_os_to\":[\"Amazon Linux 2016.09\"], \"allow_reboot\":[\"true\"] } @
    DeploymentCommand -> Maybe (HashMap Text [Text])
args :: Prelude.Maybe (Prelude.HashMap Prelude.Text [Prelude.Text]),
    -- | Specifies the operation. You can specify only one command.
    --
    -- For stacks, the following commands are available:
    --
    -- -   @execute_recipes@: Execute one or more recipes. To specify the
    --     recipes, set an @Args@ parameter named @recipes@ to the list of
    --     recipes to be executed. For example, to execute @phpapp::appsetup@,
    --     set @Args@ to @{\"recipes\":[\"phpapp::appsetup\"]}@.
    --
    -- -   @install_dependencies@: Install the stack\'s dependencies.
    --
    -- -   @update_custom_cookbooks@: Update the stack\'s custom cookbooks.
    --
    -- -   @update_dependencies@: Update the stack\'s dependencies.
    --
    -- The update_dependencies and install_dependencies commands are supported
    -- only for Linux instances. You can run the commands successfully on
    -- Windows instances, but they do nothing.
    --
    -- For apps, the following commands are available:
    --
    -- -   @deploy@: Deploy an app. Ruby on Rails apps have an optional @Args@
    --     parameter named @migrate@. Set @Args@ to {\"migrate\":[\"true\"]} to
    --     migrate the database. The default setting is
    --     {\"migrate\":[\"false\"]}.
    --
    -- -   @rollback@ Roll the app back to the previous version. When you
    --     update an app, AWS OpsWorks Stacks stores the previous version, up
    --     to a maximum of five versions. You can use this command to roll an
    --     app back as many as four versions.
    --
    -- -   @start@: Start the app\'s web or application server.
    --
    -- -   @stop@: Stop the app\'s web or application server.
    --
    -- -   @restart@: Restart the app\'s web or application server.
    --
    -- -   @undeploy@: Undeploy the app.
    DeploymentCommand -> DeploymentCommandName
name :: DeploymentCommandName
  }
  deriving (DeploymentCommand -> DeploymentCommand -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeploymentCommand -> DeploymentCommand -> Bool
$c/= :: DeploymentCommand -> DeploymentCommand -> Bool
== :: DeploymentCommand -> DeploymentCommand -> Bool
$c== :: DeploymentCommand -> DeploymentCommand -> Bool
Prelude.Eq, ReadPrec [DeploymentCommand]
ReadPrec DeploymentCommand
Int -> ReadS DeploymentCommand
ReadS [DeploymentCommand]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeploymentCommand]
$creadListPrec :: ReadPrec [DeploymentCommand]
readPrec :: ReadPrec DeploymentCommand
$creadPrec :: ReadPrec DeploymentCommand
readList :: ReadS [DeploymentCommand]
$creadList :: ReadS [DeploymentCommand]
readsPrec :: Int -> ReadS DeploymentCommand
$creadsPrec :: Int -> ReadS DeploymentCommand
Prelude.Read, Int -> DeploymentCommand -> ShowS
[DeploymentCommand] -> ShowS
DeploymentCommand -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeploymentCommand] -> ShowS
$cshowList :: [DeploymentCommand] -> ShowS
show :: DeploymentCommand -> String
$cshow :: DeploymentCommand -> String
showsPrec :: Int -> DeploymentCommand -> ShowS
$cshowsPrec :: Int -> DeploymentCommand -> ShowS
Prelude.Show, forall x. Rep DeploymentCommand x -> DeploymentCommand
forall x. DeploymentCommand -> Rep DeploymentCommand x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeploymentCommand x -> DeploymentCommand
$cfrom :: forall x. DeploymentCommand -> Rep DeploymentCommand x
Prelude.Generic)

-- |
-- Create a value of 'DeploymentCommand' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'args', 'deploymentCommand_args' - The arguments of those commands that take arguments. It should be set to
-- a JSON object with the following format:
--
-- @{\"arg_name1\" : [\"value1\", \"value2\", ...], \"arg_name2\" : [\"value1\", \"value2\", ...], ...}@
--
-- The @update_dependencies@ command takes two arguments:
--
-- -   @upgrade_os_to@ - Specifies the desired Amazon Linux version for
--     instances whose OS you want to upgrade, such as
--     @Amazon Linux 2016.09@. You must also set the @allow_reboot@
--     argument to true.
--
-- -   @allow_reboot@ - Specifies whether to allow AWS OpsWorks Stacks to
--     reboot the instances if necessary, after installing the updates.
--     This argument can be set to either @true@ or @false@. The default
--     value is @false@.
--
-- For example, to upgrade an instance to Amazon Linux 2016.09, set @Args@
-- to the following.
--
-- @ { \"upgrade_os_to\":[\"Amazon Linux 2016.09\"], \"allow_reboot\":[\"true\"] } @
--
-- 'name', 'deploymentCommand_name' - Specifies the operation. You can specify only one command.
--
-- For stacks, the following commands are available:
--
-- -   @execute_recipes@: Execute one or more recipes. To specify the
--     recipes, set an @Args@ parameter named @recipes@ to the list of
--     recipes to be executed. For example, to execute @phpapp::appsetup@,
--     set @Args@ to @{\"recipes\":[\"phpapp::appsetup\"]}@.
--
-- -   @install_dependencies@: Install the stack\'s dependencies.
--
-- -   @update_custom_cookbooks@: Update the stack\'s custom cookbooks.
--
-- -   @update_dependencies@: Update the stack\'s dependencies.
--
-- The update_dependencies and install_dependencies commands are supported
-- only for Linux instances. You can run the commands successfully on
-- Windows instances, but they do nothing.
--
-- For apps, the following commands are available:
--
-- -   @deploy@: Deploy an app. Ruby on Rails apps have an optional @Args@
--     parameter named @migrate@. Set @Args@ to {\"migrate\":[\"true\"]} to
--     migrate the database. The default setting is
--     {\"migrate\":[\"false\"]}.
--
-- -   @rollback@ Roll the app back to the previous version. When you
--     update an app, AWS OpsWorks Stacks stores the previous version, up
--     to a maximum of five versions. You can use this command to roll an
--     app back as many as four versions.
--
-- -   @start@: Start the app\'s web or application server.
--
-- -   @stop@: Stop the app\'s web or application server.
--
-- -   @restart@: Restart the app\'s web or application server.
--
-- -   @undeploy@: Undeploy the app.
newDeploymentCommand ::
  -- | 'name'
  DeploymentCommandName ->
  DeploymentCommand
newDeploymentCommand :: DeploymentCommandName -> DeploymentCommand
newDeploymentCommand DeploymentCommandName
pName_ =
  DeploymentCommand'
    { $sel:args:DeploymentCommand' :: Maybe (HashMap Text [Text])
args = forall a. Maybe a
Prelude.Nothing,
      $sel:name:DeploymentCommand' :: DeploymentCommandName
name = DeploymentCommandName
pName_
    }

-- | The arguments of those commands that take arguments. It should be set to
-- a JSON object with the following format:
--
-- @{\"arg_name1\" : [\"value1\", \"value2\", ...], \"arg_name2\" : [\"value1\", \"value2\", ...], ...}@
--
-- The @update_dependencies@ command takes two arguments:
--
-- -   @upgrade_os_to@ - Specifies the desired Amazon Linux version for
--     instances whose OS you want to upgrade, such as
--     @Amazon Linux 2016.09@. You must also set the @allow_reboot@
--     argument to true.
--
-- -   @allow_reboot@ - Specifies whether to allow AWS OpsWorks Stacks to
--     reboot the instances if necessary, after installing the updates.
--     This argument can be set to either @true@ or @false@. The default
--     value is @false@.
--
-- For example, to upgrade an instance to Amazon Linux 2016.09, set @Args@
-- to the following.
--
-- @ { \"upgrade_os_to\":[\"Amazon Linux 2016.09\"], \"allow_reboot\":[\"true\"] } @
deploymentCommand_args :: Lens.Lens' DeploymentCommand (Prelude.Maybe (Prelude.HashMap Prelude.Text [Prelude.Text]))
deploymentCommand_args :: Lens' DeploymentCommand (Maybe (HashMap Text [Text]))
deploymentCommand_args = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeploymentCommand' {Maybe (HashMap Text [Text])
args :: Maybe (HashMap Text [Text])
$sel:args:DeploymentCommand' :: DeploymentCommand -> Maybe (HashMap Text [Text])
args} -> Maybe (HashMap Text [Text])
args) (\s :: DeploymentCommand
s@DeploymentCommand' {} Maybe (HashMap Text [Text])
a -> DeploymentCommand
s {$sel:args:DeploymentCommand' :: Maybe (HashMap Text [Text])
args = Maybe (HashMap Text [Text])
a} :: DeploymentCommand) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Specifies the operation. You can specify only one command.
--
-- For stacks, the following commands are available:
--
-- -   @execute_recipes@: Execute one or more recipes. To specify the
--     recipes, set an @Args@ parameter named @recipes@ to the list of
--     recipes to be executed. For example, to execute @phpapp::appsetup@,
--     set @Args@ to @{\"recipes\":[\"phpapp::appsetup\"]}@.
--
-- -   @install_dependencies@: Install the stack\'s dependencies.
--
-- -   @update_custom_cookbooks@: Update the stack\'s custom cookbooks.
--
-- -   @update_dependencies@: Update the stack\'s dependencies.
--
-- The update_dependencies and install_dependencies commands are supported
-- only for Linux instances. You can run the commands successfully on
-- Windows instances, but they do nothing.
--
-- For apps, the following commands are available:
--
-- -   @deploy@: Deploy an app. Ruby on Rails apps have an optional @Args@
--     parameter named @migrate@. Set @Args@ to {\"migrate\":[\"true\"]} to
--     migrate the database. The default setting is
--     {\"migrate\":[\"false\"]}.
--
-- -   @rollback@ Roll the app back to the previous version. When you
--     update an app, AWS OpsWorks Stacks stores the previous version, up
--     to a maximum of five versions. You can use this command to roll an
--     app back as many as four versions.
--
-- -   @start@: Start the app\'s web or application server.
--
-- -   @stop@: Stop the app\'s web or application server.
--
-- -   @restart@: Restart the app\'s web or application server.
--
-- -   @undeploy@: Undeploy the app.
deploymentCommand_name :: Lens.Lens' DeploymentCommand DeploymentCommandName
deploymentCommand_name :: Lens' DeploymentCommand DeploymentCommandName
deploymentCommand_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeploymentCommand' {DeploymentCommandName
name :: DeploymentCommandName
$sel:name:DeploymentCommand' :: DeploymentCommand -> DeploymentCommandName
name} -> DeploymentCommandName
name) (\s :: DeploymentCommand
s@DeploymentCommand' {} DeploymentCommandName
a -> DeploymentCommand
s {$sel:name:DeploymentCommand' :: DeploymentCommandName
name = DeploymentCommandName
a} :: DeploymentCommand)

instance Data.FromJSON DeploymentCommand where
  parseJSON :: Value -> Parser DeploymentCommand
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"DeploymentCommand"
      ( \Object
x ->
          Maybe (HashMap Text [Text])
-> DeploymentCommandName -> DeploymentCommand
DeploymentCommand'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Args" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Name")
      )

instance Prelude.Hashable DeploymentCommand where
  hashWithSalt :: Int -> DeploymentCommand -> Int
hashWithSalt Int
_salt DeploymentCommand' {Maybe (HashMap Text [Text])
DeploymentCommandName
name :: DeploymentCommandName
args :: Maybe (HashMap Text [Text])
$sel:name:DeploymentCommand' :: DeploymentCommand -> DeploymentCommandName
$sel:args:DeploymentCommand' :: DeploymentCommand -> Maybe (HashMap Text [Text])
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text [Text])
args
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` DeploymentCommandName
name

instance Prelude.NFData DeploymentCommand where
  rnf :: DeploymentCommand -> ()
rnf DeploymentCommand' {Maybe (HashMap Text [Text])
DeploymentCommandName
name :: DeploymentCommandName
args :: Maybe (HashMap Text [Text])
$sel:name:DeploymentCommand' :: DeploymentCommand -> DeploymentCommandName
$sel:args:DeploymentCommand' :: DeploymentCommand -> Maybe (HashMap Text [Text])
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text [Text])
args seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf DeploymentCommandName
name

instance Data.ToJSON DeploymentCommand where
  toJSON :: DeploymentCommand -> Value
toJSON DeploymentCommand' {Maybe (HashMap Text [Text])
DeploymentCommandName
name :: DeploymentCommandName
args :: Maybe (HashMap Text [Text])
$sel:name:DeploymentCommand' :: DeploymentCommand -> DeploymentCommandName
$sel:args:DeploymentCommand' :: DeploymentCommand -> Maybe (HashMap Text [Text])
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Args" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text [Text])
args,
            forall a. a -> Maybe a
Prelude.Just (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= DeploymentCommandName
name)
          ]
      )