{-# 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.CloudWatchLogs.CreateLogGroup
-- 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)
--
-- Creates a log group with the specified name. You can create up to 20,000
-- log groups per account.
--
-- You must use the following guidelines when naming a log group:
--
-- -   Log group names must be unique within a region for an Amazon Web
--     Services account.
--
-- -   Log group names can be between 1 and 512 characters long.
--
-- -   Log group names consist of the following characters: a-z, A-Z, 0-9,
--     \'_\' (underscore), \'-\' (hyphen), \'\/\' (forward slash), \'.\'
--     (period), and \'#\' (number sign)
--
-- When you create a log group, by default the log events in the log group
-- never expire. To set a retention policy so that events expire and are
-- deleted after a specified time, use
-- <https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutRetentionPolicy.html PutRetentionPolicy>.
--
-- If you associate a Key Management Service customer master key (CMK) with
-- the log group, ingested data is encrypted using the CMK. This
-- association is stored as long as the data encrypted with the CMK is
-- still within CloudWatch Logs. This enables CloudWatch Logs to decrypt
-- this data whenever it is requested.
--
-- If you attempt to associate a CMK with the log group but the CMK does
-- not exist or the CMK is disabled, you receive an
-- @InvalidParameterException@ error.
--
-- CloudWatch Logs supports only symmetric CMKs. Do not associate an
-- asymmetric CMK with your log group. For more information, see
-- <https://docs.aws.amazon.com/kms/latest/developerguide/symmetric-asymmetric.html Using Symmetric and Asymmetric Keys>.
module Amazonka.CloudWatchLogs.CreateLogGroup
  ( -- * Creating a Request
    CreateLogGroup (..),
    newCreateLogGroup,

    -- * Request Lenses
    createLogGroup_kmsKeyId,
    createLogGroup_tags,
    createLogGroup_logGroupName,

    -- * Destructuring the Response
    CreateLogGroupResponse (..),
    newCreateLogGroupResponse,
  )
where

import Amazonka.CloudWatchLogs.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:/ 'newCreateLogGroup' smart constructor.
data CreateLogGroup = CreateLogGroup'
  { -- | The Amazon Resource Name (ARN) of the CMK to use when encrypting log
    -- data. For more information, see
    -- <https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#arn-syntax-kms Amazon Resource Names - Key Management Service>.
    CreateLogGroup -> Maybe Text
kmsKeyId :: Prelude.Maybe Prelude.Text,
    -- | The key-value pairs to use for the tags.
    --
    -- CloudWatch Logs doesn’t support IAM policies that prevent users from
    -- assigning specified tags to log groups using the
    -- @aws:Resource\/key-name @ or @aws:TagKeys@ condition keys. For more
    -- information about using tags to control access, see
    -- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access_tags.html Controlling access to Amazon Web Services resources using tags>.
    CreateLogGroup -> Maybe (HashMap Text Text)
tags :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The name of the log group.
    CreateLogGroup -> Text
logGroupName :: Prelude.Text
  }
  deriving (CreateLogGroup -> CreateLogGroup -> Bool
(CreateLogGroup -> CreateLogGroup -> Bool)
-> (CreateLogGroup -> CreateLogGroup -> Bool) -> Eq CreateLogGroup
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateLogGroup -> CreateLogGroup -> Bool
$c/= :: CreateLogGroup -> CreateLogGroup -> Bool
== :: CreateLogGroup -> CreateLogGroup -> Bool
$c== :: CreateLogGroup -> CreateLogGroup -> Bool
Prelude.Eq, ReadPrec [CreateLogGroup]
ReadPrec CreateLogGroup
Int -> ReadS CreateLogGroup
ReadS [CreateLogGroup]
(Int -> ReadS CreateLogGroup)
-> ReadS [CreateLogGroup]
-> ReadPrec CreateLogGroup
-> ReadPrec [CreateLogGroup]
-> Read CreateLogGroup
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateLogGroup]
$creadListPrec :: ReadPrec [CreateLogGroup]
readPrec :: ReadPrec CreateLogGroup
$creadPrec :: ReadPrec CreateLogGroup
readList :: ReadS [CreateLogGroup]
$creadList :: ReadS [CreateLogGroup]
readsPrec :: Int -> ReadS CreateLogGroup
$creadsPrec :: Int -> ReadS CreateLogGroup
Prelude.Read, Int -> CreateLogGroup -> ShowS
[CreateLogGroup] -> ShowS
CreateLogGroup -> String
(Int -> CreateLogGroup -> ShowS)
-> (CreateLogGroup -> String)
-> ([CreateLogGroup] -> ShowS)
-> Show CreateLogGroup
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateLogGroup] -> ShowS
$cshowList :: [CreateLogGroup] -> ShowS
show :: CreateLogGroup -> String
$cshow :: CreateLogGroup -> String
showsPrec :: Int -> CreateLogGroup -> ShowS
$cshowsPrec :: Int -> CreateLogGroup -> ShowS
Prelude.Show, (forall x. CreateLogGroup -> Rep CreateLogGroup x)
-> (forall x. Rep CreateLogGroup x -> CreateLogGroup)
-> Generic CreateLogGroup
forall x. Rep CreateLogGroup x -> CreateLogGroup
forall x. CreateLogGroup -> Rep CreateLogGroup x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateLogGroup x -> CreateLogGroup
$cfrom :: forall x. CreateLogGroup -> Rep CreateLogGroup x
Prelude.Generic)

-- |
-- Create a value of 'CreateLogGroup' 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:
--
-- 'kmsKeyId', 'createLogGroup_kmsKeyId' - The Amazon Resource Name (ARN) of the CMK to use when encrypting log
-- data. For more information, see
-- <https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#arn-syntax-kms Amazon Resource Names - Key Management Service>.
--
-- 'tags', 'createLogGroup_tags' - The key-value pairs to use for the tags.
--
-- CloudWatch Logs doesn’t support IAM policies that prevent users from
-- assigning specified tags to log groups using the
-- @aws:Resource\/key-name @ or @aws:TagKeys@ condition keys. For more
-- information about using tags to control access, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access_tags.html Controlling access to Amazon Web Services resources using tags>.
--
-- 'logGroupName', 'createLogGroup_logGroupName' - The name of the log group.
newCreateLogGroup ::
  -- | 'logGroupName'
  Prelude.Text ->
  CreateLogGroup
newCreateLogGroup :: Text -> CreateLogGroup
newCreateLogGroup Text
pLogGroupName_ =
  CreateLogGroup' :: Maybe Text -> Maybe (HashMap Text Text) -> Text -> CreateLogGroup
CreateLogGroup'
    { $sel:kmsKeyId:CreateLogGroup' :: Maybe Text
kmsKeyId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:tags:CreateLogGroup' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:logGroupName:CreateLogGroup' :: Text
logGroupName = Text
pLogGroupName_
    }

-- | The Amazon Resource Name (ARN) of the CMK to use when encrypting log
-- data. For more information, see
-- <https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#arn-syntax-kms Amazon Resource Names - Key Management Service>.
createLogGroup_kmsKeyId :: Lens.Lens' CreateLogGroup (Prelude.Maybe Prelude.Text)
createLogGroup_kmsKeyId :: (Maybe Text -> f (Maybe Text))
-> CreateLogGroup -> f CreateLogGroup
createLogGroup_kmsKeyId = (CreateLogGroup -> Maybe Text)
-> (CreateLogGroup -> Maybe Text -> CreateLogGroup)
-> Lens CreateLogGroup CreateLogGroup (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateLogGroup' {Maybe Text
kmsKeyId :: Maybe Text
$sel:kmsKeyId:CreateLogGroup' :: CreateLogGroup -> Maybe Text
kmsKeyId} -> Maybe Text
kmsKeyId) (\s :: CreateLogGroup
s@CreateLogGroup' {} Maybe Text
a -> CreateLogGroup
s {$sel:kmsKeyId:CreateLogGroup' :: Maybe Text
kmsKeyId = Maybe Text
a} :: CreateLogGroup)

-- | The key-value pairs to use for the tags.
--
-- CloudWatch Logs doesn’t support IAM policies that prevent users from
-- assigning specified tags to log groups using the
-- @aws:Resource\/key-name @ or @aws:TagKeys@ condition keys. For more
-- information about using tags to control access, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access_tags.html Controlling access to Amazon Web Services resources using tags>.
createLogGroup_tags :: Lens.Lens' CreateLogGroup (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
createLogGroup_tags :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> CreateLogGroup -> f CreateLogGroup
createLogGroup_tags = (CreateLogGroup -> Maybe (HashMap Text Text))
-> (CreateLogGroup -> Maybe (HashMap Text Text) -> CreateLogGroup)
-> Lens
     CreateLogGroup
     CreateLogGroup
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateLogGroup' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:CreateLogGroup' :: CreateLogGroup -> Maybe (HashMap Text Text)
tags} -> Maybe (HashMap Text Text)
tags) (\s :: CreateLogGroup
s@CreateLogGroup' {} Maybe (HashMap Text Text)
a -> CreateLogGroup
s {$sel:tags:CreateLogGroup' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
a} :: CreateLogGroup) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> CreateLogGroup -> f CreateLogGroup)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> CreateLogGroup
-> f CreateLogGroup
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text 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
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the log group.
createLogGroup_logGroupName :: Lens.Lens' CreateLogGroup Prelude.Text
createLogGroup_logGroupName :: (Text -> f Text) -> CreateLogGroup -> f CreateLogGroup
createLogGroup_logGroupName = (CreateLogGroup -> Text)
-> (CreateLogGroup -> Text -> CreateLogGroup)
-> Lens CreateLogGroup CreateLogGroup Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateLogGroup' {Text
logGroupName :: Text
$sel:logGroupName:CreateLogGroup' :: CreateLogGroup -> Text
logGroupName} -> Text
logGroupName) (\s :: CreateLogGroup
s@CreateLogGroup' {} Text
a -> CreateLogGroup
s {$sel:logGroupName:CreateLogGroup' :: Text
logGroupName = Text
a} :: CreateLogGroup)

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

instance Prelude.Hashable CreateLogGroup

instance Prelude.NFData CreateLogGroup

instance Core.ToHeaders CreateLogGroup where
  toHeaders :: CreateLogGroup -> [Header]
toHeaders =
    [Header] -> CreateLogGroup -> [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
"Logs_20140328.CreateLogGroup" ::
                          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 CreateLogGroup where
  toJSON :: CreateLogGroup -> Value
toJSON CreateLogGroup' {Maybe Text
Maybe (HashMap Text Text)
Text
logGroupName :: Text
tags :: Maybe (HashMap Text Text)
kmsKeyId :: Maybe Text
$sel:logGroupName:CreateLogGroup' :: CreateLogGroup -> Text
$sel:tags:CreateLogGroup' :: CreateLogGroup -> Maybe (HashMap Text Text)
$sel:kmsKeyId:CreateLogGroup' :: CreateLogGroup -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"kmsKeyId" 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
kmsKeyId,
            (Text
"tags" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
tags,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"logGroupName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
logGroupName)
          ]
      )

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

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

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

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

instance Prelude.NFData CreateLogGroupResponse