{-# 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.AppConfig.CreateExtensionAssociation
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- When you create an extension or configure an Amazon Web
-- Services-authored extension, you associate the extension with an
-- AppConfig application, environment, or configuration profile. For
-- example, you can choose to run the
-- @AppConfig deployment events to Amazon SNS@ Amazon Web Services-authored
-- extension and receive notifications on an Amazon SNS topic anytime a
-- configuration deployment is started for a specific application. Defining
-- which extension to associate with an AppConfig resource is called an
-- /extension association/. An extension association is a specified
-- relationship between an extension and an AppConfig resource, such as an
-- application or a configuration profile. For more information about
-- extensions and associations, see
-- <https://docs.aws.amazon.com/appconfig/latest/userguide/working-with-appconfig-extensions.html Working with AppConfig extensions>
-- in the /AppConfig User Guide/.
module Amazonka.AppConfig.CreateExtensionAssociation
  ( -- * Creating a Request
    CreateExtensionAssociation (..),
    newCreateExtensionAssociation,

    -- * Request Lenses
    createExtensionAssociation_extensionVersionNumber,
    createExtensionAssociation_parameters,
    createExtensionAssociation_tags,
    createExtensionAssociation_extensionIdentifier,
    createExtensionAssociation_resourceIdentifier,

    -- * Destructuring the Response
    ExtensionAssociation (..),
    newExtensionAssociation,

    -- * Response Lenses
    extensionAssociation_arn,
    extensionAssociation_extensionArn,
    extensionAssociation_extensionVersionNumber,
    extensionAssociation_id,
    extensionAssociation_parameters,
    extensionAssociation_resourceArn,
  )
where

import Amazonka.AppConfig.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:/ 'newCreateExtensionAssociation' smart constructor.
data CreateExtensionAssociation = CreateExtensionAssociation'
  { -- | The version number of the extension. If not specified, AppConfig uses
    -- the maximum version of the extension.
    CreateExtensionAssociation -> Maybe Int
extensionVersionNumber :: Prelude.Maybe Prelude.Int,
    -- | The parameter names and values defined in the extensions. Extension
    -- parameters marked @Required@ must be entered for this field.
    CreateExtensionAssociation -> Maybe (HashMap Text Text)
parameters :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | Adds one or more tags for the specified extension association. Tags are
    -- metadata that help you categorize resources in different ways, for
    -- example, by purpose, owner, or environment. Each tag consists of a key
    -- and an optional value, both of which you define.
    CreateExtensionAssociation -> Maybe (HashMap Text Text)
tags :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The name, the ID, or the Amazon Resource Name (ARN) of the extension.
    CreateExtensionAssociation -> Text
extensionIdentifier :: Prelude.Text,
    -- | The ARN of an application, configuration profile, or environment.
    CreateExtensionAssociation -> Text
resourceIdentifier :: Prelude.Text
  }
  deriving (CreateExtensionAssociation -> CreateExtensionAssociation -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateExtensionAssociation -> CreateExtensionAssociation -> Bool
$c/= :: CreateExtensionAssociation -> CreateExtensionAssociation -> Bool
== :: CreateExtensionAssociation -> CreateExtensionAssociation -> Bool
$c== :: CreateExtensionAssociation -> CreateExtensionAssociation -> Bool
Prelude.Eq, ReadPrec [CreateExtensionAssociation]
ReadPrec CreateExtensionAssociation
Int -> ReadS CreateExtensionAssociation
ReadS [CreateExtensionAssociation]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateExtensionAssociation]
$creadListPrec :: ReadPrec [CreateExtensionAssociation]
readPrec :: ReadPrec CreateExtensionAssociation
$creadPrec :: ReadPrec CreateExtensionAssociation
readList :: ReadS [CreateExtensionAssociation]
$creadList :: ReadS [CreateExtensionAssociation]
readsPrec :: Int -> ReadS CreateExtensionAssociation
$creadsPrec :: Int -> ReadS CreateExtensionAssociation
Prelude.Read, Int -> CreateExtensionAssociation -> ShowS
[CreateExtensionAssociation] -> ShowS
CreateExtensionAssociation -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateExtensionAssociation] -> ShowS
$cshowList :: [CreateExtensionAssociation] -> ShowS
show :: CreateExtensionAssociation -> String
$cshow :: CreateExtensionAssociation -> String
showsPrec :: Int -> CreateExtensionAssociation -> ShowS
$cshowsPrec :: Int -> CreateExtensionAssociation -> ShowS
Prelude.Show, forall x.
Rep CreateExtensionAssociation x -> CreateExtensionAssociation
forall x.
CreateExtensionAssociation -> Rep CreateExtensionAssociation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateExtensionAssociation x -> CreateExtensionAssociation
$cfrom :: forall x.
CreateExtensionAssociation -> Rep CreateExtensionAssociation x
Prelude.Generic)

-- |
-- Create a value of 'CreateExtensionAssociation' 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:
--
-- 'extensionVersionNumber', 'createExtensionAssociation_extensionVersionNumber' - The version number of the extension. If not specified, AppConfig uses
-- the maximum version of the extension.
--
-- 'parameters', 'createExtensionAssociation_parameters' - The parameter names and values defined in the extensions. Extension
-- parameters marked @Required@ must be entered for this field.
--
-- 'tags', 'createExtensionAssociation_tags' - Adds one or more tags for the specified extension association. Tags are
-- metadata that help you categorize resources in different ways, for
-- example, by purpose, owner, or environment. Each tag consists of a key
-- and an optional value, both of which you define.
--
-- 'extensionIdentifier', 'createExtensionAssociation_extensionIdentifier' - The name, the ID, or the Amazon Resource Name (ARN) of the extension.
--
-- 'resourceIdentifier', 'createExtensionAssociation_resourceIdentifier' - The ARN of an application, configuration profile, or environment.
newCreateExtensionAssociation ::
  -- | 'extensionIdentifier'
  Prelude.Text ->
  -- | 'resourceIdentifier'
  Prelude.Text ->
  CreateExtensionAssociation
newCreateExtensionAssociation :: Text -> Text -> CreateExtensionAssociation
newCreateExtensionAssociation
  Text
pExtensionIdentifier_
  Text
pResourceIdentifier_ =
    CreateExtensionAssociation'
      { $sel:extensionVersionNumber:CreateExtensionAssociation' :: Maybe Int
extensionVersionNumber =
          forall a. Maybe a
Prelude.Nothing,
        $sel:parameters:CreateExtensionAssociation' :: Maybe (HashMap Text Text)
parameters = forall a. Maybe a
Prelude.Nothing,
        $sel:tags:CreateExtensionAssociation' :: Maybe (HashMap Text Text)
tags = forall a. Maybe a
Prelude.Nothing,
        $sel:extensionIdentifier:CreateExtensionAssociation' :: Text
extensionIdentifier = Text
pExtensionIdentifier_,
        $sel:resourceIdentifier:CreateExtensionAssociation' :: Text
resourceIdentifier = Text
pResourceIdentifier_
      }

-- | The version number of the extension. If not specified, AppConfig uses
-- the maximum version of the extension.
createExtensionAssociation_extensionVersionNumber :: Lens.Lens' CreateExtensionAssociation (Prelude.Maybe Prelude.Int)
createExtensionAssociation_extensionVersionNumber :: Lens' CreateExtensionAssociation (Maybe Int)
createExtensionAssociation_extensionVersionNumber = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateExtensionAssociation' {Maybe Int
extensionVersionNumber :: Maybe Int
$sel:extensionVersionNumber:CreateExtensionAssociation' :: CreateExtensionAssociation -> Maybe Int
extensionVersionNumber} -> Maybe Int
extensionVersionNumber) (\s :: CreateExtensionAssociation
s@CreateExtensionAssociation' {} Maybe Int
a -> CreateExtensionAssociation
s {$sel:extensionVersionNumber:CreateExtensionAssociation' :: Maybe Int
extensionVersionNumber = Maybe Int
a} :: CreateExtensionAssociation)

-- | The parameter names and values defined in the extensions. Extension
-- parameters marked @Required@ must be entered for this field.
createExtensionAssociation_parameters :: Lens.Lens' CreateExtensionAssociation (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
createExtensionAssociation_parameters :: Lens' CreateExtensionAssociation (Maybe (HashMap Text Text))
createExtensionAssociation_parameters = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateExtensionAssociation' {Maybe (HashMap Text Text)
parameters :: Maybe (HashMap Text Text)
$sel:parameters:CreateExtensionAssociation' :: CreateExtensionAssociation -> Maybe (HashMap Text Text)
parameters} -> Maybe (HashMap Text Text)
parameters) (\s :: CreateExtensionAssociation
s@CreateExtensionAssociation' {} Maybe (HashMap Text Text)
a -> CreateExtensionAssociation
s {$sel:parameters:CreateExtensionAssociation' :: Maybe (HashMap Text Text)
parameters = Maybe (HashMap Text Text)
a} :: CreateExtensionAssociation) 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

-- | Adds one or more tags for the specified extension association. Tags are
-- metadata that help you categorize resources in different ways, for
-- example, by purpose, owner, or environment. Each tag consists of a key
-- and an optional value, both of which you define.
createExtensionAssociation_tags :: Lens.Lens' CreateExtensionAssociation (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
createExtensionAssociation_tags :: Lens' CreateExtensionAssociation (Maybe (HashMap Text Text))
createExtensionAssociation_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateExtensionAssociation' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:CreateExtensionAssociation' :: CreateExtensionAssociation -> Maybe (HashMap Text Text)
tags} -> Maybe (HashMap Text Text)
tags) (\s :: CreateExtensionAssociation
s@CreateExtensionAssociation' {} Maybe (HashMap Text Text)
a -> CreateExtensionAssociation
s {$sel:tags:CreateExtensionAssociation' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
a} :: CreateExtensionAssociation) 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, the ID, or the Amazon Resource Name (ARN) of the extension.
createExtensionAssociation_extensionIdentifier :: Lens.Lens' CreateExtensionAssociation Prelude.Text
createExtensionAssociation_extensionIdentifier :: Lens' CreateExtensionAssociation Text
createExtensionAssociation_extensionIdentifier = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateExtensionAssociation' {Text
extensionIdentifier :: Text
$sel:extensionIdentifier:CreateExtensionAssociation' :: CreateExtensionAssociation -> Text
extensionIdentifier} -> Text
extensionIdentifier) (\s :: CreateExtensionAssociation
s@CreateExtensionAssociation' {} Text
a -> CreateExtensionAssociation
s {$sel:extensionIdentifier:CreateExtensionAssociation' :: Text
extensionIdentifier = Text
a} :: CreateExtensionAssociation)

-- | The ARN of an application, configuration profile, or environment.
createExtensionAssociation_resourceIdentifier :: Lens.Lens' CreateExtensionAssociation Prelude.Text
createExtensionAssociation_resourceIdentifier :: Lens' CreateExtensionAssociation Text
createExtensionAssociation_resourceIdentifier = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateExtensionAssociation' {Text
resourceIdentifier :: Text
$sel:resourceIdentifier:CreateExtensionAssociation' :: CreateExtensionAssociation -> Text
resourceIdentifier} -> Text
resourceIdentifier) (\s :: CreateExtensionAssociation
s@CreateExtensionAssociation' {} Text
a -> CreateExtensionAssociation
s {$sel:resourceIdentifier:CreateExtensionAssociation' :: Text
resourceIdentifier = Text
a} :: CreateExtensionAssociation)

instance Core.AWSRequest CreateExtensionAssociation where
  type
    AWSResponse CreateExtensionAssociation =
      ExtensionAssociation
  request :: (Service -> Service)
-> CreateExtensionAssociation -> Request CreateExtensionAssociation
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 CreateExtensionAssociation
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateExtensionAssociation)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      (\Int
s ResponseHeaders
h Object
x -> forall a. FromJSON a => Object -> Either String a
Data.eitherParseJSON Object
x)

instance Prelude.Hashable CreateExtensionAssociation where
  hashWithSalt :: Int -> CreateExtensionAssociation -> Int
hashWithSalt Int
_salt CreateExtensionAssociation' {Maybe Int
Maybe (HashMap Text Text)
Text
resourceIdentifier :: Text
extensionIdentifier :: Text
tags :: Maybe (HashMap Text Text)
parameters :: Maybe (HashMap Text Text)
extensionVersionNumber :: Maybe Int
$sel:resourceIdentifier:CreateExtensionAssociation' :: CreateExtensionAssociation -> Text
$sel:extensionIdentifier:CreateExtensionAssociation' :: CreateExtensionAssociation -> Text
$sel:tags:CreateExtensionAssociation' :: CreateExtensionAssociation -> Maybe (HashMap Text Text)
$sel:parameters:CreateExtensionAssociation' :: CreateExtensionAssociation -> Maybe (HashMap Text Text)
$sel:extensionVersionNumber:CreateExtensionAssociation' :: CreateExtensionAssociation -> Maybe Int
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
extensionVersionNumber
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
parameters
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
tags
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
extensionIdentifier
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
resourceIdentifier

instance Prelude.NFData CreateExtensionAssociation where
  rnf :: CreateExtensionAssociation -> ()
rnf CreateExtensionAssociation' {Maybe Int
Maybe (HashMap Text Text)
Text
resourceIdentifier :: Text
extensionIdentifier :: Text
tags :: Maybe (HashMap Text Text)
parameters :: Maybe (HashMap Text Text)
extensionVersionNumber :: Maybe Int
$sel:resourceIdentifier:CreateExtensionAssociation' :: CreateExtensionAssociation -> Text
$sel:extensionIdentifier:CreateExtensionAssociation' :: CreateExtensionAssociation -> Text
$sel:tags:CreateExtensionAssociation' :: CreateExtensionAssociation -> Maybe (HashMap Text Text)
$sel:parameters:CreateExtensionAssociation' :: CreateExtensionAssociation -> Maybe (HashMap Text Text)
$sel:extensionVersionNumber:CreateExtensionAssociation' :: CreateExtensionAssociation -> Maybe Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
extensionVersionNumber
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
parameters
      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
extensionIdentifier
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
resourceIdentifier

instance Data.ToHeaders CreateExtensionAssociation where
  toHeaders :: CreateExtensionAssociation -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON CreateExtensionAssociation where
  toJSON :: CreateExtensionAssociation -> Value
toJSON CreateExtensionAssociation' {Maybe Int
Maybe (HashMap Text Text)
Text
resourceIdentifier :: Text
extensionIdentifier :: Text
tags :: Maybe (HashMap Text Text)
parameters :: Maybe (HashMap Text Text)
extensionVersionNumber :: Maybe Int
$sel:resourceIdentifier:CreateExtensionAssociation' :: CreateExtensionAssociation -> Text
$sel:extensionIdentifier:CreateExtensionAssociation' :: CreateExtensionAssociation -> Text
$sel:tags:CreateExtensionAssociation' :: CreateExtensionAssociation -> Maybe (HashMap Text Text)
$sel:parameters:CreateExtensionAssociation' :: CreateExtensionAssociation -> Maybe (HashMap Text Text)
$sel:extensionVersionNumber:CreateExtensionAssociation' :: CreateExtensionAssociation -> Maybe Int
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"ExtensionVersionNumber" 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 Int
extensionVersionNumber,
            (Key
"Parameters" 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)
parameters,
            (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
"ExtensionIdentifier" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
extensionIdentifier),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"ResourceIdentifier" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
resourceIdentifier)
          ]
      )

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

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