{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.AutoScaling.Types.InstanceMetadataOptions
-- 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)
module Amazonka.AutoScaling.Types.InstanceMetadataOptions where

import Amazonka.AutoScaling.Types.InstanceMetadataEndpointState
import Amazonka.AutoScaling.Types.InstanceMetadataHttpTokensState
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The metadata options for the instances. For more information, see
-- <https://docs.aws.amazon.com/autoscaling/ec2/userguide/create-launch-config.html#launch-configurations-imds Configuring the Instance Metadata Options>
-- in the /Amazon EC2 Auto Scaling User Guide/.
--
-- /See:/ 'newInstanceMetadataOptions' smart constructor.
data InstanceMetadataOptions = InstanceMetadataOptions'
  { -- | This parameter enables or disables the HTTP metadata endpoint on your
    -- instances. If the parameter is not specified, the default state is
    -- @enabled@.
    --
    -- If you specify a value of @disabled@, you will not be able to access
    -- your instance metadata.
    InstanceMetadataOptions -> Maybe InstanceMetadataEndpointState
httpEndpoint :: Prelude.Maybe InstanceMetadataEndpointState,
    -- | The desired HTTP PUT response hop limit for instance metadata requests.
    -- The larger the number, the further instance metadata requests can
    -- travel.
    --
    -- Default: 1
    InstanceMetadataOptions -> Maybe Natural
httpPutResponseHopLimit :: Prelude.Maybe Prelude.Natural,
    -- | The state of token usage for your instance metadata requests. If the
    -- parameter is not specified in the request, the default state is
    -- @optional@.
    --
    -- If the state is @optional@, you can choose to retrieve instance metadata
    -- with or without a signed token header on your request. If you retrieve
    -- the IAM role credentials without a token, the version 1.0 role
    -- credentials are returned. If you retrieve the IAM role credentials using
    -- a valid signed token, the version 2.0 role credentials are returned.
    --
    -- If the state is @required@, you must send a signed token header with any
    -- instance metadata retrieval requests. In this state, retrieving the IAM
    -- role credentials always returns the version 2.0 credentials; the version
    -- 1.0 credentials are not available.
    InstanceMetadataOptions -> Maybe InstanceMetadataHttpTokensState
httpTokens :: Prelude.Maybe InstanceMetadataHttpTokensState
  }
  deriving (InstanceMetadataOptions -> InstanceMetadataOptions -> Bool
(InstanceMetadataOptions -> InstanceMetadataOptions -> Bool)
-> (InstanceMetadataOptions -> InstanceMetadataOptions -> Bool)
-> Eq InstanceMetadataOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InstanceMetadataOptions -> InstanceMetadataOptions -> Bool
$c/= :: InstanceMetadataOptions -> InstanceMetadataOptions -> Bool
== :: InstanceMetadataOptions -> InstanceMetadataOptions -> Bool
$c== :: InstanceMetadataOptions -> InstanceMetadataOptions -> Bool
Prelude.Eq, ReadPrec [InstanceMetadataOptions]
ReadPrec InstanceMetadataOptions
Int -> ReadS InstanceMetadataOptions
ReadS [InstanceMetadataOptions]
(Int -> ReadS InstanceMetadataOptions)
-> ReadS [InstanceMetadataOptions]
-> ReadPrec InstanceMetadataOptions
-> ReadPrec [InstanceMetadataOptions]
-> Read InstanceMetadataOptions
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InstanceMetadataOptions]
$creadListPrec :: ReadPrec [InstanceMetadataOptions]
readPrec :: ReadPrec InstanceMetadataOptions
$creadPrec :: ReadPrec InstanceMetadataOptions
readList :: ReadS [InstanceMetadataOptions]
$creadList :: ReadS [InstanceMetadataOptions]
readsPrec :: Int -> ReadS InstanceMetadataOptions
$creadsPrec :: Int -> ReadS InstanceMetadataOptions
Prelude.Read, Int -> InstanceMetadataOptions -> ShowS
[InstanceMetadataOptions] -> ShowS
InstanceMetadataOptions -> String
(Int -> InstanceMetadataOptions -> ShowS)
-> (InstanceMetadataOptions -> String)
-> ([InstanceMetadataOptions] -> ShowS)
-> Show InstanceMetadataOptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InstanceMetadataOptions] -> ShowS
$cshowList :: [InstanceMetadataOptions] -> ShowS
show :: InstanceMetadataOptions -> String
$cshow :: InstanceMetadataOptions -> String
showsPrec :: Int -> InstanceMetadataOptions -> ShowS
$cshowsPrec :: Int -> InstanceMetadataOptions -> ShowS
Prelude.Show, (forall x.
 InstanceMetadataOptions -> Rep InstanceMetadataOptions x)
-> (forall x.
    Rep InstanceMetadataOptions x -> InstanceMetadataOptions)
-> Generic InstanceMetadataOptions
forall x. Rep InstanceMetadataOptions x -> InstanceMetadataOptions
forall x. InstanceMetadataOptions -> Rep InstanceMetadataOptions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InstanceMetadataOptions x -> InstanceMetadataOptions
$cfrom :: forall x. InstanceMetadataOptions -> Rep InstanceMetadataOptions x
Prelude.Generic)

-- |
-- Create a value of 'InstanceMetadataOptions' 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:
--
-- 'httpEndpoint', 'instanceMetadataOptions_httpEndpoint' - This parameter enables or disables the HTTP metadata endpoint on your
-- instances. If the parameter is not specified, the default state is
-- @enabled@.
--
-- If you specify a value of @disabled@, you will not be able to access
-- your instance metadata.
--
-- 'httpPutResponseHopLimit', 'instanceMetadataOptions_httpPutResponseHopLimit' - The desired HTTP PUT response hop limit for instance metadata requests.
-- The larger the number, the further instance metadata requests can
-- travel.
--
-- Default: 1
--
-- 'httpTokens', 'instanceMetadataOptions_httpTokens' - The state of token usage for your instance metadata requests. If the
-- parameter is not specified in the request, the default state is
-- @optional@.
--
-- If the state is @optional@, you can choose to retrieve instance metadata
-- with or without a signed token header on your request. If you retrieve
-- the IAM role credentials without a token, the version 1.0 role
-- credentials are returned. If you retrieve the IAM role credentials using
-- a valid signed token, the version 2.0 role credentials are returned.
--
-- If the state is @required@, you must send a signed token header with any
-- instance metadata retrieval requests. In this state, retrieving the IAM
-- role credentials always returns the version 2.0 credentials; the version
-- 1.0 credentials are not available.
newInstanceMetadataOptions ::
  InstanceMetadataOptions
newInstanceMetadataOptions :: InstanceMetadataOptions
newInstanceMetadataOptions =
  InstanceMetadataOptions' :: Maybe InstanceMetadataEndpointState
-> Maybe Natural
-> Maybe InstanceMetadataHttpTokensState
-> InstanceMetadataOptions
InstanceMetadataOptions'
    { $sel:httpEndpoint:InstanceMetadataOptions' :: Maybe InstanceMetadataEndpointState
httpEndpoint =
        Maybe InstanceMetadataEndpointState
forall a. Maybe a
Prelude.Nothing,
      $sel:httpPutResponseHopLimit:InstanceMetadataOptions' :: Maybe Natural
httpPutResponseHopLimit = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:httpTokens:InstanceMetadataOptions' :: Maybe InstanceMetadataHttpTokensState
httpTokens = Maybe InstanceMetadataHttpTokensState
forall a. Maybe a
Prelude.Nothing
    }

-- | This parameter enables or disables the HTTP metadata endpoint on your
-- instances. If the parameter is not specified, the default state is
-- @enabled@.
--
-- If you specify a value of @disabled@, you will not be able to access
-- your instance metadata.
instanceMetadataOptions_httpEndpoint :: Lens.Lens' InstanceMetadataOptions (Prelude.Maybe InstanceMetadataEndpointState)
instanceMetadataOptions_httpEndpoint :: (Maybe InstanceMetadataEndpointState
 -> f (Maybe InstanceMetadataEndpointState))
-> InstanceMetadataOptions -> f InstanceMetadataOptions
instanceMetadataOptions_httpEndpoint = (InstanceMetadataOptions -> Maybe InstanceMetadataEndpointState)
-> (InstanceMetadataOptions
    -> Maybe InstanceMetadataEndpointState -> InstanceMetadataOptions)
-> Lens
     InstanceMetadataOptions
     InstanceMetadataOptions
     (Maybe InstanceMetadataEndpointState)
     (Maybe InstanceMetadataEndpointState)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceMetadataOptions' {Maybe InstanceMetadataEndpointState
httpEndpoint :: Maybe InstanceMetadataEndpointState
$sel:httpEndpoint:InstanceMetadataOptions' :: InstanceMetadataOptions -> Maybe InstanceMetadataEndpointState
httpEndpoint} -> Maybe InstanceMetadataEndpointState
httpEndpoint) (\s :: InstanceMetadataOptions
s@InstanceMetadataOptions' {} Maybe InstanceMetadataEndpointState
a -> InstanceMetadataOptions
s {$sel:httpEndpoint:InstanceMetadataOptions' :: Maybe InstanceMetadataEndpointState
httpEndpoint = Maybe InstanceMetadataEndpointState
a} :: InstanceMetadataOptions)

-- | The desired HTTP PUT response hop limit for instance metadata requests.
-- The larger the number, the further instance metadata requests can
-- travel.
--
-- Default: 1
instanceMetadataOptions_httpPutResponseHopLimit :: Lens.Lens' InstanceMetadataOptions (Prelude.Maybe Prelude.Natural)
instanceMetadataOptions_httpPutResponseHopLimit :: (Maybe Natural -> f (Maybe Natural))
-> InstanceMetadataOptions -> f InstanceMetadataOptions
instanceMetadataOptions_httpPutResponseHopLimit = (InstanceMetadataOptions -> Maybe Natural)
-> (InstanceMetadataOptions
    -> Maybe Natural -> InstanceMetadataOptions)
-> Lens
     InstanceMetadataOptions
     InstanceMetadataOptions
     (Maybe Natural)
     (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceMetadataOptions' {Maybe Natural
httpPutResponseHopLimit :: Maybe Natural
$sel:httpPutResponseHopLimit:InstanceMetadataOptions' :: InstanceMetadataOptions -> Maybe Natural
httpPutResponseHopLimit} -> Maybe Natural
httpPutResponseHopLimit) (\s :: InstanceMetadataOptions
s@InstanceMetadataOptions' {} Maybe Natural
a -> InstanceMetadataOptions
s {$sel:httpPutResponseHopLimit:InstanceMetadataOptions' :: Maybe Natural
httpPutResponseHopLimit = Maybe Natural
a} :: InstanceMetadataOptions)

-- | The state of token usage for your instance metadata requests. If the
-- parameter is not specified in the request, the default state is
-- @optional@.
--
-- If the state is @optional@, you can choose to retrieve instance metadata
-- with or without a signed token header on your request. If you retrieve
-- the IAM role credentials without a token, the version 1.0 role
-- credentials are returned. If you retrieve the IAM role credentials using
-- a valid signed token, the version 2.0 role credentials are returned.
--
-- If the state is @required@, you must send a signed token header with any
-- instance metadata retrieval requests. In this state, retrieving the IAM
-- role credentials always returns the version 2.0 credentials; the version
-- 1.0 credentials are not available.
instanceMetadataOptions_httpTokens :: Lens.Lens' InstanceMetadataOptions (Prelude.Maybe InstanceMetadataHttpTokensState)
instanceMetadataOptions_httpTokens :: (Maybe InstanceMetadataHttpTokensState
 -> f (Maybe InstanceMetadataHttpTokensState))
-> InstanceMetadataOptions -> f InstanceMetadataOptions
instanceMetadataOptions_httpTokens = (InstanceMetadataOptions -> Maybe InstanceMetadataHttpTokensState)
-> (InstanceMetadataOptions
    -> Maybe InstanceMetadataHttpTokensState
    -> InstanceMetadataOptions)
-> Lens
     InstanceMetadataOptions
     InstanceMetadataOptions
     (Maybe InstanceMetadataHttpTokensState)
     (Maybe InstanceMetadataHttpTokensState)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceMetadataOptions' {Maybe InstanceMetadataHttpTokensState
httpTokens :: Maybe InstanceMetadataHttpTokensState
$sel:httpTokens:InstanceMetadataOptions' :: InstanceMetadataOptions -> Maybe InstanceMetadataHttpTokensState
httpTokens} -> Maybe InstanceMetadataHttpTokensState
httpTokens) (\s :: InstanceMetadataOptions
s@InstanceMetadataOptions' {} Maybe InstanceMetadataHttpTokensState
a -> InstanceMetadataOptions
s {$sel:httpTokens:InstanceMetadataOptions' :: Maybe InstanceMetadataHttpTokensState
httpTokens = Maybe InstanceMetadataHttpTokensState
a} :: InstanceMetadataOptions)

instance Core.FromXML InstanceMetadataOptions where
  parseXML :: [Node] -> Either String InstanceMetadataOptions
parseXML [Node]
x =
    Maybe InstanceMetadataEndpointState
-> Maybe Natural
-> Maybe InstanceMetadataHttpTokensState
-> InstanceMetadataOptions
InstanceMetadataOptions'
      (Maybe InstanceMetadataEndpointState
 -> Maybe Natural
 -> Maybe InstanceMetadataHttpTokensState
 -> InstanceMetadataOptions)
-> Either String (Maybe InstanceMetadataEndpointState)
-> Either
     String
     (Maybe Natural
      -> Maybe InstanceMetadataHttpTokensState
      -> InstanceMetadataOptions)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node]
-> Text -> Either String (Maybe InstanceMetadataEndpointState)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"HttpEndpoint")
      Either
  String
  (Maybe Natural
   -> Maybe InstanceMetadataHttpTokensState
   -> InstanceMetadataOptions)
-> Either String (Maybe Natural)
-> Either
     String
     (Maybe InstanceMetadataHttpTokensState -> InstanceMetadataOptions)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Natural)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"HttpPutResponseHopLimit")
      Either
  String
  (Maybe InstanceMetadataHttpTokensState -> InstanceMetadataOptions)
-> Either String (Maybe InstanceMetadataHttpTokensState)
-> Either String InstanceMetadataOptions
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node]
-> Text -> Either String (Maybe InstanceMetadataHttpTokensState)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"HttpTokens")

instance Prelude.Hashable InstanceMetadataOptions

instance Prelude.NFData InstanceMetadataOptions

instance Core.ToQuery InstanceMetadataOptions where
  toQuery :: InstanceMetadataOptions -> QueryString
toQuery InstanceMetadataOptions' {Maybe Natural
Maybe InstanceMetadataEndpointState
Maybe InstanceMetadataHttpTokensState
httpTokens :: Maybe InstanceMetadataHttpTokensState
httpPutResponseHopLimit :: Maybe Natural
httpEndpoint :: Maybe InstanceMetadataEndpointState
$sel:httpTokens:InstanceMetadataOptions' :: InstanceMetadataOptions -> Maybe InstanceMetadataHttpTokensState
$sel:httpPutResponseHopLimit:InstanceMetadataOptions' :: InstanceMetadataOptions -> Maybe Natural
$sel:httpEndpoint:InstanceMetadataOptions' :: InstanceMetadataOptions -> Maybe InstanceMetadataEndpointState
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"HttpEndpoint" ByteString -> Maybe InstanceMetadataEndpointState -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe InstanceMetadataEndpointState
httpEndpoint,
        ByteString
"HttpPutResponseHopLimit"
          ByteString -> Maybe Natural -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Natural
httpPutResponseHopLimit,
        ByteString
"HttpTokens" ByteString -> Maybe InstanceMetadataHttpTokensState -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe InstanceMetadataHttpTokensState
httpTokens
      ]