{-# 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.CloudFormation.Types.AutoDeployment
-- 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)
module Amazonka.CloudFormation.Types.AutoDeployment where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | [Service-managed permissions] Describes whether StackSets automatically
-- deploys to Organizations accounts that are added to a target
-- organization or organizational unit (OU).
--
-- /See:/ 'newAutoDeployment' smart constructor.
data AutoDeployment = AutoDeployment'
  { -- | If set to @true@, StackSets automatically deploys additional stack
    -- instances to Organizations accounts that are added to a target
    -- organization or organizational unit (OU) in the specified Regions. If an
    -- account is removed from a target organization or OU, StackSets deletes
    -- stack instances from the account in the specified Regions.
    AutoDeployment -> Maybe Bool
enabled :: Prelude.Maybe Prelude.Bool,
    -- | If set to @true@, stack resources are retained when an account is
    -- removed from a target organization or OU. If set to @false@, stack
    -- resources are deleted. Specify only if @Enabled@ is set to @True@.
    AutoDeployment -> Maybe Bool
retainStacksOnAccountRemoval :: Prelude.Maybe Prelude.Bool
  }
  deriving (AutoDeployment -> AutoDeployment -> Bool
(AutoDeployment -> AutoDeployment -> Bool)
-> (AutoDeployment -> AutoDeployment -> Bool) -> Eq AutoDeployment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AutoDeployment -> AutoDeployment -> Bool
$c/= :: AutoDeployment -> AutoDeployment -> Bool
== :: AutoDeployment -> AutoDeployment -> Bool
$c== :: AutoDeployment -> AutoDeployment -> Bool
Prelude.Eq, ReadPrec [AutoDeployment]
ReadPrec AutoDeployment
Int -> ReadS AutoDeployment
ReadS [AutoDeployment]
(Int -> ReadS AutoDeployment)
-> ReadS [AutoDeployment]
-> ReadPrec AutoDeployment
-> ReadPrec [AutoDeployment]
-> Read AutoDeployment
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AutoDeployment]
$creadListPrec :: ReadPrec [AutoDeployment]
readPrec :: ReadPrec AutoDeployment
$creadPrec :: ReadPrec AutoDeployment
readList :: ReadS [AutoDeployment]
$creadList :: ReadS [AutoDeployment]
readsPrec :: Int -> ReadS AutoDeployment
$creadsPrec :: Int -> ReadS AutoDeployment
Prelude.Read, Int -> AutoDeployment -> ShowS
[AutoDeployment] -> ShowS
AutoDeployment -> String
(Int -> AutoDeployment -> ShowS)
-> (AutoDeployment -> String)
-> ([AutoDeployment] -> ShowS)
-> Show AutoDeployment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AutoDeployment] -> ShowS
$cshowList :: [AutoDeployment] -> ShowS
show :: AutoDeployment -> String
$cshow :: AutoDeployment -> String
showsPrec :: Int -> AutoDeployment -> ShowS
$cshowsPrec :: Int -> AutoDeployment -> ShowS
Prelude.Show, (forall x. AutoDeployment -> Rep AutoDeployment x)
-> (forall x. Rep AutoDeployment x -> AutoDeployment)
-> Generic AutoDeployment
forall x. Rep AutoDeployment x -> AutoDeployment
forall x. AutoDeployment -> Rep AutoDeployment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AutoDeployment x -> AutoDeployment
$cfrom :: forall x. AutoDeployment -> Rep AutoDeployment x
Prelude.Generic)

-- |
-- Create a value of 'AutoDeployment' 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:
--
-- 'enabled', 'autoDeployment_enabled' - If set to @true@, StackSets automatically deploys additional stack
-- instances to Organizations accounts that are added to a target
-- organization or organizational unit (OU) in the specified Regions. If an
-- account is removed from a target organization or OU, StackSets deletes
-- stack instances from the account in the specified Regions.
--
-- 'retainStacksOnAccountRemoval', 'autoDeployment_retainStacksOnAccountRemoval' - If set to @true@, stack resources are retained when an account is
-- removed from a target organization or OU. If set to @false@, stack
-- resources are deleted. Specify only if @Enabled@ is set to @True@.
newAutoDeployment ::
  AutoDeployment
newAutoDeployment :: AutoDeployment
newAutoDeployment =
  AutoDeployment' :: Maybe Bool -> Maybe Bool -> AutoDeployment
AutoDeployment'
    { $sel:enabled:AutoDeployment' :: Maybe Bool
enabled = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:retainStacksOnAccountRemoval:AutoDeployment' :: Maybe Bool
retainStacksOnAccountRemoval = Maybe Bool
forall a. Maybe a
Prelude.Nothing
    }

-- | If set to @true@, StackSets automatically deploys additional stack
-- instances to Organizations accounts that are added to a target
-- organization or organizational unit (OU) in the specified Regions. If an
-- account is removed from a target organization or OU, StackSets deletes
-- stack instances from the account in the specified Regions.
autoDeployment_enabled :: Lens.Lens' AutoDeployment (Prelude.Maybe Prelude.Bool)
autoDeployment_enabled :: (Maybe Bool -> f (Maybe Bool))
-> AutoDeployment -> f AutoDeployment
autoDeployment_enabled = (AutoDeployment -> Maybe Bool)
-> (AutoDeployment -> Maybe Bool -> AutoDeployment)
-> Lens AutoDeployment AutoDeployment (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AutoDeployment' {Maybe Bool
enabled :: Maybe Bool
$sel:enabled:AutoDeployment' :: AutoDeployment -> Maybe Bool
enabled} -> Maybe Bool
enabled) (\s :: AutoDeployment
s@AutoDeployment' {} Maybe Bool
a -> AutoDeployment
s {$sel:enabled:AutoDeployment' :: Maybe Bool
enabled = Maybe Bool
a} :: AutoDeployment)

-- | If set to @true@, stack resources are retained when an account is
-- removed from a target organization or OU. If set to @false@, stack
-- resources are deleted. Specify only if @Enabled@ is set to @True@.
autoDeployment_retainStacksOnAccountRemoval :: Lens.Lens' AutoDeployment (Prelude.Maybe Prelude.Bool)
autoDeployment_retainStacksOnAccountRemoval :: (Maybe Bool -> f (Maybe Bool))
-> AutoDeployment -> f AutoDeployment
autoDeployment_retainStacksOnAccountRemoval = (AutoDeployment -> Maybe Bool)
-> (AutoDeployment -> Maybe Bool -> AutoDeployment)
-> Lens AutoDeployment AutoDeployment (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AutoDeployment' {Maybe Bool
retainStacksOnAccountRemoval :: Maybe Bool
$sel:retainStacksOnAccountRemoval:AutoDeployment' :: AutoDeployment -> Maybe Bool
retainStacksOnAccountRemoval} -> Maybe Bool
retainStacksOnAccountRemoval) (\s :: AutoDeployment
s@AutoDeployment' {} Maybe Bool
a -> AutoDeployment
s {$sel:retainStacksOnAccountRemoval:AutoDeployment' :: Maybe Bool
retainStacksOnAccountRemoval = Maybe Bool
a} :: AutoDeployment)

instance Core.FromXML AutoDeployment where
  parseXML :: [Node] -> Either String AutoDeployment
parseXML [Node]
x =
    Maybe Bool -> Maybe Bool -> AutoDeployment
AutoDeployment'
      (Maybe Bool -> Maybe Bool -> AutoDeployment)
-> Either String (Maybe Bool)
-> Either String (Maybe Bool -> AutoDeployment)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Bool)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Enabled")
      Either String (Maybe Bool -> AutoDeployment)
-> Either String (Maybe Bool) -> Either String AutoDeployment
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Bool)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"RetainStacksOnAccountRemoval")

instance Prelude.Hashable AutoDeployment

instance Prelude.NFData AutoDeployment

instance Core.ToQuery AutoDeployment where
  toQuery :: AutoDeployment -> QueryString
toQuery AutoDeployment' {Maybe Bool
retainStacksOnAccountRemoval :: Maybe Bool
enabled :: Maybe Bool
$sel:retainStacksOnAccountRemoval:AutoDeployment' :: AutoDeployment -> Maybe Bool
$sel:enabled:AutoDeployment' :: AutoDeployment -> Maybe Bool
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Enabled" ByteString -> Maybe Bool -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Bool
enabled,
        ByteString
"RetainStacksOnAccountRemoval"
          ByteString -> Maybe Bool -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Bool
retainStacksOnAccountRemoval
      ]