{-# 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.Scope
-- 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.Scope where

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

-- | Defines which resources trigger an evaluation for an Config rule. The
-- scope can include one or more resource types, a combination of a tag key
-- and value, or a combination of one resource type and one resource ID.
-- Specify a scope to constrain which resources trigger an evaluation for a
-- rule. Otherwise, evaluations for the rule are triggered when any
-- resource in your recording group changes in configuration.
--
-- /See:/ 'newScope' smart constructor.
data Scope = Scope'
  { -- | The resource types of only those Amazon Web Services resources that you
    -- want to trigger an evaluation for the rule. You can only specify one
    -- type if you also specify a resource ID for @ComplianceResourceId@.
    Scope -> Maybe [Text]
complianceResourceTypes :: Prelude.Maybe [Prelude.Text],
    -- | The ID of the only Amazon Web Services resource that you want to trigger
    -- an evaluation for the rule. If you specify a resource ID, you must
    -- specify one resource type for @ComplianceResourceTypes@.
    Scope -> Maybe Text
complianceResourceId :: Prelude.Maybe Prelude.Text,
    -- | The tag value applied to only those Amazon Web Services resources that
    -- you want to trigger an evaluation for the rule. If you specify a value
    -- for @TagValue@, you must also specify a value for @TagKey@.
    Scope -> Maybe Text
tagValue :: Prelude.Maybe Prelude.Text,
    -- | The tag key that is applied to only those Amazon Web Services resources
    -- that you want to trigger an evaluation for the rule.
    Scope -> Maybe Text
tagKey :: Prelude.Maybe Prelude.Text
  }
  deriving (Scope -> Scope -> Bool
(Scope -> Scope -> Bool) -> (Scope -> Scope -> Bool) -> Eq Scope
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Scope -> Scope -> Bool
$c/= :: Scope -> Scope -> Bool
== :: Scope -> Scope -> Bool
$c== :: Scope -> Scope -> Bool
Prelude.Eq, ReadPrec [Scope]
ReadPrec Scope
Int -> ReadS Scope
ReadS [Scope]
(Int -> ReadS Scope)
-> ReadS [Scope]
-> ReadPrec Scope
-> ReadPrec [Scope]
-> Read Scope
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Scope]
$creadListPrec :: ReadPrec [Scope]
readPrec :: ReadPrec Scope
$creadPrec :: ReadPrec Scope
readList :: ReadS [Scope]
$creadList :: ReadS [Scope]
readsPrec :: Int -> ReadS Scope
$creadsPrec :: Int -> ReadS Scope
Prelude.Read, Int -> Scope -> ShowS
[Scope] -> ShowS
Scope -> String
(Int -> Scope -> ShowS)
-> (Scope -> String) -> ([Scope] -> ShowS) -> Show Scope
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Scope] -> ShowS
$cshowList :: [Scope] -> ShowS
show :: Scope -> String
$cshow :: Scope -> String
showsPrec :: Int -> Scope -> ShowS
$cshowsPrec :: Int -> Scope -> ShowS
Prelude.Show, (forall x. Scope -> Rep Scope x)
-> (forall x. Rep Scope x -> Scope) -> Generic Scope
forall x. Rep Scope x -> Scope
forall x. Scope -> Rep Scope x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Scope x -> Scope
$cfrom :: forall x. Scope -> Rep Scope x
Prelude.Generic)

-- |
-- Create a value of 'Scope' 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:
--
-- 'complianceResourceTypes', 'scope_complianceResourceTypes' - The resource types of only those Amazon Web Services resources that you
-- want to trigger an evaluation for the rule. You can only specify one
-- type if you also specify a resource ID for @ComplianceResourceId@.
--
-- 'complianceResourceId', 'scope_complianceResourceId' - The ID of the only Amazon Web Services resource that you want to trigger
-- an evaluation for the rule. If you specify a resource ID, you must
-- specify one resource type for @ComplianceResourceTypes@.
--
-- 'tagValue', 'scope_tagValue' - The tag value applied to only those Amazon Web Services resources that
-- you want to trigger an evaluation for the rule. If you specify a value
-- for @TagValue@, you must also specify a value for @TagKey@.
--
-- 'tagKey', 'scope_tagKey' - The tag key that is applied to only those Amazon Web Services resources
-- that you want to trigger an evaluation for the rule.
newScope ::
  Scope
newScope :: Scope
newScope =
  Scope' :: Maybe [Text] -> Maybe Text -> Maybe Text -> Maybe Text -> Scope
Scope'
    { $sel:complianceResourceTypes:Scope' :: Maybe [Text]
complianceResourceTypes = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:complianceResourceId:Scope' :: Maybe Text
complianceResourceId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:tagValue:Scope' :: Maybe Text
tagValue = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:tagKey:Scope' :: Maybe Text
tagKey = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The resource types of only those Amazon Web Services resources that you
-- want to trigger an evaluation for the rule. You can only specify one
-- type if you also specify a resource ID for @ComplianceResourceId@.
scope_complianceResourceTypes :: Lens.Lens' Scope (Prelude.Maybe [Prelude.Text])
scope_complianceResourceTypes :: (Maybe [Text] -> f (Maybe [Text])) -> Scope -> f Scope
scope_complianceResourceTypes = (Scope -> Maybe [Text])
-> (Scope -> Maybe [Text] -> Scope)
-> Lens Scope Scope (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Scope' {Maybe [Text]
complianceResourceTypes :: Maybe [Text]
$sel:complianceResourceTypes:Scope' :: Scope -> Maybe [Text]
complianceResourceTypes} -> Maybe [Text]
complianceResourceTypes) (\s :: Scope
s@Scope' {} Maybe [Text]
a -> Scope
s {$sel:complianceResourceTypes:Scope' :: Maybe [Text]
complianceResourceTypes = Maybe [Text]
a} :: Scope) ((Maybe [Text] -> f (Maybe [Text])) -> Scope -> f Scope)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> Scope
-> f Scope
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [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 [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The ID of the only Amazon Web Services resource that you want to trigger
-- an evaluation for the rule. If you specify a resource ID, you must
-- specify one resource type for @ComplianceResourceTypes@.
scope_complianceResourceId :: Lens.Lens' Scope (Prelude.Maybe Prelude.Text)
scope_complianceResourceId :: (Maybe Text -> f (Maybe Text)) -> Scope -> f Scope
scope_complianceResourceId = (Scope -> Maybe Text)
-> (Scope -> Maybe Text -> Scope)
-> Lens Scope Scope (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Scope' {Maybe Text
complianceResourceId :: Maybe Text
$sel:complianceResourceId:Scope' :: Scope -> Maybe Text
complianceResourceId} -> Maybe Text
complianceResourceId) (\s :: Scope
s@Scope' {} Maybe Text
a -> Scope
s {$sel:complianceResourceId:Scope' :: Maybe Text
complianceResourceId = Maybe Text
a} :: Scope)

-- | The tag value applied to only those Amazon Web Services resources that
-- you want to trigger an evaluation for the rule. If you specify a value
-- for @TagValue@, you must also specify a value for @TagKey@.
scope_tagValue :: Lens.Lens' Scope (Prelude.Maybe Prelude.Text)
scope_tagValue :: (Maybe Text -> f (Maybe Text)) -> Scope -> f Scope
scope_tagValue = (Scope -> Maybe Text)
-> (Scope -> Maybe Text -> Scope)
-> Lens Scope Scope (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Scope' {Maybe Text
tagValue :: Maybe Text
$sel:tagValue:Scope' :: Scope -> Maybe Text
tagValue} -> Maybe Text
tagValue) (\s :: Scope
s@Scope' {} Maybe Text
a -> Scope
s {$sel:tagValue:Scope' :: Maybe Text
tagValue = Maybe Text
a} :: Scope)

-- | The tag key that is applied to only those Amazon Web Services resources
-- that you want to trigger an evaluation for the rule.
scope_tagKey :: Lens.Lens' Scope (Prelude.Maybe Prelude.Text)
scope_tagKey :: (Maybe Text -> f (Maybe Text)) -> Scope -> f Scope
scope_tagKey = (Scope -> Maybe Text)
-> (Scope -> Maybe Text -> Scope)
-> Lens Scope Scope (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Scope' {Maybe Text
tagKey :: Maybe Text
$sel:tagKey:Scope' :: Scope -> Maybe Text
tagKey} -> Maybe Text
tagKey) (\s :: Scope
s@Scope' {} Maybe Text
a -> Scope
s {$sel:tagKey:Scope' :: Maybe Text
tagKey = Maybe Text
a} :: Scope)

instance Core.FromJSON Scope where
  parseJSON :: Value -> Parser Scope
parseJSON =
    String -> (Object -> Parser Scope) -> Value -> Parser Scope
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Scope"
      ( \Object
x ->
          Maybe [Text] -> Maybe Text -> Maybe Text -> Maybe Text -> Scope
Scope'
            (Maybe [Text] -> Maybe Text -> Maybe Text -> Maybe Text -> Scope)
-> Parser (Maybe [Text])
-> Parser (Maybe Text -> Maybe Text -> Maybe Text -> Scope)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ComplianceResourceTypes"
                            Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser (Maybe Text -> Maybe Text -> Maybe Text -> Scope)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe Text -> Scope)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ComplianceResourceId")
            Parser (Maybe Text -> Maybe Text -> Scope)
-> Parser (Maybe Text) -> Parser (Maybe Text -> Scope)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"TagValue")
            Parser (Maybe Text -> Scope) -> Parser (Maybe Text) -> Parser Scope
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"TagKey")
      )

instance Prelude.Hashable Scope

instance Prelude.NFData Scope

instance Core.ToJSON Scope where
  toJSON :: Scope -> Value
toJSON Scope' {Maybe [Text]
Maybe Text
tagKey :: Maybe Text
tagValue :: Maybe Text
complianceResourceId :: Maybe Text
complianceResourceTypes :: Maybe [Text]
$sel:tagKey:Scope' :: Scope -> Maybe Text
$sel:tagValue:Scope' :: Scope -> Maybe Text
$sel:complianceResourceId:Scope' :: Scope -> Maybe Text
$sel:complianceResourceTypes:Scope' :: Scope -> Maybe [Text]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ComplianceResourceTypes" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              ([Text] -> Pair) -> Maybe [Text] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
complianceResourceTypes,
            (Text
"ComplianceResourceId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
complianceResourceId,
            (Text
"TagValue" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
tagValue,
            (Text
"TagKey" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
tagKey
          ]
      )