{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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
-- do not 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 an KMS key with the log group, ingested data is
-- encrypted using the KMS key. This association is stored as long as the
-- data encrypted with the KMS key is still within CloudWatch Logs. This
-- enables CloudWatch Logs to decrypt this data whenever it is requested.
--
-- If you attempt to associate a KMS key with the log group but the KMS
-- keydoes not exist or the KMS key is disabled, you receive an
-- @InvalidParameterException@ error.
--
-- CloudWatch Logs supports only symmetric KMS keys. Do not associate an
-- asymmetric KMS key 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.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:/ 'newCreateLogGroup' smart constructor.
data CreateLogGroup = CreateLogGroup'
  { -- | The Amazon Resource Name (ARN) of the KMS key 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>.
    CreateLogGroup -> Maybe Text
kmsKeyId :: Prelude.Maybe Prelude.Text,
    -- | The key-value pairs to use for the tags.
    --
    -- You can grant users access to certain log groups while preventing them
    -- from accessing other log groups. To do so, tag your groups and use IAM
    -- policies that refer to those tags. To assign tags when you create a log
    -- group, you must have either the @logs:TagResource@ or @logs:TagLogGroup@
    -- permission. For more information about tagging, see
    -- <https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html Tagging Amazon Web Services resources>.
    -- 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
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]
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
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. 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 KMS key 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>.
--
-- 'tags', 'createLogGroup_tags' - The key-value pairs to use for the tags.
--
-- You can grant users access to certain log groups while preventing them
-- from accessing other log groups. To do so, tag your groups and use IAM
-- policies that refer to those tags. To assign tags when you create a log
-- group, you must have either the @logs:TagResource@ or @logs:TagLogGroup@
-- permission. For more information about tagging, see
-- <https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html Tagging Amazon Web Services resources>.
-- 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'
    { $sel:kmsKeyId:CreateLogGroup' :: Maybe Text
kmsKeyId = forall a. Maybe a
Prelude.Nothing,
      $sel:tags:CreateLogGroup' :: Maybe (HashMap Text Text)
tags = forall a. Maybe a
Prelude.Nothing,
      $sel:logGroupName:CreateLogGroup' :: Text
logGroupName = Text
pLogGroupName_
    }

-- | The Amazon Resource Name (ARN) of the KMS key 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>.
createLogGroup_kmsKeyId :: Lens.Lens' CreateLogGroup (Prelude.Maybe Prelude.Text)
createLogGroup_kmsKeyId :: Lens' CreateLogGroup (Maybe Text)
createLogGroup_kmsKeyId = 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.
--
-- You can grant users access to certain log groups while preventing them
-- from accessing other log groups. To do so, tag your groups and use IAM
-- policies that refer to those tags. To assign tags when you create a log
-- group, you must have either the @logs:TagResource@ or @logs:TagLogGroup@
-- permission. For more information about tagging, see
-- <https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html Tagging Amazon Web Services resources>.
-- 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 :: Lens' CreateLogGroup (Maybe (HashMap Text Text))
createLogGroup_tags = 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) 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 name of the log group.
createLogGroup_logGroupName :: Lens.Lens' CreateLogGroup Prelude.Text
createLogGroup_logGroupName :: Lens' CreateLogGroup Text
createLogGroup_logGroupName = 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 :: (Service -> Service) -> CreateLogGroup -> Request CreateLogGroup
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 CreateLogGroup
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateLogGroup)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull CreateLogGroupResponse
CreateLogGroupResponse'

instance Prelude.Hashable CreateLogGroup where
  hashWithSalt :: Int -> CreateLogGroup -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
kmsKeyId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
tags
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
logGroupName

instance Prelude.NFData CreateLogGroup where
  rnf :: CreateLogGroup -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
kmsKeyId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
tags
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
logGroupName

instance Data.ToHeaders CreateLogGroup where
  toHeaders :: CreateLogGroup -> [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
"Logs_20140328.CreateLogGroup" ::
                          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 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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"kmsKeyId" 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
kmsKeyId,
            (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 (HashMap Text Text)
tags,
            forall a. a -> Maybe a
Prelude.Just (Key
"logGroupName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
logGroupName)
          ]
      )

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

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

-- | /See:/ 'newCreateLogGroupResponse' smart constructor.
data CreateLogGroupResponse = CreateLogGroupResponse'
  {
  }
  deriving (CreateLogGroupResponse -> CreateLogGroupResponse -> Bool
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]
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
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. 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 where
  rnf :: CreateLogGroupResponse -> ()
rnf CreateLogGroupResponse
_ = ()