{-# 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-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)
--
-- Adds or updates an Config rule for evaluating whether your Amazon Web
-- Services resources comply with your desired configurations.
--
-- You can use this action for custom Config rules and Config managed
-- rules. A custom Config rule is a rule that you develop and maintain. An
-- Config managed rule is a customizable, predefined rule that Config
-- provides.
--
-- If you are adding a new custom Config rule, you must first create the
-- Lambda function that the rule invokes to evaluate your resources. When
-- you use the @PutConfigRule@ action to add the rule to Config, you must
-- specify the Amazon Resource Name (ARN) that Lambda assigns to the
-- function. Specify the ARN for the @SourceIdentifier@ key. This key is
-- part of the @Source@ object, which is part of the @ConfigRule@ object.
--
-- If you are adding an Config managed rule, specify the rule\'s identifier
-- for the @SourceIdentifier@ key. To reference Config managed rule
-- identifiers, see
-- <https://docs.aws.amazon.com/config/latest/developerguide/evaluate-config_use-managed-rules.html About Config managed rules>.
--
-- 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.
--
-- The maximum number of rules that Config supports is 150.
--
-- For information about requesting a rule limit increase, see
-- <http://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html#limits_config Config Limits>
-- in the /Amazon Web Services General Reference Guide/.
--
-- 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.Lens as Lens
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
(PutConfigRule -> PutConfigRule -> Bool)
-> (PutConfigRule -> PutConfigRule -> Bool) -> Eq PutConfigRule
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]
(Int -> ReadS PutConfigRule)
-> ReadS [PutConfigRule]
-> ReadPrec PutConfigRule
-> ReadPrec [PutConfigRule]
-> Read 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
(Int -> PutConfigRule -> ShowS)
-> (PutConfigRule -> String)
-> ([PutConfigRule] -> ShowS)
-> Show PutConfigRule
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. PutConfigRule -> Rep PutConfigRule x)
-> (forall x. Rep PutConfigRule x -> PutConfigRule)
-> Generic PutConfigRule
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' :: Maybe [Tag] -> ConfigRule -> PutConfigRule
PutConfigRule'
    { $sel:tags:PutConfigRule' :: Maybe [Tag]
tags = Maybe [Tag]
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 :: (Maybe [Tag] -> f (Maybe [Tag]))
-> PutConfigRule -> f PutConfigRule
putConfigRule_tags = (PutConfigRule -> Maybe [Tag])
-> (PutConfigRule -> Maybe [Tag] -> PutConfigRule)
-> Lens PutConfigRule PutConfigRule (Maybe [Tag]) (Maybe [Tag])
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) ((Maybe [Tag] -> f (Maybe [Tag]))
 -> PutConfigRule -> f PutConfigRule)
-> ((Maybe [Tag] -> f (Maybe [Tag]))
    -> Maybe [Tag] -> f (Maybe [Tag]))
-> (Maybe [Tag] -> f (Maybe [Tag]))
-> PutConfigRule
-> f PutConfigRule
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Tag] [Tag] [Tag] [Tag]
-> Iso (Maybe [Tag]) (Maybe [Tag]) (Maybe [Tag]) (Maybe [Tag])
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 [Tag] [Tag] [Tag] [Tag]
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 :: (ConfigRule -> f ConfigRule) -> PutConfigRule -> f PutConfigRule
putConfigRule_configRule = (PutConfigRule -> ConfigRule)
-> (PutConfigRule -> ConfigRule -> PutConfigRule)
-> Lens PutConfigRule PutConfigRule ConfigRule 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 :: PutConfigRule -> Request PutConfigRule
request = Service -> PutConfigRule -> Request PutConfigRule
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutConfigRule
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutConfigRule)))
response =
    AWSResponse PutConfigRule
-> Logger
-> Service
-> Proxy PutConfigRule
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutConfigRule)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse PutConfigRule
PutConfigRuleResponse
PutConfigRuleResponse'

instance Prelude.Hashable PutConfigRule

instance Prelude.NFData PutConfigRule

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

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Tags" Text -> [Tag] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Tag] -> Pair) -> Maybe [Tag] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Tag]
tags,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ConfigRule" Text -> ConfigRule -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ConfigRule
configRule)
          ]
      )

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

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

-- | /See:/ 'newPutConfigRuleResponse' smart constructor.
data PutConfigRuleResponse = PutConfigRuleResponse'
  {
  }
  deriving (PutConfigRuleResponse -> PutConfigRuleResponse -> Bool
(PutConfigRuleResponse -> PutConfigRuleResponse -> Bool)
-> (PutConfigRuleResponse -> PutConfigRuleResponse -> Bool)
-> Eq PutConfigRuleResponse
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]
(Int -> ReadS PutConfigRuleResponse)
-> ReadS [PutConfigRuleResponse]
-> ReadPrec PutConfigRuleResponse
-> ReadPrec [PutConfigRuleResponse]
-> Read 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
(Int -> PutConfigRuleResponse -> ShowS)
-> (PutConfigRuleResponse -> String)
-> ([PutConfigRuleResponse] -> ShowS)
-> Show PutConfigRuleResponse
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. PutConfigRuleResponse -> Rep PutConfigRuleResponse x)
-> (forall x. Rep PutConfigRuleResponse x -> PutConfigRuleResponse)
-> Generic PutConfigRuleResponse
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