{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Config.Types.Scope where

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

-- | 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 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 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 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,
    -- | 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
  }
  deriving (Scope -> Scope -> Bool
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]
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
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. 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:
--
-- '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@.
--
-- '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@.
--
-- '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.
--
-- '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@.
newScope ::
  Scope
newScope :: Scope
newScope =
  Scope'
    { $sel:complianceResourceId:Scope' :: Maybe Text
complianceResourceId = forall a. Maybe a
Prelude.Nothing,
      $sel:complianceResourceTypes:Scope' :: Maybe [Text]
complianceResourceTypes = forall a. Maybe a
Prelude.Nothing,
      $sel:tagKey:Scope' :: Maybe Text
tagKey = forall a. Maybe a
Prelude.Nothing,
      $sel:tagValue:Scope' :: Maybe Text
tagValue = forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: Lens' Scope (Maybe Text)
scope_complianceResourceId = 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 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 :: Lens' Scope (Maybe [Text])
scope_complianceResourceTypes = 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) 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

-- | 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 :: Lens' Scope (Maybe Text)
scope_tagKey = 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)

-- | 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 :: Lens' Scope (Maybe Text)
scope_tagValue = 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)

instance Data.FromJSON Scope where
  parseJSON :: Value -> Parser Scope
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Scope"
      ( \Object
x ->
          Maybe Text -> Maybe [Text] -> Maybe Text -> Maybe Text -> Scope
Scope'
            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
"ComplianceResourceId")
            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
"ComplianceResourceTypes"
                            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
"TagKey")
            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
"TagValue")
      )

instance Prelude.Hashable Scope where
  hashWithSalt :: Int -> Scope -> Int
hashWithSalt Int
_salt Scope' {Maybe [Text]
Maybe Text
tagValue :: Maybe Text
tagKey :: Maybe Text
complianceResourceTypes :: Maybe [Text]
complianceResourceId :: Maybe Text
$sel:tagValue:Scope' :: Scope -> Maybe Text
$sel:tagKey:Scope' :: Scope -> Maybe Text
$sel:complianceResourceTypes:Scope' :: Scope -> Maybe [Text]
$sel:complianceResourceId:Scope' :: Scope -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
complianceResourceId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
complianceResourceTypes
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
tagKey
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
tagValue

instance Prelude.NFData Scope where
  rnf :: Scope -> ()
rnf Scope' {Maybe [Text]
Maybe Text
tagValue :: Maybe Text
tagKey :: Maybe Text
complianceResourceTypes :: Maybe [Text]
complianceResourceId :: Maybe Text
$sel:tagValue:Scope' :: Scope -> Maybe Text
$sel:tagKey:Scope' :: Scope -> Maybe Text
$sel:complianceResourceTypes:Scope' :: Scope -> Maybe [Text]
$sel:complianceResourceId:Scope' :: Scope -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
complianceResourceId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
complianceResourceTypes
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
tagKey
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
tagValue

instance Data.ToJSON Scope where
  toJSON :: Scope -> Value
toJSON Scope' {Maybe [Text]
Maybe Text
tagValue :: Maybe Text
tagKey :: Maybe Text
complianceResourceTypes :: Maybe [Text]
complianceResourceId :: Maybe Text
$sel:tagValue:Scope' :: Scope -> Maybe Text
$sel:tagKey:Scope' :: Scope -> Maybe Text
$sel:complianceResourceTypes:Scope' :: Scope -> Maybe [Text]
$sel:complianceResourceId:Scope' :: Scope -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"ComplianceResourceId" 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
complianceResourceId,
            (Key
"ComplianceResourceTypes" 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]
complianceResourceTypes,
            (Key
"TagKey" 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
tagKey,
            (Key
"TagValue" 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
tagValue
          ]
      )