{-# 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.CodeDeploy.Types.TargetInstances
-- 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.CodeDeploy.Types.TargetInstances where

import Amazonka.CodeDeploy.Types.EC2TagFilter
import Amazonka.CodeDeploy.Types.EC2TagSet
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | Information about the instances to be used in the replacement
-- environment in a blue\/green deployment.
--
-- /See:/ 'newTargetInstances' smart constructor.
data TargetInstances = TargetInstances'
  { -- | The names of one or more Auto Scaling groups to identify a replacement
    -- environment for a blue\/green deployment.
    TargetInstances -> Maybe [Text]
autoScalingGroups :: Prelude.Maybe [Prelude.Text],
    -- | Information about the groups of Amazon EC2 instance tags that an
    -- instance must be identified by in order for it to be included in the
    -- replacement environment for a blue\/green deployment. Cannot be used in
    -- the same call as @tagFilters@.
    TargetInstances -> Maybe EC2TagSet
ec2TagSet :: Prelude.Maybe EC2TagSet,
    -- | The tag filter key, type, and value used to identify Amazon EC2
    -- instances in a replacement environment for a blue\/green deployment.
    -- Cannot be used in the same call as @ec2TagSet@.
    TargetInstances -> Maybe [EC2TagFilter]
tagFilters :: Prelude.Maybe [EC2TagFilter]
  }
  deriving (TargetInstances -> TargetInstances -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TargetInstances -> TargetInstances -> Bool
$c/= :: TargetInstances -> TargetInstances -> Bool
== :: TargetInstances -> TargetInstances -> Bool
$c== :: TargetInstances -> TargetInstances -> Bool
Prelude.Eq, ReadPrec [TargetInstances]
ReadPrec TargetInstances
Int -> ReadS TargetInstances
ReadS [TargetInstances]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TargetInstances]
$creadListPrec :: ReadPrec [TargetInstances]
readPrec :: ReadPrec TargetInstances
$creadPrec :: ReadPrec TargetInstances
readList :: ReadS [TargetInstances]
$creadList :: ReadS [TargetInstances]
readsPrec :: Int -> ReadS TargetInstances
$creadsPrec :: Int -> ReadS TargetInstances
Prelude.Read, Int -> TargetInstances -> ShowS
[TargetInstances] -> ShowS
TargetInstances -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TargetInstances] -> ShowS
$cshowList :: [TargetInstances] -> ShowS
show :: TargetInstances -> String
$cshow :: TargetInstances -> String
showsPrec :: Int -> TargetInstances -> ShowS
$cshowsPrec :: Int -> TargetInstances -> ShowS
Prelude.Show, forall x. Rep TargetInstances x -> TargetInstances
forall x. TargetInstances -> Rep TargetInstances x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TargetInstances x -> TargetInstances
$cfrom :: forall x. TargetInstances -> Rep TargetInstances x
Prelude.Generic)

-- |
-- Create a value of 'TargetInstances' 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:
--
-- 'autoScalingGroups', 'targetInstances_autoScalingGroups' - The names of one or more Auto Scaling groups to identify a replacement
-- environment for a blue\/green deployment.
--
-- 'ec2TagSet', 'targetInstances_ec2TagSet' - Information about the groups of Amazon EC2 instance tags that an
-- instance must be identified by in order for it to be included in the
-- replacement environment for a blue\/green deployment. Cannot be used in
-- the same call as @tagFilters@.
--
-- 'tagFilters', 'targetInstances_tagFilters' - The tag filter key, type, and value used to identify Amazon EC2
-- instances in a replacement environment for a blue\/green deployment.
-- Cannot be used in the same call as @ec2TagSet@.
newTargetInstances ::
  TargetInstances
newTargetInstances :: TargetInstances
newTargetInstances =
  TargetInstances'
    { $sel:autoScalingGroups:TargetInstances' :: Maybe [Text]
autoScalingGroups =
        forall a. Maybe a
Prelude.Nothing,
      $sel:ec2TagSet:TargetInstances' :: Maybe EC2TagSet
ec2TagSet = forall a. Maybe a
Prelude.Nothing,
      $sel:tagFilters:TargetInstances' :: Maybe [EC2TagFilter]
tagFilters = forall a. Maybe a
Prelude.Nothing
    }

-- | The names of one or more Auto Scaling groups to identify a replacement
-- environment for a blue\/green deployment.
targetInstances_autoScalingGroups :: Lens.Lens' TargetInstances (Prelude.Maybe [Prelude.Text])
targetInstances_autoScalingGroups :: Lens' TargetInstances (Maybe [Text])
targetInstances_autoScalingGroups = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TargetInstances' {Maybe [Text]
autoScalingGroups :: Maybe [Text]
$sel:autoScalingGroups:TargetInstances' :: TargetInstances -> Maybe [Text]
autoScalingGroups} -> Maybe [Text]
autoScalingGroups) (\s :: TargetInstances
s@TargetInstances' {} Maybe [Text]
a -> TargetInstances
s {$sel:autoScalingGroups:TargetInstances' :: Maybe [Text]
autoScalingGroups = Maybe [Text]
a} :: TargetInstances) 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

-- | Information about the groups of Amazon EC2 instance tags that an
-- instance must be identified by in order for it to be included in the
-- replacement environment for a blue\/green deployment. Cannot be used in
-- the same call as @tagFilters@.
targetInstances_ec2TagSet :: Lens.Lens' TargetInstances (Prelude.Maybe EC2TagSet)
targetInstances_ec2TagSet :: Lens' TargetInstances (Maybe EC2TagSet)
targetInstances_ec2TagSet = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TargetInstances' {Maybe EC2TagSet
ec2TagSet :: Maybe EC2TagSet
$sel:ec2TagSet:TargetInstances' :: TargetInstances -> Maybe EC2TagSet
ec2TagSet} -> Maybe EC2TagSet
ec2TagSet) (\s :: TargetInstances
s@TargetInstances' {} Maybe EC2TagSet
a -> TargetInstances
s {$sel:ec2TagSet:TargetInstances' :: Maybe EC2TagSet
ec2TagSet = Maybe EC2TagSet
a} :: TargetInstances)

-- | The tag filter key, type, and value used to identify Amazon EC2
-- instances in a replacement environment for a blue\/green deployment.
-- Cannot be used in the same call as @ec2TagSet@.
targetInstances_tagFilters :: Lens.Lens' TargetInstances (Prelude.Maybe [EC2TagFilter])
targetInstances_tagFilters :: Lens' TargetInstances (Maybe [EC2TagFilter])
targetInstances_tagFilters = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TargetInstances' {Maybe [EC2TagFilter]
tagFilters :: Maybe [EC2TagFilter]
$sel:tagFilters:TargetInstances' :: TargetInstances -> Maybe [EC2TagFilter]
tagFilters} -> Maybe [EC2TagFilter]
tagFilters) (\s :: TargetInstances
s@TargetInstances' {} Maybe [EC2TagFilter]
a -> TargetInstances
s {$sel:tagFilters:TargetInstances' :: Maybe [EC2TagFilter]
tagFilters = Maybe [EC2TagFilter]
a} :: TargetInstances) 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

instance Data.FromJSON TargetInstances where
  parseJSON :: Value -> Parser TargetInstances
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"TargetInstances"
      ( \Object
x ->
          Maybe [Text]
-> Maybe EC2TagSet -> Maybe [EC2TagFilter] -> TargetInstances
TargetInstances'
            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
"autoScalingGroups"
                            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 (Maybe a)
Data..:? Key
"ec2TagSet")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"tagFilters" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable TargetInstances where
  hashWithSalt :: Int -> TargetInstances -> Int
hashWithSalt Int
_salt TargetInstances' {Maybe [Text]
Maybe [EC2TagFilter]
Maybe EC2TagSet
tagFilters :: Maybe [EC2TagFilter]
ec2TagSet :: Maybe EC2TagSet
autoScalingGroups :: Maybe [Text]
$sel:tagFilters:TargetInstances' :: TargetInstances -> Maybe [EC2TagFilter]
$sel:ec2TagSet:TargetInstances' :: TargetInstances -> Maybe EC2TagSet
$sel:autoScalingGroups:TargetInstances' :: TargetInstances -> Maybe [Text]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
autoScalingGroups
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe EC2TagSet
ec2TagSet
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [EC2TagFilter]
tagFilters

instance Prelude.NFData TargetInstances where
  rnf :: TargetInstances -> ()
rnf TargetInstances' {Maybe [Text]
Maybe [EC2TagFilter]
Maybe EC2TagSet
tagFilters :: Maybe [EC2TagFilter]
ec2TagSet :: Maybe EC2TagSet
autoScalingGroups :: Maybe [Text]
$sel:tagFilters:TargetInstances' :: TargetInstances -> Maybe [EC2TagFilter]
$sel:ec2TagSet:TargetInstances' :: TargetInstances -> Maybe EC2TagSet
$sel:autoScalingGroups:TargetInstances' :: TargetInstances -> Maybe [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
autoScalingGroups
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe EC2TagSet
ec2TagSet
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [EC2TagFilter]
tagFilters

instance Data.ToJSON TargetInstances where
  toJSON :: TargetInstances -> Value
toJSON TargetInstances' {Maybe [Text]
Maybe [EC2TagFilter]
Maybe EC2TagSet
tagFilters :: Maybe [EC2TagFilter]
ec2TagSet :: Maybe EC2TagSet
autoScalingGroups :: Maybe [Text]
$sel:tagFilters:TargetInstances' :: TargetInstances -> Maybe [EC2TagFilter]
$sel:ec2TagSet:TargetInstances' :: TargetInstances -> Maybe EC2TagSet
$sel:autoScalingGroups:TargetInstances' :: TargetInstances -> Maybe [Text]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"autoScalingGroups" 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 [Text]
autoScalingGroups,
            (Key
"ec2TagSet" 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 EC2TagSet
ec2TagSet,
            (Key
"tagFilters" 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 [EC2TagFilter]
tagFilters
          ]
      )