{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.PutConfigRule
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Adds or updates an Config rule to evaluate if your Amazon Web Services
-- resources comply with your desired configurations. For information on
-- how many Config rules you can have per account, see
-- <https://docs.aws.amazon.com/config/latest/developerguide/configlimits.html Service Limits>
-- in the /Config Developer Guide/.
--
-- There are two types of rules: Config Custom Rules and Config Managed
-- Rules. You can use @PutConfigRule@ to create both Config custom rules
-- and Config managed rules.
--
-- Custom rules are rules that you can create using either Guard or Lambda
-- functions. Guard
-- (<https://github.com/aws-cloudformation/cloudformation-guard Guard GitHub Repository>)
-- is a policy-as-code language that allows you to write policies that are
-- enforced by Config Custom Policy rules. Lambda uses custom code that you
-- upload to evaluate a custom rule. If you are adding a new Custom Lambda
-- rule, you first need to create an Lambda function that the rule invokes
-- to evaluate your resources. When you use @PutConfigRule@ to add a Custom
-- Lambda rule to Config, you must specify the Amazon Resource Name (ARN)
-- that Lambda assigns to the function. You specify the ARN in the
-- @SourceIdentifier@ key. This key is part of the @Source@ object, which
-- is part of the @ConfigRule@ object.
--
-- Managed rules are predefined, customizable rules created by Config. For
-- a list of managed rules, see
-- <https://docs.aws.amazon.com/config/latest/developerguide/managed-rules-by-aws-config.html List of Config Managed Rules>.
-- If you are adding an Config managed rule, you must specify the rule\'s
-- identifier for the @SourceIdentifier@ key.
--
-- For any new rule that you add, specify the @ConfigRuleName@ in the
-- @ConfigRule@ object. Do not specify the @ConfigRuleArn@ or the
-- @ConfigRuleId@. These values are generated by Config for new rules.
--
-- If you are updating a rule that you added previously, you can specify
-- the rule by @ConfigRuleName@, @ConfigRuleId@, or @ConfigRuleArn@ in the
-- @ConfigRule@ data type that you use in this request.
--
-- For more information about developing and using Config rules, see
-- <https://docs.aws.amazon.com/config/latest/developerguide/evaluate-config.html Evaluating Amazon Web Services resource Configurations with Config>
-- in the /Config Developer Guide/.
module Amazonka.Config.PutConfigRule
  ( -- * Creating a Request
    PutConfigRule (..),
    newPutConfigRule,

    -- * Request Lenses
    putConfigRule_tags,
    putConfigRule_configRule,

    -- * Destructuring the Response
    PutConfigRuleResponse (..),
    newPutConfigRuleResponse,
  )
where

import Amazonka.Config.Types
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
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newPutConfigRule' smart constructor.
data PutConfigRule = PutConfigRule'
  { -- | An array of tag object.
    PutConfigRule -> Maybe [Tag]
tags :: Prelude.Maybe [Tag],
    -- | The rule that you want to add to your account.
    PutConfigRule -> ConfigRule
configRule :: ConfigRule
  }
  deriving (PutConfigRule -> PutConfigRule -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutConfigRule -> PutConfigRule -> Bool
$c/= :: PutConfigRule -> PutConfigRule -> Bool
== :: PutConfigRule -> PutConfigRule -> Bool
$c== :: PutConfigRule -> PutConfigRule -> Bool
Prelude.Eq, ReadPrec [PutConfigRule]
ReadPrec PutConfigRule
Int -> ReadS PutConfigRule
ReadS [PutConfigRule]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutConfigRule]
$creadListPrec :: ReadPrec [PutConfigRule]
readPrec :: ReadPrec PutConfigRule
$creadPrec :: ReadPrec PutConfigRule
readList :: ReadS [PutConfigRule]
$creadList :: ReadS [PutConfigRule]
readsPrec :: Int -> ReadS PutConfigRule
$creadsPrec :: Int -> ReadS PutConfigRule
Prelude.Read, Int -> PutConfigRule -> ShowS
[PutConfigRule] -> ShowS
PutConfigRule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutConfigRule] -> ShowS
$cshowList :: [PutConfigRule] -> ShowS
show :: PutConfigRule -> String
$cshow :: PutConfigRule -> String
showsPrec :: Int -> PutConfigRule -> ShowS
$cshowsPrec :: Int -> PutConfigRule -> ShowS
Prelude.Show, forall x. Rep PutConfigRule x -> PutConfigRule
forall x. PutConfigRule -> Rep PutConfigRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutConfigRule x -> PutConfigRule
$cfrom :: forall x. PutConfigRule -> Rep PutConfigRule x
Prelude.Generic)

-- |
-- Create a value of 'PutConfigRule' 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:
--
-- 'tags', 'putConfigRule_tags' - An array of tag object.
--
-- 'configRule', 'putConfigRule_configRule' - The rule that you want to add to your account.
newPutConfigRule ::
  -- | 'configRule'
  ConfigRule ->
  PutConfigRule
newPutConfigRule :: ConfigRule -> PutConfigRule
newPutConfigRule ConfigRule
pConfigRule_ =
  PutConfigRule'
    { $sel:tags:PutConfigRule' :: Maybe [Tag]
tags = forall a. Maybe a
Prelude.Nothing,
      $sel:configRule:PutConfigRule' :: ConfigRule
configRule = ConfigRule
pConfigRule_
    }

-- | An array of tag object.
putConfigRule_tags :: Lens.Lens' PutConfigRule (Prelude.Maybe [Tag])
putConfigRule_tags :: Lens' PutConfigRule (Maybe [Tag])
putConfigRule_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutConfigRule' {Maybe [Tag]
tags :: Maybe [Tag]
$sel:tags:PutConfigRule' :: PutConfigRule -> Maybe [Tag]
tags} -> Maybe [Tag]
tags) (\s :: PutConfigRule
s@PutConfigRule' {} Maybe [Tag]
a -> PutConfigRule
s {$sel:tags:PutConfigRule' :: Maybe [Tag]
tags = Maybe [Tag]
a} :: PutConfigRule) 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 rule that you want to add to your account.
putConfigRule_configRule :: Lens.Lens' PutConfigRule ConfigRule
putConfigRule_configRule :: Lens' PutConfigRule ConfigRule
putConfigRule_configRule = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutConfigRule' {ConfigRule
configRule :: ConfigRule
$sel:configRule:PutConfigRule' :: PutConfigRule -> ConfigRule
configRule} -> ConfigRule
configRule) (\s :: PutConfigRule
s@PutConfigRule' {} ConfigRule
a -> PutConfigRule
s {$sel:configRule:PutConfigRule' :: ConfigRule
configRule = ConfigRule
a} :: PutConfigRule)

instance Core.AWSRequest PutConfigRule where
  type
    AWSResponse PutConfigRule =
      PutConfigRuleResponse
  request :: (Service -> Service) -> PutConfigRule -> Request PutConfigRule
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy PutConfigRule
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutConfigRule)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull PutConfigRuleResponse
PutConfigRuleResponse'

instance Prelude.Hashable PutConfigRule where
  hashWithSalt :: Int -> PutConfigRule -> Int
hashWithSalt Int
_salt PutConfigRule' {Maybe [Tag]
ConfigRule
configRule :: ConfigRule
tags :: Maybe [Tag]
$sel:configRule:PutConfigRule' :: PutConfigRule -> ConfigRule
$sel:tags:PutConfigRule' :: PutConfigRule -> Maybe [Tag]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Tag]
tags
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ConfigRule
configRule

instance Prelude.NFData PutConfigRule where
  rnf :: PutConfigRule -> ()
rnf PutConfigRule' {Maybe [Tag]
ConfigRule
configRule :: ConfigRule
tags :: Maybe [Tag]
$sel:configRule:PutConfigRule' :: PutConfigRule -> ConfigRule
$sel:tags:PutConfigRule' :: PutConfigRule -> Maybe [Tag]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Tag]
tags
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ConfigRule
configRule

instance Data.ToHeaders PutConfigRule where
  toHeaders :: PutConfigRule -> [Header]
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> [Header]
Data.=# ( ByteString
"StarlingDoveService.PutConfigRule" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> [Header]
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON PutConfigRule where
  toJSON :: PutConfigRule -> Value
toJSON PutConfigRule' {Maybe [Tag]
ConfigRule
configRule :: ConfigRule
tags :: Maybe [Tag]
$sel:configRule:PutConfigRule' :: PutConfigRule -> ConfigRule
$sel:tags:PutConfigRule' :: PutConfigRule -> Maybe [Tag]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Tags" 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 [Tag]
tags,
            forall a. a -> Maybe a
Prelude.Just (Key
"ConfigRule" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ConfigRule
configRule)
          ]
      )

instance Data.ToPath PutConfigRule where
  toPath :: PutConfigRule -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Data.ToQuery PutConfigRule where
  toQuery :: PutConfigRule -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newPutConfigRuleResponse' smart constructor.
data PutConfigRuleResponse = PutConfigRuleResponse'
  {
  }
  deriving (PutConfigRuleResponse -> PutConfigRuleResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutConfigRuleResponse -> PutConfigRuleResponse -> Bool
$c/= :: PutConfigRuleResponse -> PutConfigRuleResponse -> Bool
== :: PutConfigRuleResponse -> PutConfigRuleResponse -> Bool
$c== :: PutConfigRuleResponse -> PutConfigRuleResponse -> Bool
Prelude.Eq, ReadPrec [PutConfigRuleResponse]
ReadPrec PutConfigRuleResponse
Int -> ReadS PutConfigRuleResponse
ReadS [PutConfigRuleResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutConfigRuleResponse]
$creadListPrec :: ReadPrec [PutConfigRuleResponse]
readPrec :: ReadPrec PutConfigRuleResponse
$creadPrec :: ReadPrec PutConfigRuleResponse
readList :: ReadS [PutConfigRuleResponse]
$creadList :: ReadS [PutConfigRuleResponse]
readsPrec :: Int -> ReadS PutConfigRuleResponse
$creadsPrec :: Int -> ReadS PutConfigRuleResponse
Prelude.Read, Int -> PutConfigRuleResponse -> ShowS
[PutConfigRuleResponse] -> ShowS
PutConfigRuleResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutConfigRuleResponse] -> ShowS
$cshowList :: [PutConfigRuleResponse] -> ShowS
show :: PutConfigRuleResponse -> String
$cshow :: PutConfigRuleResponse -> String
showsPrec :: Int -> PutConfigRuleResponse -> ShowS
$cshowsPrec :: Int -> PutConfigRuleResponse -> ShowS
Prelude.Show, forall x. Rep PutConfigRuleResponse x -> PutConfigRuleResponse
forall x. PutConfigRuleResponse -> Rep PutConfigRuleResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutConfigRuleResponse x -> PutConfigRuleResponse
$cfrom :: forall x. PutConfigRuleResponse -> Rep PutConfigRuleResponse x
Prelude.Generic)

-- |
-- Create a value of 'PutConfigRuleResponse' 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.
newPutConfigRuleResponse ::
  PutConfigRuleResponse
newPutConfigRuleResponse :: PutConfigRuleResponse
newPutConfigRuleResponse = PutConfigRuleResponse
PutConfigRuleResponse'

instance Prelude.NFData PutConfigRuleResponse where
  rnf :: PutConfigRuleResponse -> ()
rnf PutConfigRuleResponse
_ = ()