{-# 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.EC2.Types.SpotPlacement
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.EC2.Types.SpotPlacement where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.EC2.Internal
import Amazonka.EC2.Types.Tenancy
import qualified Amazonka.Prelude as Prelude

-- | Describes Spot Instance placement.
--
-- /See:/ 'newSpotPlacement' smart constructor.
data SpotPlacement = SpotPlacement'
  { -- | The Availability Zone.
    --
    -- [Spot Fleet only] To specify multiple Availability Zones, separate them
    -- using commas; for example, \"us-west-2a, us-west-2b\".
    SpotPlacement -> Maybe Text
availabilityZone :: Prelude.Maybe Prelude.Text,
    -- | The name of the placement group.
    SpotPlacement -> Maybe Text
groupName :: Prelude.Maybe Prelude.Text,
    -- | The tenancy of the instance (if the instance is running in a VPC). An
    -- instance with a tenancy of @dedicated@ runs on single-tenant hardware.
    -- The @host@ tenancy is not supported for Spot Instances.
    SpotPlacement -> Maybe Tenancy
tenancy :: Prelude.Maybe Tenancy
  }
  deriving (SpotPlacement -> SpotPlacement -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SpotPlacement -> SpotPlacement -> Bool
$c/= :: SpotPlacement -> SpotPlacement -> Bool
== :: SpotPlacement -> SpotPlacement -> Bool
$c== :: SpotPlacement -> SpotPlacement -> Bool
Prelude.Eq, ReadPrec [SpotPlacement]
ReadPrec SpotPlacement
Int -> ReadS SpotPlacement
ReadS [SpotPlacement]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SpotPlacement]
$creadListPrec :: ReadPrec [SpotPlacement]
readPrec :: ReadPrec SpotPlacement
$creadPrec :: ReadPrec SpotPlacement
readList :: ReadS [SpotPlacement]
$creadList :: ReadS [SpotPlacement]
readsPrec :: Int -> ReadS SpotPlacement
$creadsPrec :: Int -> ReadS SpotPlacement
Prelude.Read, Int -> SpotPlacement -> ShowS
[SpotPlacement] -> ShowS
SpotPlacement -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SpotPlacement] -> ShowS
$cshowList :: [SpotPlacement] -> ShowS
show :: SpotPlacement -> String
$cshow :: SpotPlacement -> String
showsPrec :: Int -> SpotPlacement -> ShowS
$cshowsPrec :: Int -> SpotPlacement -> ShowS
Prelude.Show, forall x. Rep SpotPlacement x -> SpotPlacement
forall x. SpotPlacement -> Rep SpotPlacement x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SpotPlacement x -> SpotPlacement
$cfrom :: forall x. SpotPlacement -> Rep SpotPlacement x
Prelude.Generic)

-- |
-- Create a value of 'SpotPlacement' 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:
--
-- 'availabilityZone', 'spotPlacement_availabilityZone' - The Availability Zone.
--
-- [Spot Fleet only] To specify multiple Availability Zones, separate them
-- using commas; for example, \"us-west-2a, us-west-2b\".
--
-- 'groupName', 'spotPlacement_groupName' - The name of the placement group.
--
-- 'tenancy', 'spotPlacement_tenancy' - The tenancy of the instance (if the instance is running in a VPC). An
-- instance with a tenancy of @dedicated@ runs on single-tenant hardware.
-- The @host@ tenancy is not supported for Spot Instances.
newSpotPlacement ::
  SpotPlacement
newSpotPlacement :: SpotPlacement
newSpotPlacement =
  SpotPlacement'
    { $sel:availabilityZone:SpotPlacement' :: Maybe Text
availabilityZone = forall a. Maybe a
Prelude.Nothing,
      $sel:groupName:SpotPlacement' :: Maybe Text
groupName = forall a. Maybe a
Prelude.Nothing,
      $sel:tenancy:SpotPlacement' :: Maybe Tenancy
tenancy = forall a. Maybe a
Prelude.Nothing
    }

-- | The Availability Zone.
--
-- [Spot Fleet only] To specify multiple Availability Zones, separate them
-- using commas; for example, \"us-west-2a, us-west-2b\".
spotPlacement_availabilityZone :: Lens.Lens' SpotPlacement (Prelude.Maybe Prelude.Text)
spotPlacement_availabilityZone :: Lens' SpotPlacement (Maybe Text)
spotPlacement_availabilityZone = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SpotPlacement' {Maybe Text
availabilityZone :: Maybe Text
$sel:availabilityZone:SpotPlacement' :: SpotPlacement -> Maybe Text
availabilityZone} -> Maybe Text
availabilityZone) (\s :: SpotPlacement
s@SpotPlacement' {} Maybe Text
a -> SpotPlacement
s {$sel:availabilityZone:SpotPlacement' :: Maybe Text
availabilityZone = Maybe Text
a} :: SpotPlacement)

-- | The name of the placement group.
spotPlacement_groupName :: Lens.Lens' SpotPlacement (Prelude.Maybe Prelude.Text)
spotPlacement_groupName :: Lens' SpotPlacement (Maybe Text)
spotPlacement_groupName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SpotPlacement' {Maybe Text
groupName :: Maybe Text
$sel:groupName:SpotPlacement' :: SpotPlacement -> Maybe Text
groupName} -> Maybe Text
groupName) (\s :: SpotPlacement
s@SpotPlacement' {} Maybe Text
a -> SpotPlacement
s {$sel:groupName:SpotPlacement' :: Maybe Text
groupName = Maybe Text
a} :: SpotPlacement)

-- | The tenancy of the instance (if the instance is running in a VPC). An
-- instance with a tenancy of @dedicated@ runs on single-tenant hardware.
-- The @host@ tenancy is not supported for Spot Instances.
spotPlacement_tenancy :: Lens.Lens' SpotPlacement (Prelude.Maybe Tenancy)
spotPlacement_tenancy :: Lens' SpotPlacement (Maybe Tenancy)
spotPlacement_tenancy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SpotPlacement' {Maybe Tenancy
tenancy :: Maybe Tenancy
$sel:tenancy:SpotPlacement' :: SpotPlacement -> Maybe Tenancy
tenancy} -> Maybe Tenancy
tenancy) (\s :: SpotPlacement
s@SpotPlacement' {} Maybe Tenancy
a -> SpotPlacement
s {$sel:tenancy:SpotPlacement' :: Maybe Tenancy
tenancy = Maybe Tenancy
a} :: SpotPlacement)

instance Data.FromXML SpotPlacement where
  parseXML :: [Node] -> Either String SpotPlacement
parseXML [Node]
x =
    Maybe Text -> Maybe Text -> Maybe Tenancy -> SpotPlacement
SpotPlacement'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"availabilityZone")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"groupName")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"tenancy")

instance Prelude.Hashable SpotPlacement where
  hashWithSalt :: Int -> SpotPlacement -> Int
hashWithSalt Int
_salt SpotPlacement' {Maybe Text
Maybe Tenancy
tenancy :: Maybe Tenancy
groupName :: Maybe Text
availabilityZone :: Maybe Text
$sel:tenancy:SpotPlacement' :: SpotPlacement -> Maybe Tenancy
$sel:groupName:SpotPlacement' :: SpotPlacement -> Maybe Text
$sel:availabilityZone:SpotPlacement' :: SpotPlacement -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
availabilityZone
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
groupName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Tenancy
tenancy

instance Prelude.NFData SpotPlacement where
  rnf :: SpotPlacement -> ()
rnf SpotPlacement' {Maybe Text
Maybe Tenancy
tenancy :: Maybe Tenancy
groupName :: Maybe Text
availabilityZone :: Maybe Text
$sel:tenancy:SpotPlacement' :: SpotPlacement -> Maybe Tenancy
$sel:groupName:SpotPlacement' :: SpotPlacement -> Maybe Text
$sel:availabilityZone:SpotPlacement' :: SpotPlacement -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
availabilityZone
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
groupName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Tenancy
tenancy

instance Data.ToQuery SpotPlacement where
  toQuery :: SpotPlacement -> QueryString
toQuery SpotPlacement' {Maybe Text
Maybe Tenancy
tenancy :: Maybe Tenancy
groupName :: Maybe Text
availabilityZone :: Maybe Text
$sel:tenancy:SpotPlacement' :: SpotPlacement -> Maybe Tenancy
$sel:groupName:SpotPlacement' :: SpotPlacement -> Maybe Text
$sel:availabilityZone:SpotPlacement' :: SpotPlacement -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"AvailabilityZone" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
availabilityZone,
        ByteString
"GroupName" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
groupName,
        ByteString
"Tenancy" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Tenancy
tenancy
      ]