{-# 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.Inspector.CreateResourceGroup
-- 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 resource group using the specified set of tags (key and value
-- pairs) that are used to select the EC2 instances to be included in an
-- Amazon Inspector assessment target. The created resource group is then
-- used to create an Amazon Inspector assessment target. For more
-- information, see CreateAssessmentTarget.
module Amazonka.Inspector.CreateResourceGroup
  ( -- * Creating a Request
    CreateResourceGroup (..),
    newCreateResourceGroup,

    -- * Request Lenses
    createResourceGroup_resourceGroupTags,

    -- * Destructuring the Response
    CreateResourceGroupResponse (..),
    newCreateResourceGroupResponse,

    -- * Response Lenses
    createResourceGroupResponse_httpStatus,
    createResourceGroupResponse_resourceGroupArn,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.Inspector.Types
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:/ 'newCreateResourceGroup' smart constructor.
data CreateResourceGroup = CreateResourceGroup'
  { -- | A collection of keys and an array of possible values,
    -- \'[{\"key\":\"key1\",\"values\":[\"Value1\",\"Value2\"]},{\"key\":\"Key2\",\"values\":[\"Value3\"]}]\'.
    --
    -- For example,\'[{\"key\":\"Name\",\"values\":[\"TestEC2Instance\"]}]\'.
    CreateResourceGroup -> NonEmpty ResourceGroupTag
resourceGroupTags :: Prelude.NonEmpty ResourceGroupTag
  }
  deriving (CreateResourceGroup -> CreateResourceGroup -> Bool
(CreateResourceGroup -> CreateResourceGroup -> Bool)
-> (CreateResourceGroup -> CreateResourceGroup -> Bool)
-> Eq CreateResourceGroup
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateResourceGroup -> CreateResourceGroup -> Bool
$c/= :: CreateResourceGroup -> CreateResourceGroup -> Bool
== :: CreateResourceGroup -> CreateResourceGroup -> Bool
$c== :: CreateResourceGroup -> CreateResourceGroup -> Bool
Prelude.Eq, ReadPrec [CreateResourceGroup]
ReadPrec CreateResourceGroup
Int -> ReadS CreateResourceGroup
ReadS [CreateResourceGroup]
(Int -> ReadS CreateResourceGroup)
-> ReadS [CreateResourceGroup]
-> ReadPrec CreateResourceGroup
-> ReadPrec [CreateResourceGroup]
-> Read CreateResourceGroup
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateResourceGroup]
$creadListPrec :: ReadPrec [CreateResourceGroup]
readPrec :: ReadPrec CreateResourceGroup
$creadPrec :: ReadPrec CreateResourceGroup
readList :: ReadS [CreateResourceGroup]
$creadList :: ReadS [CreateResourceGroup]
readsPrec :: Int -> ReadS CreateResourceGroup
$creadsPrec :: Int -> ReadS CreateResourceGroup
Prelude.Read, Int -> CreateResourceGroup -> ShowS
[CreateResourceGroup] -> ShowS
CreateResourceGroup -> String
(Int -> CreateResourceGroup -> ShowS)
-> (CreateResourceGroup -> String)
-> ([CreateResourceGroup] -> ShowS)
-> Show CreateResourceGroup
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateResourceGroup] -> ShowS
$cshowList :: [CreateResourceGroup] -> ShowS
show :: CreateResourceGroup -> String
$cshow :: CreateResourceGroup -> String
showsPrec :: Int -> CreateResourceGroup -> ShowS
$cshowsPrec :: Int -> CreateResourceGroup -> ShowS
Prelude.Show, (forall x. CreateResourceGroup -> Rep CreateResourceGroup x)
-> (forall x. Rep CreateResourceGroup x -> CreateResourceGroup)
-> Generic CreateResourceGroup
forall x. Rep CreateResourceGroup x -> CreateResourceGroup
forall x. CreateResourceGroup -> Rep CreateResourceGroup x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateResourceGroup x -> CreateResourceGroup
$cfrom :: forall x. CreateResourceGroup -> Rep CreateResourceGroup x
Prelude.Generic)

-- |
-- Create a value of 'CreateResourceGroup' 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:
--
-- 'resourceGroupTags', 'createResourceGroup_resourceGroupTags' - A collection of keys and an array of possible values,
-- \'[{\"key\":\"key1\",\"values\":[\"Value1\",\"Value2\"]},{\"key\":\"Key2\",\"values\":[\"Value3\"]}]\'.
--
-- For example,\'[{\"key\":\"Name\",\"values\":[\"TestEC2Instance\"]}]\'.
newCreateResourceGroup ::
  -- | 'resourceGroupTags'
  Prelude.NonEmpty ResourceGroupTag ->
  CreateResourceGroup
newCreateResourceGroup :: NonEmpty ResourceGroupTag -> CreateResourceGroup
newCreateResourceGroup NonEmpty ResourceGroupTag
pResourceGroupTags_ =
  CreateResourceGroup' :: NonEmpty ResourceGroupTag -> CreateResourceGroup
CreateResourceGroup'
    { $sel:resourceGroupTags:CreateResourceGroup' :: NonEmpty ResourceGroupTag
resourceGroupTags =
        Tagged
  (NonEmpty ResourceGroupTag) (Identity (NonEmpty ResourceGroupTag))
-> Tagged
     (NonEmpty ResourceGroupTag) (Identity (NonEmpty ResourceGroupTag))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged
   (NonEmpty ResourceGroupTag) (Identity (NonEmpty ResourceGroupTag))
 -> Tagged
      (NonEmpty ResourceGroupTag) (Identity (NonEmpty ResourceGroupTag)))
-> NonEmpty ResourceGroupTag -> NonEmpty ResourceGroupTag
forall t b. AReview t b -> b -> t
Lens.# NonEmpty ResourceGroupTag
pResourceGroupTags_
    }

-- | A collection of keys and an array of possible values,
-- \'[{\"key\":\"key1\",\"values\":[\"Value1\",\"Value2\"]},{\"key\":\"Key2\",\"values\":[\"Value3\"]}]\'.
--
-- For example,\'[{\"key\":\"Name\",\"values\":[\"TestEC2Instance\"]}]\'.
createResourceGroup_resourceGroupTags :: Lens.Lens' CreateResourceGroup (Prelude.NonEmpty ResourceGroupTag)
createResourceGroup_resourceGroupTags :: (NonEmpty ResourceGroupTag -> f (NonEmpty ResourceGroupTag))
-> CreateResourceGroup -> f CreateResourceGroup
createResourceGroup_resourceGroupTags = (CreateResourceGroup -> NonEmpty ResourceGroupTag)
-> (CreateResourceGroup
    -> NonEmpty ResourceGroupTag -> CreateResourceGroup)
-> Lens
     CreateResourceGroup
     CreateResourceGroup
     (NonEmpty ResourceGroupTag)
     (NonEmpty ResourceGroupTag)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateResourceGroup' {NonEmpty ResourceGroupTag
resourceGroupTags :: NonEmpty ResourceGroupTag
$sel:resourceGroupTags:CreateResourceGroup' :: CreateResourceGroup -> NonEmpty ResourceGroupTag
resourceGroupTags} -> NonEmpty ResourceGroupTag
resourceGroupTags) (\s :: CreateResourceGroup
s@CreateResourceGroup' {} NonEmpty ResourceGroupTag
a -> CreateResourceGroup
s {$sel:resourceGroupTags:CreateResourceGroup' :: NonEmpty ResourceGroupTag
resourceGroupTags = NonEmpty ResourceGroupTag
a} :: CreateResourceGroup) ((NonEmpty ResourceGroupTag -> f (NonEmpty ResourceGroupTag))
 -> CreateResourceGroup -> f CreateResourceGroup)
-> ((NonEmpty ResourceGroupTag -> f (NonEmpty ResourceGroupTag))
    -> NonEmpty ResourceGroupTag -> f (NonEmpty ResourceGroupTag))
-> (NonEmpty ResourceGroupTag -> f (NonEmpty ResourceGroupTag))
-> CreateResourceGroup
-> f CreateResourceGroup
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty ResourceGroupTag -> f (NonEmpty ResourceGroupTag))
-> NonEmpty ResourceGroupTag -> f (NonEmpty ResourceGroupTag)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest CreateResourceGroup where
  type
    AWSResponse CreateResourceGroup =
      CreateResourceGroupResponse
  request :: CreateResourceGroup -> Request CreateResourceGroup
request = Service -> CreateResourceGroup -> Request CreateResourceGroup
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateResourceGroup
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateResourceGroup)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateResourceGroup))
-> Logger
-> Service
-> Proxy CreateResourceGroup
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateResourceGroup)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Int -> Text -> CreateResourceGroupResponse
CreateResourceGroupResponse'
            (Int -> Text -> CreateResourceGroupResponse)
-> Either String Int
-> Either String (Text -> CreateResourceGroupResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            Either String (Text -> CreateResourceGroupResponse)
-> Either String Text -> Either String CreateResourceGroupResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String Text
forall a. FromJSON a => Object -> Text -> Either String a
Core..:> Text
"resourceGroupArn")
      )

instance Prelude.Hashable CreateResourceGroup

instance Prelude.NFData CreateResourceGroup

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

instance Core.ToJSON CreateResourceGroup where
  toJSON :: CreateResourceGroup -> Value
toJSON CreateResourceGroup' {NonEmpty ResourceGroupTag
resourceGroupTags :: NonEmpty ResourceGroupTag
$sel:resourceGroupTags:CreateResourceGroup' :: CreateResourceGroup -> NonEmpty ResourceGroupTag
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"resourceGroupTags" Text -> NonEmpty ResourceGroupTag -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty ResourceGroupTag
resourceGroupTags)
          ]
      )

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

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

-- | /See:/ 'newCreateResourceGroupResponse' smart constructor.
data CreateResourceGroupResponse = CreateResourceGroupResponse'
  { -- | The response's http status code.
    CreateResourceGroupResponse -> Int
httpStatus :: Prelude.Int,
    -- | The ARN that specifies the resource group that is created.
    CreateResourceGroupResponse -> Text
resourceGroupArn :: Prelude.Text
  }
  deriving (CreateResourceGroupResponse -> CreateResourceGroupResponse -> Bool
(CreateResourceGroupResponse
 -> CreateResourceGroupResponse -> Bool)
-> (CreateResourceGroupResponse
    -> CreateResourceGroupResponse -> Bool)
-> Eq CreateResourceGroupResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateResourceGroupResponse -> CreateResourceGroupResponse -> Bool
$c/= :: CreateResourceGroupResponse -> CreateResourceGroupResponse -> Bool
== :: CreateResourceGroupResponse -> CreateResourceGroupResponse -> Bool
$c== :: CreateResourceGroupResponse -> CreateResourceGroupResponse -> Bool
Prelude.Eq, ReadPrec [CreateResourceGroupResponse]
ReadPrec CreateResourceGroupResponse
Int -> ReadS CreateResourceGroupResponse
ReadS [CreateResourceGroupResponse]
(Int -> ReadS CreateResourceGroupResponse)
-> ReadS [CreateResourceGroupResponse]
-> ReadPrec CreateResourceGroupResponse
-> ReadPrec [CreateResourceGroupResponse]
-> Read CreateResourceGroupResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateResourceGroupResponse]
$creadListPrec :: ReadPrec [CreateResourceGroupResponse]
readPrec :: ReadPrec CreateResourceGroupResponse
$creadPrec :: ReadPrec CreateResourceGroupResponse
readList :: ReadS [CreateResourceGroupResponse]
$creadList :: ReadS [CreateResourceGroupResponse]
readsPrec :: Int -> ReadS CreateResourceGroupResponse
$creadsPrec :: Int -> ReadS CreateResourceGroupResponse
Prelude.Read, Int -> CreateResourceGroupResponse -> ShowS
[CreateResourceGroupResponse] -> ShowS
CreateResourceGroupResponse -> String
(Int -> CreateResourceGroupResponse -> ShowS)
-> (CreateResourceGroupResponse -> String)
-> ([CreateResourceGroupResponse] -> ShowS)
-> Show CreateResourceGroupResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateResourceGroupResponse] -> ShowS
$cshowList :: [CreateResourceGroupResponse] -> ShowS
show :: CreateResourceGroupResponse -> String
$cshow :: CreateResourceGroupResponse -> String
showsPrec :: Int -> CreateResourceGroupResponse -> ShowS
$cshowsPrec :: Int -> CreateResourceGroupResponse -> ShowS
Prelude.Show, (forall x.
 CreateResourceGroupResponse -> Rep CreateResourceGroupResponse x)
-> (forall x.
    Rep CreateResourceGroupResponse x -> CreateResourceGroupResponse)
-> Generic CreateResourceGroupResponse
forall x.
Rep CreateResourceGroupResponse x -> CreateResourceGroupResponse
forall x.
CreateResourceGroupResponse -> Rep CreateResourceGroupResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateResourceGroupResponse x -> CreateResourceGroupResponse
$cfrom :: forall x.
CreateResourceGroupResponse -> Rep CreateResourceGroupResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateResourceGroupResponse' 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:
--
-- 'httpStatus', 'createResourceGroupResponse_httpStatus' - The response's http status code.
--
-- 'resourceGroupArn', 'createResourceGroupResponse_resourceGroupArn' - The ARN that specifies the resource group that is created.
newCreateResourceGroupResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'resourceGroupArn'
  Prelude.Text ->
  CreateResourceGroupResponse
newCreateResourceGroupResponse :: Int -> Text -> CreateResourceGroupResponse
newCreateResourceGroupResponse
  Int
pHttpStatus_
  Text
pResourceGroupArn_ =
    CreateResourceGroupResponse' :: Int -> Text -> CreateResourceGroupResponse
CreateResourceGroupResponse'
      { $sel:httpStatus:CreateResourceGroupResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:resourceGroupArn:CreateResourceGroupResponse' :: Text
resourceGroupArn = Text
pResourceGroupArn_
      }

-- | The response's http status code.
createResourceGroupResponse_httpStatus :: Lens.Lens' CreateResourceGroupResponse Prelude.Int
createResourceGroupResponse_httpStatus :: (Int -> f Int)
-> CreateResourceGroupResponse -> f CreateResourceGroupResponse
createResourceGroupResponse_httpStatus = (CreateResourceGroupResponse -> Int)
-> (CreateResourceGroupResponse
    -> Int -> CreateResourceGroupResponse)
-> Lens
     CreateResourceGroupResponse CreateResourceGroupResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateResourceGroupResponse' {Int
httpStatus :: Int
$sel:httpStatus:CreateResourceGroupResponse' :: CreateResourceGroupResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: CreateResourceGroupResponse
s@CreateResourceGroupResponse' {} Int
a -> CreateResourceGroupResponse
s {$sel:httpStatus:CreateResourceGroupResponse' :: Int
httpStatus = Int
a} :: CreateResourceGroupResponse)

-- | The ARN that specifies the resource group that is created.
createResourceGroupResponse_resourceGroupArn :: Lens.Lens' CreateResourceGroupResponse Prelude.Text
createResourceGroupResponse_resourceGroupArn :: (Text -> f Text)
-> CreateResourceGroupResponse -> f CreateResourceGroupResponse
createResourceGroupResponse_resourceGroupArn = (CreateResourceGroupResponse -> Text)
-> (CreateResourceGroupResponse
    -> Text -> CreateResourceGroupResponse)
-> Lens
     CreateResourceGroupResponse CreateResourceGroupResponse Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateResourceGroupResponse' {Text
resourceGroupArn :: Text
$sel:resourceGroupArn:CreateResourceGroupResponse' :: CreateResourceGroupResponse -> Text
resourceGroupArn} -> Text
resourceGroupArn) (\s :: CreateResourceGroupResponse
s@CreateResourceGroupResponse' {} Text
a -> CreateResourceGroupResponse
s {$sel:resourceGroupArn:CreateResourceGroupResponse' :: Text
resourceGroupArn = Text
a} :: CreateResourceGroupResponse)

instance Prelude.NFData CreateResourceGroupResponse