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

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

-- |
-- Module      : Amazonka.ElasticBeanstalk.TerminateEnvironment
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Terminates the specified environment.
module Amazonka.ElasticBeanstalk.TerminateEnvironment
  ( -- * Creating a Request
    TerminateEnvironment (..),
    newTerminateEnvironment,

    -- * Request Lenses
    terminateEnvironment_forceTerminate,
    terminateEnvironment_terminateResources,
    terminateEnvironment_environmentName,
    terminateEnvironment_environmentId,

    -- * Destructuring the Response
    EnvironmentDescription (..),
    newEnvironmentDescription,

    -- * Response Lenses
    environmentDescription_status,
    environmentDescription_cname,
    environmentDescription_templateName,
    environmentDescription_abortableOperationInProgress,
    environmentDescription_endpointURL,
    environmentDescription_resources,
    environmentDescription_dateUpdated,
    environmentDescription_dateCreated,
    environmentDescription_health,
    environmentDescription_versionLabel,
    environmentDescription_operationsRole,
    environmentDescription_platformArn,
    environmentDescription_tier,
    environmentDescription_environmentName,
    environmentDescription_applicationName,
    environmentDescription_environmentArn,
    environmentDescription_solutionStackName,
    environmentDescription_environmentId,
    environmentDescription_healthStatus,
    environmentDescription_environmentLinks,
    environmentDescription_description,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.ElasticBeanstalk.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | Request to terminate an environment.
--
-- /See:/ 'newTerminateEnvironment' smart constructor.
data TerminateEnvironment = TerminateEnvironment'
  { -- | Terminates the target environment even if another environment in the
    -- same group is dependent on it.
    TerminateEnvironment -> Maybe Bool
forceTerminate :: Prelude.Maybe Prelude.Bool,
    -- | Indicates whether the associated AWS resources should shut down when the
    -- environment is terminated:
    --
    -- -   @true@: The specified environment as well as the associated AWS
    --     resources, such as Auto Scaling group and LoadBalancer, are
    --     terminated.
    --
    -- -   @false@: AWS Elastic Beanstalk resource management is removed from
    --     the environment, but the AWS resources continue to operate.
    --
    -- For more information, see the
    -- <https://docs.aws.amazon.com/elasticbeanstalk/latest/ug/ AWS Elastic Beanstalk User Guide.>
    --
    -- Default: @true@
    --
    -- Valid Values: @true@ | @false@
    TerminateEnvironment -> Maybe Bool
terminateResources :: Prelude.Maybe Prelude.Bool,
    -- | The name of the environment to terminate.
    --
    -- Condition: You must specify either this or an EnvironmentId, or both. If
    -- you do not specify either, AWS Elastic Beanstalk returns
    -- @MissingRequiredParameter@ error.
    TerminateEnvironment -> Maybe Text
environmentName :: Prelude.Maybe Prelude.Text,
    -- | The ID of the environment to terminate.
    --
    -- Condition: You must specify either this or an EnvironmentName, or both.
    -- If you do not specify either, AWS Elastic Beanstalk returns
    -- @MissingRequiredParameter@ error.
    TerminateEnvironment -> Maybe Text
environmentId :: Prelude.Maybe Prelude.Text
  }
  deriving (TerminateEnvironment -> TerminateEnvironment -> Bool
(TerminateEnvironment -> TerminateEnvironment -> Bool)
-> (TerminateEnvironment -> TerminateEnvironment -> Bool)
-> Eq TerminateEnvironment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TerminateEnvironment -> TerminateEnvironment -> Bool
$c/= :: TerminateEnvironment -> TerminateEnvironment -> Bool
== :: TerminateEnvironment -> TerminateEnvironment -> Bool
$c== :: TerminateEnvironment -> TerminateEnvironment -> Bool
Prelude.Eq, ReadPrec [TerminateEnvironment]
ReadPrec TerminateEnvironment
Int -> ReadS TerminateEnvironment
ReadS [TerminateEnvironment]
(Int -> ReadS TerminateEnvironment)
-> ReadS [TerminateEnvironment]
-> ReadPrec TerminateEnvironment
-> ReadPrec [TerminateEnvironment]
-> Read TerminateEnvironment
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TerminateEnvironment]
$creadListPrec :: ReadPrec [TerminateEnvironment]
readPrec :: ReadPrec TerminateEnvironment
$creadPrec :: ReadPrec TerminateEnvironment
readList :: ReadS [TerminateEnvironment]
$creadList :: ReadS [TerminateEnvironment]
readsPrec :: Int -> ReadS TerminateEnvironment
$creadsPrec :: Int -> ReadS TerminateEnvironment
Prelude.Read, Int -> TerminateEnvironment -> ShowS
[TerminateEnvironment] -> ShowS
TerminateEnvironment -> String
(Int -> TerminateEnvironment -> ShowS)
-> (TerminateEnvironment -> String)
-> ([TerminateEnvironment] -> ShowS)
-> Show TerminateEnvironment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TerminateEnvironment] -> ShowS
$cshowList :: [TerminateEnvironment] -> ShowS
show :: TerminateEnvironment -> String
$cshow :: TerminateEnvironment -> String
showsPrec :: Int -> TerminateEnvironment -> ShowS
$cshowsPrec :: Int -> TerminateEnvironment -> ShowS
Prelude.Show, (forall x. TerminateEnvironment -> Rep TerminateEnvironment x)
-> (forall x. Rep TerminateEnvironment x -> TerminateEnvironment)
-> Generic TerminateEnvironment
forall x. Rep TerminateEnvironment x -> TerminateEnvironment
forall x. TerminateEnvironment -> Rep TerminateEnvironment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TerminateEnvironment x -> TerminateEnvironment
$cfrom :: forall x. TerminateEnvironment -> Rep TerminateEnvironment x
Prelude.Generic)

-- |
-- Create a value of 'TerminateEnvironment' 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:
--
-- 'forceTerminate', 'terminateEnvironment_forceTerminate' - Terminates the target environment even if another environment in the
-- same group is dependent on it.
--
-- 'terminateResources', 'terminateEnvironment_terminateResources' - Indicates whether the associated AWS resources should shut down when the
-- environment is terminated:
--
-- -   @true@: The specified environment as well as the associated AWS
--     resources, such as Auto Scaling group and LoadBalancer, are
--     terminated.
--
-- -   @false@: AWS Elastic Beanstalk resource management is removed from
--     the environment, but the AWS resources continue to operate.
--
-- For more information, see the
-- <https://docs.aws.amazon.com/elasticbeanstalk/latest/ug/ AWS Elastic Beanstalk User Guide.>
--
-- Default: @true@
--
-- Valid Values: @true@ | @false@
--
-- 'environmentName', 'terminateEnvironment_environmentName' - The name of the environment to terminate.
--
-- Condition: You must specify either this or an EnvironmentId, or both. If
-- you do not specify either, AWS Elastic Beanstalk returns
-- @MissingRequiredParameter@ error.
--
-- 'environmentId', 'terminateEnvironment_environmentId' - The ID of the environment to terminate.
--
-- Condition: You must specify either this or an EnvironmentName, or both.
-- If you do not specify either, AWS Elastic Beanstalk returns
-- @MissingRequiredParameter@ error.
newTerminateEnvironment ::
  TerminateEnvironment
newTerminateEnvironment :: TerminateEnvironment
newTerminateEnvironment =
  TerminateEnvironment' :: Maybe Bool
-> Maybe Bool -> Maybe Text -> Maybe Text -> TerminateEnvironment
TerminateEnvironment'
    { $sel:forceTerminate:TerminateEnvironment' :: Maybe Bool
forceTerminate =
        Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:terminateResources:TerminateEnvironment' :: Maybe Bool
terminateResources = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:environmentName:TerminateEnvironment' :: Maybe Text
environmentName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:environmentId:TerminateEnvironment' :: Maybe Text
environmentId = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | Terminates the target environment even if another environment in the
-- same group is dependent on it.
terminateEnvironment_forceTerminate :: Lens.Lens' TerminateEnvironment (Prelude.Maybe Prelude.Bool)
terminateEnvironment_forceTerminate :: (Maybe Bool -> f (Maybe Bool))
-> TerminateEnvironment -> f TerminateEnvironment
terminateEnvironment_forceTerminate = (TerminateEnvironment -> Maybe Bool)
-> (TerminateEnvironment -> Maybe Bool -> TerminateEnvironment)
-> Lens
     TerminateEnvironment TerminateEnvironment (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TerminateEnvironment' {Maybe Bool
forceTerminate :: Maybe Bool
$sel:forceTerminate:TerminateEnvironment' :: TerminateEnvironment -> Maybe Bool
forceTerminate} -> Maybe Bool
forceTerminate) (\s :: TerminateEnvironment
s@TerminateEnvironment' {} Maybe Bool
a -> TerminateEnvironment
s {$sel:forceTerminate:TerminateEnvironment' :: Maybe Bool
forceTerminate = Maybe Bool
a} :: TerminateEnvironment)

-- | Indicates whether the associated AWS resources should shut down when the
-- environment is terminated:
--
-- -   @true@: The specified environment as well as the associated AWS
--     resources, such as Auto Scaling group and LoadBalancer, are
--     terminated.
--
-- -   @false@: AWS Elastic Beanstalk resource management is removed from
--     the environment, but the AWS resources continue to operate.
--
-- For more information, see the
-- <https://docs.aws.amazon.com/elasticbeanstalk/latest/ug/ AWS Elastic Beanstalk User Guide.>
--
-- Default: @true@
--
-- Valid Values: @true@ | @false@
terminateEnvironment_terminateResources :: Lens.Lens' TerminateEnvironment (Prelude.Maybe Prelude.Bool)
terminateEnvironment_terminateResources :: (Maybe Bool -> f (Maybe Bool))
-> TerminateEnvironment -> f TerminateEnvironment
terminateEnvironment_terminateResources = (TerminateEnvironment -> Maybe Bool)
-> (TerminateEnvironment -> Maybe Bool -> TerminateEnvironment)
-> Lens
     TerminateEnvironment TerminateEnvironment (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TerminateEnvironment' {Maybe Bool
terminateResources :: Maybe Bool
$sel:terminateResources:TerminateEnvironment' :: TerminateEnvironment -> Maybe Bool
terminateResources} -> Maybe Bool
terminateResources) (\s :: TerminateEnvironment
s@TerminateEnvironment' {} Maybe Bool
a -> TerminateEnvironment
s {$sel:terminateResources:TerminateEnvironment' :: Maybe Bool
terminateResources = Maybe Bool
a} :: TerminateEnvironment)

-- | The name of the environment to terminate.
--
-- Condition: You must specify either this or an EnvironmentId, or both. If
-- you do not specify either, AWS Elastic Beanstalk returns
-- @MissingRequiredParameter@ error.
terminateEnvironment_environmentName :: Lens.Lens' TerminateEnvironment (Prelude.Maybe Prelude.Text)
terminateEnvironment_environmentName :: (Maybe Text -> f (Maybe Text))
-> TerminateEnvironment -> f TerminateEnvironment
terminateEnvironment_environmentName = (TerminateEnvironment -> Maybe Text)
-> (TerminateEnvironment -> Maybe Text -> TerminateEnvironment)
-> Lens
     TerminateEnvironment TerminateEnvironment (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TerminateEnvironment' {Maybe Text
environmentName :: Maybe Text
$sel:environmentName:TerminateEnvironment' :: TerminateEnvironment -> Maybe Text
environmentName} -> Maybe Text
environmentName) (\s :: TerminateEnvironment
s@TerminateEnvironment' {} Maybe Text
a -> TerminateEnvironment
s {$sel:environmentName:TerminateEnvironment' :: Maybe Text
environmentName = Maybe Text
a} :: TerminateEnvironment)

-- | The ID of the environment to terminate.
--
-- Condition: You must specify either this or an EnvironmentName, or both.
-- If you do not specify either, AWS Elastic Beanstalk returns
-- @MissingRequiredParameter@ error.
terminateEnvironment_environmentId :: Lens.Lens' TerminateEnvironment (Prelude.Maybe Prelude.Text)
terminateEnvironment_environmentId :: (Maybe Text -> f (Maybe Text))
-> TerminateEnvironment -> f TerminateEnvironment
terminateEnvironment_environmentId = (TerminateEnvironment -> Maybe Text)
-> (TerminateEnvironment -> Maybe Text -> TerminateEnvironment)
-> Lens
     TerminateEnvironment TerminateEnvironment (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TerminateEnvironment' {Maybe Text
environmentId :: Maybe Text
$sel:environmentId:TerminateEnvironment' :: TerminateEnvironment -> Maybe Text
environmentId} -> Maybe Text
environmentId) (\s :: TerminateEnvironment
s@TerminateEnvironment' {} Maybe Text
a -> TerminateEnvironment
s {$sel:environmentId:TerminateEnvironment' :: Maybe Text
environmentId = Maybe Text
a} :: TerminateEnvironment)

instance Core.AWSRequest TerminateEnvironment where
  type
    AWSResponse TerminateEnvironment =
      EnvironmentDescription
  request :: TerminateEnvironment -> Request TerminateEnvironment
request = Service -> TerminateEnvironment -> Request TerminateEnvironment
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy TerminateEnvironment
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse TerminateEnvironment)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse TerminateEnvironment))
-> Logger
-> Service
-> Proxy TerminateEnvironment
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse TerminateEnvironment)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"TerminateEnvironmentResult"
      (\Int
s ResponseHeaders
h [Node]
x -> [Node] -> Either String EnvironmentDescription
forall a. FromXML a => [Node] -> Either String a
Core.parseXML [Node]
x)

instance Prelude.Hashable TerminateEnvironment

instance Prelude.NFData TerminateEnvironment

instance Core.ToHeaders TerminateEnvironment where
  toHeaders :: TerminateEnvironment -> ResponseHeaders
toHeaders = ResponseHeaders -> TerminateEnvironment -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToPath TerminateEnvironment where
  toPath :: TerminateEnvironment -> ByteString
toPath = ByteString -> TerminateEnvironment -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery TerminateEnvironment where
  toQuery :: TerminateEnvironment -> QueryString
toQuery TerminateEnvironment' {Maybe Bool
Maybe Text
environmentId :: Maybe Text
environmentName :: Maybe Text
terminateResources :: Maybe Bool
forceTerminate :: Maybe Bool
$sel:environmentId:TerminateEnvironment' :: TerminateEnvironment -> Maybe Text
$sel:environmentName:TerminateEnvironment' :: TerminateEnvironment -> Maybe Text
$sel:terminateResources:TerminateEnvironment' :: TerminateEnvironment -> Maybe Bool
$sel:forceTerminate:TerminateEnvironment' :: TerminateEnvironment -> Maybe Bool
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"TerminateEnvironment" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2010-12-01" :: Prelude.ByteString),
        ByteString
"ForceTerminate" ByteString -> Maybe Bool -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Bool
forceTerminate,
        ByteString
"TerminateResources" ByteString -> Maybe Bool -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Bool
terminateResources,
        ByteString
"EnvironmentName" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
environmentName,
        ByteString
"EnvironmentId" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
environmentId
      ]