{-# 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.SSM.DeleteAssociation
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Disassociates the specified Amazon Web Services Systems Manager document
-- (SSM document) from the specified managed node. If you created the
-- association by using the @Targets@ parameter, then you must delete the
-- association by using the association ID.
--
-- When you disassociate a document from a managed node, it doesn\'t change
-- the configuration of the node. To change the configuration state of a
-- managed node after you disassociate a document, you must create a new
-- document with the desired configuration and associate it with the node.
module Amazonka.SSM.DeleteAssociation
  ( -- * Creating a Request
    DeleteAssociation (..),
    newDeleteAssociation,

    -- * Request Lenses
    deleteAssociation_associationId,
    deleteAssociation_instanceId,
    deleteAssociation_name,

    -- * Destructuring the Response
    DeleteAssociationResponse (..),
    newDeleteAssociationResponse,

    -- * Response Lenses
    deleteAssociationResponse_httpStatus,
  )
where

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
import Amazonka.SSM.Types

-- | /See:/ 'newDeleteAssociation' smart constructor.
data DeleteAssociation = DeleteAssociation'
  { -- | The association ID that you want to delete.
    DeleteAssociation -> Maybe Text
associationId :: Prelude.Maybe Prelude.Text,
    -- | The managed node ID.
    --
    -- @InstanceId@ has been deprecated. To specify a managed node ID for an
    -- association, use the @Targets@ parameter. Requests that include the
    -- parameter @InstanceID@ with Systems Manager documents (SSM documents)
    -- that use schema version 2.0 or later will fail. In addition, if you use
    -- the parameter @InstanceId@, you can\'t use the parameters
    -- @AssociationName@, @DocumentVersion@, @MaxErrors@, @MaxConcurrency@,
    -- @OutputLocation@, or @ScheduleExpression@. To use these parameters, you
    -- must use the @Targets@ parameter.
    DeleteAssociation -> Maybe Text
instanceId :: Prelude.Maybe Prelude.Text,
    -- | The name of the SSM document.
    DeleteAssociation -> Maybe Text
name :: Prelude.Maybe Prelude.Text
  }
  deriving (DeleteAssociation -> DeleteAssociation -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteAssociation -> DeleteAssociation -> Bool
$c/= :: DeleteAssociation -> DeleteAssociation -> Bool
== :: DeleteAssociation -> DeleteAssociation -> Bool
$c== :: DeleteAssociation -> DeleteAssociation -> Bool
Prelude.Eq, ReadPrec [DeleteAssociation]
ReadPrec DeleteAssociation
Int -> ReadS DeleteAssociation
ReadS [DeleteAssociation]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteAssociation]
$creadListPrec :: ReadPrec [DeleteAssociation]
readPrec :: ReadPrec DeleteAssociation
$creadPrec :: ReadPrec DeleteAssociation
readList :: ReadS [DeleteAssociation]
$creadList :: ReadS [DeleteAssociation]
readsPrec :: Int -> ReadS DeleteAssociation
$creadsPrec :: Int -> ReadS DeleteAssociation
Prelude.Read, Int -> DeleteAssociation -> ShowS
[DeleteAssociation] -> ShowS
DeleteAssociation -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteAssociation] -> ShowS
$cshowList :: [DeleteAssociation] -> ShowS
show :: DeleteAssociation -> String
$cshow :: DeleteAssociation -> String
showsPrec :: Int -> DeleteAssociation -> ShowS
$cshowsPrec :: Int -> DeleteAssociation -> ShowS
Prelude.Show, forall x. Rep DeleteAssociation x -> DeleteAssociation
forall x. DeleteAssociation -> Rep DeleteAssociation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteAssociation x -> DeleteAssociation
$cfrom :: forall x. DeleteAssociation -> Rep DeleteAssociation x
Prelude.Generic)

-- |
-- Create a value of 'DeleteAssociation' 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:
--
-- 'associationId', 'deleteAssociation_associationId' - The association ID that you want to delete.
--
-- 'instanceId', 'deleteAssociation_instanceId' - The managed node ID.
--
-- @InstanceId@ has been deprecated. To specify a managed node ID for an
-- association, use the @Targets@ parameter. Requests that include the
-- parameter @InstanceID@ with Systems Manager documents (SSM documents)
-- that use schema version 2.0 or later will fail. In addition, if you use
-- the parameter @InstanceId@, you can\'t use the parameters
-- @AssociationName@, @DocumentVersion@, @MaxErrors@, @MaxConcurrency@,
-- @OutputLocation@, or @ScheduleExpression@. To use these parameters, you
-- must use the @Targets@ parameter.
--
-- 'name', 'deleteAssociation_name' - The name of the SSM document.
newDeleteAssociation ::
  DeleteAssociation
newDeleteAssociation :: DeleteAssociation
newDeleteAssociation =
  DeleteAssociation'
    { $sel:associationId:DeleteAssociation' :: Maybe Text
associationId = forall a. Maybe a
Prelude.Nothing,
      $sel:instanceId:DeleteAssociation' :: Maybe Text
instanceId = forall a. Maybe a
Prelude.Nothing,
      $sel:name:DeleteAssociation' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing
    }

-- | The association ID that you want to delete.
deleteAssociation_associationId :: Lens.Lens' DeleteAssociation (Prelude.Maybe Prelude.Text)
deleteAssociation_associationId :: Lens' DeleteAssociation (Maybe Text)
deleteAssociation_associationId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteAssociation' {Maybe Text
associationId :: Maybe Text
$sel:associationId:DeleteAssociation' :: DeleteAssociation -> Maybe Text
associationId} -> Maybe Text
associationId) (\s :: DeleteAssociation
s@DeleteAssociation' {} Maybe Text
a -> DeleteAssociation
s {$sel:associationId:DeleteAssociation' :: Maybe Text
associationId = Maybe Text
a} :: DeleteAssociation)

-- | The managed node ID.
--
-- @InstanceId@ has been deprecated. To specify a managed node ID for an
-- association, use the @Targets@ parameter. Requests that include the
-- parameter @InstanceID@ with Systems Manager documents (SSM documents)
-- that use schema version 2.0 or later will fail. In addition, if you use
-- the parameter @InstanceId@, you can\'t use the parameters
-- @AssociationName@, @DocumentVersion@, @MaxErrors@, @MaxConcurrency@,
-- @OutputLocation@, or @ScheduleExpression@. To use these parameters, you
-- must use the @Targets@ parameter.
deleteAssociation_instanceId :: Lens.Lens' DeleteAssociation (Prelude.Maybe Prelude.Text)
deleteAssociation_instanceId :: Lens' DeleteAssociation (Maybe Text)
deleteAssociation_instanceId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteAssociation' {Maybe Text
instanceId :: Maybe Text
$sel:instanceId:DeleteAssociation' :: DeleteAssociation -> Maybe Text
instanceId} -> Maybe Text
instanceId) (\s :: DeleteAssociation
s@DeleteAssociation' {} Maybe Text
a -> DeleteAssociation
s {$sel:instanceId:DeleteAssociation' :: Maybe Text
instanceId = Maybe Text
a} :: DeleteAssociation)

-- | The name of the SSM document.
deleteAssociation_name :: Lens.Lens' DeleteAssociation (Prelude.Maybe Prelude.Text)
deleteAssociation_name :: Lens' DeleteAssociation (Maybe Text)
deleteAssociation_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteAssociation' {Maybe Text
name :: Maybe Text
$sel:name:DeleteAssociation' :: DeleteAssociation -> Maybe Text
name} -> Maybe Text
name) (\s :: DeleteAssociation
s@DeleteAssociation' {} Maybe Text
a -> DeleteAssociation
s {$sel:name:DeleteAssociation' :: Maybe Text
name = Maybe Text
a} :: DeleteAssociation)

instance Core.AWSRequest DeleteAssociation where
  type
    AWSResponse DeleteAssociation =
      DeleteAssociationResponse
  request :: (Service -> Service)
-> DeleteAssociation -> Request DeleteAssociation
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 DeleteAssociation
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DeleteAssociation)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> DeleteAssociationResponse
DeleteAssociationResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable DeleteAssociation where
  hashWithSalt :: Int -> DeleteAssociation -> Int
hashWithSalt Int
_salt DeleteAssociation' {Maybe Text
name :: Maybe Text
instanceId :: Maybe Text
associationId :: Maybe Text
$sel:name:DeleteAssociation' :: DeleteAssociation -> Maybe Text
$sel:instanceId:DeleteAssociation' :: DeleteAssociation -> Maybe Text
$sel:associationId:DeleteAssociation' :: DeleteAssociation -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
associationId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
instanceId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
name

instance Prelude.NFData DeleteAssociation where
  rnf :: DeleteAssociation -> ()
rnf DeleteAssociation' {Maybe Text
name :: Maybe Text
instanceId :: Maybe Text
associationId :: Maybe Text
$sel:name:DeleteAssociation' :: DeleteAssociation -> Maybe Text
$sel:instanceId:DeleteAssociation' :: DeleteAssociation -> Maybe Text
$sel:associationId:DeleteAssociation' :: DeleteAssociation -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
associationId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
instanceId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
name

instance Data.ToHeaders DeleteAssociation where
  toHeaders :: DeleteAssociation -> ResponseHeaders
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 -> ResponseHeaders
Data.=# ( ByteString
"AmazonSSM.DeleteAssociation" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON DeleteAssociation where
  toJSON :: DeleteAssociation -> Value
toJSON DeleteAssociation' {Maybe Text
name :: Maybe Text
instanceId :: Maybe Text
associationId :: Maybe Text
$sel:name:DeleteAssociation' :: DeleteAssociation -> Maybe Text
$sel:instanceId:DeleteAssociation' :: DeleteAssociation -> Maybe Text
$sel:associationId:DeleteAssociation' :: DeleteAssociation -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"AssociationId" 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
associationId,
            (Key
"InstanceId" 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
instanceId,
            (Key
"Name" 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
name
          ]
      )

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

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

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

-- |
-- Create a value of 'DeleteAssociationResponse' 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', 'deleteAssociationResponse_httpStatus' - The response's http status code.
newDeleteAssociationResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DeleteAssociationResponse
newDeleteAssociationResponse :: Int -> DeleteAssociationResponse
newDeleteAssociationResponse Int
pHttpStatus_ =
  DeleteAssociationResponse'
    { $sel:httpStatus:DeleteAssociationResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

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

instance Prelude.NFData DeleteAssociationResponse where
  rnf :: DeleteAssociationResponse -> ()
rnf DeleteAssociationResponse' {Int
httpStatus :: Int
$sel:httpStatus:DeleteAssociationResponse' :: DeleteAssociationResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus