{-# 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.Config.Types.OrganizationAggregationSource
-- 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.Config.Types.OrganizationAggregationSource where

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

-- | This object contains regions to set up the aggregator and an IAM role to
-- retrieve organization details.
--
-- /See:/ 'newOrganizationAggregationSource' smart constructor.
data OrganizationAggregationSource = OrganizationAggregationSource'
  { -- | The source regions being aggregated.
    OrganizationAggregationSource -> Maybe (NonEmpty Text)
awsRegions :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | If true, aggregate existing Config regions and future regions.
    OrganizationAggregationSource -> Maybe Bool
allAwsRegions :: Prelude.Maybe Prelude.Bool,
    -- | ARN of the IAM role used to retrieve Amazon Web Services Organization
    -- details associated with the aggregator account.
    OrganizationAggregationSource -> Text
roleArn :: Prelude.Text
  }
  deriving (OrganizationAggregationSource
-> OrganizationAggregationSource -> Bool
(OrganizationAggregationSource
 -> OrganizationAggregationSource -> Bool)
-> (OrganizationAggregationSource
    -> OrganizationAggregationSource -> Bool)
-> Eq OrganizationAggregationSource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OrganizationAggregationSource
-> OrganizationAggregationSource -> Bool
$c/= :: OrganizationAggregationSource
-> OrganizationAggregationSource -> Bool
== :: OrganizationAggregationSource
-> OrganizationAggregationSource -> Bool
$c== :: OrganizationAggregationSource
-> OrganizationAggregationSource -> Bool
Prelude.Eq, ReadPrec [OrganizationAggregationSource]
ReadPrec OrganizationAggregationSource
Int -> ReadS OrganizationAggregationSource
ReadS [OrganizationAggregationSource]
(Int -> ReadS OrganizationAggregationSource)
-> ReadS [OrganizationAggregationSource]
-> ReadPrec OrganizationAggregationSource
-> ReadPrec [OrganizationAggregationSource]
-> Read OrganizationAggregationSource
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OrganizationAggregationSource]
$creadListPrec :: ReadPrec [OrganizationAggregationSource]
readPrec :: ReadPrec OrganizationAggregationSource
$creadPrec :: ReadPrec OrganizationAggregationSource
readList :: ReadS [OrganizationAggregationSource]
$creadList :: ReadS [OrganizationAggregationSource]
readsPrec :: Int -> ReadS OrganizationAggregationSource
$creadsPrec :: Int -> ReadS OrganizationAggregationSource
Prelude.Read, Int -> OrganizationAggregationSource -> ShowS
[OrganizationAggregationSource] -> ShowS
OrganizationAggregationSource -> String
(Int -> OrganizationAggregationSource -> ShowS)
-> (OrganizationAggregationSource -> String)
-> ([OrganizationAggregationSource] -> ShowS)
-> Show OrganizationAggregationSource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OrganizationAggregationSource] -> ShowS
$cshowList :: [OrganizationAggregationSource] -> ShowS
show :: OrganizationAggregationSource -> String
$cshow :: OrganizationAggregationSource -> String
showsPrec :: Int -> OrganizationAggregationSource -> ShowS
$cshowsPrec :: Int -> OrganizationAggregationSource -> ShowS
Prelude.Show, (forall x.
 OrganizationAggregationSource
 -> Rep OrganizationAggregationSource x)
-> (forall x.
    Rep OrganizationAggregationSource x
    -> OrganizationAggregationSource)
-> Generic OrganizationAggregationSource
forall x.
Rep OrganizationAggregationSource x
-> OrganizationAggregationSource
forall x.
OrganizationAggregationSource
-> Rep OrganizationAggregationSource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep OrganizationAggregationSource x
-> OrganizationAggregationSource
$cfrom :: forall x.
OrganizationAggregationSource
-> Rep OrganizationAggregationSource x
Prelude.Generic)

-- |
-- Create a value of 'OrganizationAggregationSource' 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:
--
-- 'awsRegions', 'organizationAggregationSource_awsRegions' - The source regions being aggregated.
--
-- 'allAwsRegions', 'organizationAggregationSource_allAwsRegions' - If true, aggregate existing Config regions and future regions.
--
-- 'roleArn', 'organizationAggregationSource_roleArn' - ARN of the IAM role used to retrieve Amazon Web Services Organization
-- details associated with the aggregator account.
newOrganizationAggregationSource ::
  -- | 'roleArn'
  Prelude.Text ->
  OrganizationAggregationSource
newOrganizationAggregationSource :: Text -> OrganizationAggregationSource
newOrganizationAggregationSource Text
pRoleArn_ =
  OrganizationAggregationSource' :: Maybe (NonEmpty Text)
-> Maybe Bool -> Text -> OrganizationAggregationSource
OrganizationAggregationSource'
    { $sel:awsRegions:OrganizationAggregationSource' :: Maybe (NonEmpty Text)
awsRegions =
        Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:allAwsRegions:OrganizationAggregationSource' :: Maybe Bool
allAwsRegions = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:roleArn:OrganizationAggregationSource' :: Text
roleArn = Text
pRoleArn_
    }

-- | The source regions being aggregated.
organizationAggregationSource_awsRegions :: Lens.Lens' OrganizationAggregationSource (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
organizationAggregationSource_awsRegions :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> OrganizationAggregationSource -> f OrganizationAggregationSource
organizationAggregationSource_awsRegions = (OrganizationAggregationSource -> Maybe (NonEmpty Text))
-> (OrganizationAggregationSource
    -> Maybe (NonEmpty Text) -> OrganizationAggregationSource)
-> Lens
     OrganizationAggregationSource
     OrganizationAggregationSource
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OrganizationAggregationSource' {Maybe (NonEmpty Text)
awsRegions :: Maybe (NonEmpty Text)
$sel:awsRegions:OrganizationAggregationSource' :: OrganizationAggregationSource -> Maybe (NonEmpty Text)
awsRegions} -> Maybe (NonEmpty Text)
awsRegions) (\s :: OrganizationAggregationSource
s@OrganizationAggregationSource' {} Maybe (NonEmpty Text)
a -> OrganizationAggregationSource
s {$sel:awsRegions:OrganizationAggregationSource' :: Maybe (NonEmpty Text)
awsRegions = Maybe (NonEmpty Text)
a} :: OrganizationAggregationSource) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> OrganizationAggregationSource
 -> f OrganizationAggregationSource)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> OrganizationAggregationSource
-> f OrganizationAggregationSource
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
-> Iso
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
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 AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | If true, aggregate existing Config regions and future regions.
organizationAggregationSource_allAwsRegions :: Lens.Lens' OrganizationAggregationSource (Prelude.Maybe Prelude.Bool)
organizationAggregationSource_allAwsRegions :: (Maybe Bool -> f (Maybe Bool))
-> OrganizationAggregationSource -> f OrganizationAggregationSource
organizationAggregationSource_allAwsRegions = (OrganizationAggregationSource -> Maybe Bool)
-> (OrganizationAggregationSource
    -> Maybe Bool -> OrganizationAggregationSource)
-> Lens
     OrganizationAggregationSource
     OrganizationAggregationSource
     (Maybe Bool)
     (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OrganizationAggregationSource' {Maybe Bool
allAwsRegions :: Maybe Bool
$sel:allAwsRegions:OrganizationAggregationSource' :: OrganizationAggregationSource -> Maybe Bool
allAwsRegions} -> Maybe Bool
allAwsRegions) (\s :: OrganizationAggregationSource
s@OrganizationAggregationSource' {} Maybe Bool
a -> OrganizationAggregationSource
s {$sel:allAwsRegions:OrganizationAggregationSource' :: Maybe Bool
allAwsRegions = Maybe Bool
a} :: OrganizationAggregationSource)

-- | ARN of the IAM role used to retrieve Amazon Web Services Organization
-- details associated with the aggregator account.
organizationAggregationSource_roleArn :: Lens.Lens' OrganizationAggregationSource Prelude.Text
organizationAggregationSource_roleArn :: (Text -> f Text)
-> OrganizationAggregationSource -> f OrganizationAggregationSource
organizationAggregationSource_roleArn = (OrganizationAggregationSource -> Text)
-> (OrganizationAggregationSource
    -> Text -> OrganizationAggregationSource)
-> Lens
     OrganizationAggregationSource
     OrganizationAggregationSource
     Text
     Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OrganizationAggregationSource' {Text
roleArn :: Text
$sel:roleArn:OrganizationAggregationSource' :: OrganizationAggregationSource -> Text
roleArn} -> Text
roleArn) (\s :: OrganizationAggregationSource
s@OrganizationAggregationSource' {} Text
a -> OrganizationAggregationSource
s {$sel:roleArn:OrganizationAggregationSource' :: Text
roleArn = Text
a} :: OrganizationAggregationSource)

instance Core.FromJSON OrganizationAggregationSource where
  parseJSON :: Value -> Parser OrganizationAggregationSource
parseJSON =
    String
-> (Object -> Parser OrganizationAggregationSource)
-> Value
-> Parser OrganizationAggregationSource
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"OrganizationAggregationSource"
      ( \Object
x ->
          Maybe (NonEmpty Text)
-> Maybe Bool -> Text -> OrganizationAggregationSource
OrganizationAggregationSource'
            (Maybe (NonEmpty Text)
 -> Maybe Bool -> Text -> OrganizationAggregationSource)
-> Parser (Maybe (NonEmpty Text))
-> Parser (Maybe Bool -> Text -> OrganizationAggregationSource)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (NonEmpty Text))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"AwsRegions")
            Parser (Maybe Bool -> Text -> OrganizationAggregationSource)
-> Parser (Maybe Bool)
-> Parser (Text -> OrganizationAggregationSource)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"AllAwsRegions")
            Parser (Text -> OrganizationAggregationSource)
-> Parser Text -> Parser OrganizationAggregationSource
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"RoleArn")
      )

instance
  Prelude.Hashable
    OrganizationAggregationSource

instance Prelude.NFData OrganizationAggregationSource

instance Core.ToJSON OrganizationAggregationSource where
  toJSON :: OrganizationAggregationSource -> Value
toJSON OrganizationAggregationSource' {Maybe Bool
Maybe (NonEmpty Text)
Text
roleArn :: Text
allAwsRegions :: Maybe Bool
awsRegions :: Maybe (NonEmpty Text)
$sel:roleArn:OrganizationAggregationSource' :: OrganizationAggregationSource -> Text
$sel:allAwsRegions:OrganizationAggregationSource' :: OrganizationAggregationSource -> Maybe Bool
$sel:awsRegions:OrganizationAggregationSource' :: OrganizationAggregationSource -> Maybe (NonEmpty Text)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"AwsRegions" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (NonEmpty Text -> Pair) -> Maybe (NonEmpty Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Text)
awsRegions,
            (Text
"AllAwsRegions" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
allAwsRegions,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"RoleArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
roleArn)
          ]
      )