{-# 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.ImageBuilder.Types.Distribution
-- 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.ImageBuilder.Types.Distribution where

import qualified Amazonka.Core as Core
import Amazonka.ImageBuilder.Types.AmiDistributionConfiguration
import Amazonka.ImageBuilder.Types.ContainerDistributionConfiguration
import Amazonka.ImageBuilder.Types.LaunchTemplateConfiguration
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Defines the settings for a specific Region.
--
-- /See:/ 'newDistribution' smart constructor.
data Distribution = Distribution'
  { -- | The specific AMI settings; for example, launch permissions or AMI tags.
    Distribution -> Maybe AmiDistributionConfiguration
amiDistributionConfiguration :: Prelude.Maybe AmiDistributionConfiguration,
    -- | A group of launchTemplateConfiguration settings that apply to image
    -- distribution for specified accounts.
    Distribution -> Maybe (NonEmpty LaunchTemplateConfiguration)
launchTemplateConfigurations :: Prelude.Maybe (Prelude.NonEmpty LaunchTemplateConfiguration),
    -- | The License Manager Configuration to associate with the AMI in the
    -- specified Region.
    Distribution -> Maybe (NonEmpty Text)
licenseConfigurationArns :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | Container distribution settings for encryption, licensing, and sharing
    -- in a specific Region.
    Distribution -> Maybe ContainerDistributionConfiguration
containerDistributionConfiguration :: Prelude.Maybe ContainerDistributionConfiguration,
    -- | The target Region.
    Distribution -> Text
region :: Prelude.Text
  }
  deriving (Distribution -> Distribution -> Bool
(Distribution -> Distribution -> Bool)
-> (Distribution -> Distribution -> Bool) -> Eq Distribution
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Distribution -> Distribution -> Bool
$c/= :: Distribution -> Distribution -> Bool
== :: Distribution -> Distribution -> Bool
$c== :: Distribution -> Distribution -> Bool
Prelude.Eq, ReadPrec [Distribution]
ReadPrec Distribution
Int -> ReadS Distribution
ReadS [Distribution]
(Int -> ReadS Distribution)
-> ReadS [Distribution]
-> ReadPrec Distribution
-> ReadPrec [Distribution]
-> Read Distribution
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Distribution]
$creadListPrec :: ReadPrec [Distribution]
readPrec :: ReadPrec Distribution
$creadPrec :: ReadPrec Distribution
readList :: ReadS [Distribution]
$creadList :: ReadS [Distribution]
readsPrec :: Int -> ReadS Distribution
$creadsPrec :: Int -> ReadS Distribution
Prelude.Read, Int -> Distribution -> ShowS
[Distribution] -> ShowS
Distribution -> String
(Int -> Distribution -> ShowS)
-> (Distribution -> String)
-> ([Distribution] -> ShowS)
-> Show Distribution
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Distribution] -> ShowS
$cshowList :: [Distribution] -> ShowS
show :: Distribution -> String
$cshow :: Distribution -> String
showsPrec :: Int -> Distribution -> ShowS
$cshowsPrec :: Int -> Distribution -> ShowS
Prelude.Show, (forall x. Distribution -> Rep Distribution x)
-> (forall x. Rep Distribution x -> Distribution)
-> Generic Distribution
forall x. Rep Distribution x -> Distribution
forall x. Distribution -> Rep Distribution x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Distribution x -> Distribution
$cfrom :: forall x. Distribution -> Rep Distribution x
Prelude.Generic)

-- |
-- Create a value of 'Distribution' 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:
--
-- 'amiDistributionConfiguration', 'distribution_amiDistributionConfiguration' - The specific AMI settings; for example, launch permissions or AMI tags.
--
-- 'launchTemplateConfigurations', 'distribution_launchTemplateConfigurations' - A group of launchTemplateConfiguration settings that apply to image
-- distribution for specified accounts.
--
-- 'licenseConfigurationArns', 'distribution_licenseConfigurationArns' - The License Manager Configuration to associate with the AMI in the
-- specified Region.
--
-- 'containerDistributionConfiguration', 'distribution_containerDistributionConfiguration' - Container distribution settings for encryption, licensing, and sharing
-- in a specific Region.
--
-- 'region', 'distribution_region' - The target Region.
newDistribution ::
  -- | 'region'
  Prelude.Text ->
  Distribution
newDistribution :: Text -> Distribution
newDistribution Text
pRegion_ =
  Distribution' :: Maybe AmiDistributionConfiguration
-> Maybe (NonEmpty LaunchTemplateConfiguration)
-> Maybe (NonEmpty Text)
-> Maybe ContainerDistributionConfiguration
-> Text
-> Distribution
Distribution'
    { $sel:amiDistributionConfiguration:Distribution' :: Maybe AmiDistributionConfiguration
amiDistributionConfiguration =
        Maybe AmiDistributionConfiguration
forall a. Maybe a
Prelude.Nothing,
      $sel:launchTemplateConfigurations:Distribution' :: Maybe (NonEmpty LaunchTemplateConfiguration)
launchTemplateConfigurations = Maybe (NonEmpty LaunchTemplateConfiguration)
forall a. Maybe a
Prelude.Nothing,
      $sel:licenseConfigurationArns:Distribution' :: Maybe (NonEmpty Text)
licenseConfigurationArns = Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:containerDistributionConfiguration:Distribution' :: Maybe ContainerDistributionConfiguration
containerDistributionConfiguration = Maybe ContainerDistributionConfiguration
forall a. Maybe a
Prelude.Nothing,
      $sel:region:Distribution' :: Text
region = Text
pRegion_
    }

-- | The specific AMI settings; for example, launch permissions or AMI tags.
distribution_amiDistributionConfiguration :: Lens.Lens' Distribution (Prelude.Maybe AmiDistributionConfiguration)
distribution_amiDistributionConfiguration :: (Maybe AmiDistributionConfiguration
 -> f (Maybe AmiDistributionConfiguration))
-> Distribution -> f Distribution
distribution_amiDistributionConfiguration = (Distribution -> Maybe AmiDistributionConfiguration)
-> (Distribution
    -> Maybe AmiDistributionConfiguration -> Distribution)
-> Lens
     Distribution
     Distribution
     (Maybe AmiDistributionConfiguration)
     (Maybe AmiDistributionConfiguration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Distribution' {Maybe AmiDistributionConfiguration
amiDistributionConfiguration :: Maybe AmiDistributionConfiguration
$sel:amiDistributionConfiguration:Distribution' :: Distribution -> Maybe AmiDistributionConfiguration
amiDistributionConfiguration} -> Maybe AmiDistributionConfiguration
amiDistributionConfiguration) (\s :: Distribution
s@Distribution' {} Maybe AmiDistributionConfiguration
a -> Distribution
s {$sel:amiDistributionConfiguration:Distribution' :: Maybe AmiDistributionConfiguration
amiDistributionConfiguration = Maybe AmiDistributionConfiguration
a} :: Distribution)

-- | A group of launchTemplateConfiguration settings that apply to image
-- distribution for specified accounts.
distribution_launchTemplateConfigurations :: Lens.Lens' Distribution (Prelude.Maybe (Prelude.NonEmpty LaunchTemplateConfiguration))
distribution_launchTemplateConfigurations :: (Maybe (NonEmpty LaunchTemplateConfiguration)
 -> f (Maybe (NonEmpty LaunchTemplateConfiguration)))
-> Distribution -> f Distribution
distribution_launchTemplateConfigurations = (Distribution -> Maybe (NonEmpty LaunchTemplateConfiguration))
-> (Distribution
    -> Maybe (NonEmpty LaunchTemplateConfiguration) -> Distribution)
-> Lens
     Distribution
     Distribution
     (Maybe (NonEmpty LaunchTemplateConfiguration))
     (Maybe (NonEmpty LaunchTemplateConfiguration))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Distribution' {Maybe (NonEmpty LaunchTemplateConfiguration)
launchTemplateConfigurations :: Maybe (NonEmpty LaunchTemplateConfiguration)
$sel:launchTemplateConfigurations:Distribution' :: Distribution -> Maybe (NonEmpty LaunchTemplateConfiguration)
launchTemplateConfigurations} -> Maybe (NonEmpty LaunchTemplateConfiguration)
launchTemplateConfigurations) (\s :: Distribution
s@Distribution' {} Maybe (NonEmpty LaunchTemplateConfiguration)
a -> Distribution
s {$sel:launchTemplateConfigurations:Distribution' :: Maybe (NonEmpty LaunchTemplateConfiguration)
launchTemplateConfigurations = Maybe (NonEmpty LaunchTemplateConfiguration)
a} :: Distribution) ((Maybe (NonEmpty LaunchTemplateConfiguration)
  -> f (Maybe (NonEmpty LaunchTemplateConfiguration)))
 -> Distribution -> f Distribution)
-> ((Maybe (NonEmpty LaunchTemplateConfiguration)
     -> f (Maybe (NonEmpty LaunchTemplateConfiguration)))
    -> Maybe (NonEmpty LaunchTemplateConfiguration)
    -> f (Maybe (NonEmpty LaunchTemplateConfiguration)))
-> (Maybe (NonEmpty LaunchTemplateConfiguration)
    -> f (Maybe (NonEmpty LaunchTemplateConfiguration)))
-> Distribution
-> f Distribution
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty LaunchTemplateConfiguration)
  (NonEmpty LaunchTemplateConfiguration)
  (NonEmpty LaunchTemplateConfiguration)
  (NonEmpty LaunchTemplateConfiguration)
-> Iso
     (Maybe (NonEmpty LaunchTemplateConfiguration))
     (Maybe (NonEmpty LaunchTemplateConfiguration))
     (Maybe (NonEmpty LaunchTemplateConfiguration))
     (Maybe (NonEmpty LaunchTemplateConfiguration))
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 AnIso
  (NonEmpty LaunchTemplateConfiguration)
  (NonEmpty LaunchTemplateConfiguration)
  (NonEmpty LaunchTemplateConfiguration)
  (NonEmpty LaunchTemplateConfiguration)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The License Manager Configuration to associate with the AMI in the
-- specified Region.
distribution_licenseConfigurationArns :: Lens.Lens' Distribution (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
distribution_licenseConfigurationArns :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> Distribution -> f Distribution
distribution_licenseConfigurationArns = (Distribution -> Maybe (NonEmpty Text))
-> (Distribution -> Maybe (NonEmpty Text) -> Distribution)
-> Lens
     Distribution
     Distribution
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Distribution' {Maybe (NonEmpty Text)
licenseConfigurationArns :: Maybe (NonEmpty Text)
$sel:licenseConfigurationArns:Distribution' :: Distribution -> Maybe (NonEmpty Text)
licenseConfigurationArns} -> Maybe (NonEmpty Text)
licenseConfigurationArns) (\s :: Distribution
s@Distribution' {} Maybe (NonEmpty Text)
a -> Distribution
s {$sel:licenseConfigurationArns:Distribution' :: Maybe (NonEmpty Text)
licenseConfigurationArns = Maybe (NonEmpty Text)
a} :: Distribution) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> Distribution -> f Distribution)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> Distribution
-> f Distribution
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
-> Iso
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
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 AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Container distribution settings for encryption, licensing, and sharing
-- in a specific Region.
distribution_containerDistributionConfiguration :: Lens.Lens' Distribution (Prelude.Maybe ContainerDistributionConfiguration)
distribution_containerDistributionConfiguration :: (Maybe ContainerDistributionConfiguration
 -> f (Maybe ContainerDistributionConfiguration))
-> Distribution -> f Distribution
distribution_containerDistributionConfiguration = (Distribution -> Maybe ContainerDistributionConfiguration)
-> (Distribution
    -> Maybe ContainerDistributionConfiguration -> Distribution)
-> Lens
     Distribution
     Distribution
     (Maybe ContainerDistributionConfiguration)
     (Maybe ContainerDistributionConfiguration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Distribution' {Maybe ContainerDistributionConfiguration
containerDistributionConfiguration :: Maybe ContainerDistributionConfiguration
$sel:containerDistributionConfiguration:Distribution' :: Distribution -> Maybe ContainerDistributionConfiguration
containerDistributionConfiguration} -> Maybe ContainerDistributionConfiguration
containerDistributionConfiguration) (\s :: Distribution
s@Distribution' {} Maybe ContainerDistributionConfiguration
a -> Distribution
s {$sel:containerDistributionConfiguration:Distribution' :: Maybe ContainerDistributionConfiguration
containerDistributionConfiguration = Maybe ContainerDistributionConfiguration
a} :: Distribution)

-- | The target Region.
distribution_region :: Lens.Lens' Distribution Prelude.Text
distribution_region :: (Text -> f Text) -> Distribution -> f Distribution
distribution_region = (Distribution -> Text)
-> (Distribution -> Text -> Distribution)
-> Lens Distribution Distribution Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Distribution' {Text
region :: Text
$sel:region:Distribution' :: Distribution -> Text
region} -> Text
region) (\s :: Distribution
s@Distribution' {} Text
a -> Distribution
s {$sel:region:Distribution' :: Text
region = Text
a} :: Distribution)

instance Core.FromJSON Distribution where
  parseJSON :: Value -> Parser Distribution
parseJSON =
    String
-> (Object -> Parser Distribution) -> Value -> Parser Distribution
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Distribution"
      ( \Object
x ->
          Maybe AmiDistributionConfiguration
-> Maybe (NonEmpty LaunchTemplateConfiguration)
-> Maybe (NonEmpty Text)
-> Maybe ContainerDistributionConfiguration
-> Text
-> Distribution
Distribution'
            (Maybe AmiDistributionConfiguration
 -> Maybe (NonEmpty LaunchTemplateConfiguration)
 -> Maybe (NonEmpty Text)
 -> Maybe ContainerDistributionConfiguration
 -> Text
 -> Distribution)
-> Parser (Maybe AmiDistributionConfiguration)
-> Parser
     (Maybe (NonEmpty LaunchTemplateConfiguration)
      -> Maybe (NonEmpty Text)
      -> Maybe ContainerDistributionConfiguration
      -> Text
      -> Distribution)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe AmiDistributionConfiguration)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"amiDistributionConfiguration")
            Parser
  (Maybe (NonEmpty LaunchTemplateConfiguration)
   -> Maybe (NonEmpty Text)
   -> Maybe ContainerDistributionConfiguration
   -> Text
   -> Distribution)
-> Parser (Maybe (NonEmpty LaunchTemplateConfiguration))
-> Parser
     (Maybe (NonEmpty Text)
      -> Maybe ContainerDistributionConfiguration
      -> Text
      -> Distribution)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object
-> Text -> Parser (Maybe (NonEmpty LaunchTemplateConfiguration))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"launchTemplateConfigurations")
            Parser
  (Maybe (NonEmpty Text)
   -> Maybe ContainerDistributionConfiguration
   -> Text
   -> Distribution)
-> Parser (Maybe (NonEmpty Text))
-> Parser
     (Maybe ContainerDistributionConfiguration -> Text -> Distribution)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (NonEmpty Text))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"licenseConfigurationArns")
            Parser
  (Maybe ContainerDistributionConfiguration -> Text -> Distribution)
-> Parser (Maybe ContainerDistributionConfiguration)
-> Parser (Text -> Distribution)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe ContainerDistributionConfiguration)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"containerDistributionConfiguration")
            Parser (Text -> Distribution) -> Parser Text -> Parser Distribution
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"region")
      )

instance Prelude.Hashable Distribution

instance Prelude.NFData Distribution

instance Core.ToJSON Distribution where
  toJSON :: Distribution -> Value
toJSON Distribution' {Maybe (NonEmpty Text)
Maybe (NonEmpty LaunchTemplateConfiguration)
Maybe AmiDistributionConfiguration
Maybe ContainerDistributionConfiguration
Text
region :: Text
containerDistributionConfiguration :: Maybe ContainerDistributionConfiguration
licenseConfigurationArns :: Maybe (NonEmpty Text)
launchTemplateConfigurations :: Maybe (NonEmpty LaunchTemplateConfiguration)
amiDistributionConfiguration :: Maybe AmiDistributionConfiguration
$sel:region:Distribution' :: Distribution -> Text
$sel:containerDistributionConfiguration:Distribution' :: Distribution -> Maybe ContainerDistributionConfiguration
$sel:licenseConfigurationArns:Distribution' :: Distribution -> Maybe (NonEmpty Text)
$sel:launchTemplateConfigurations:Distribution' :: Distribution -> Maybe (NonEmpty LaunchTemplateConfiguration)
$sel:amiDistributionConfiguration:Distribution' :: Distribution -> Maybe AmiDistributionConfiguration
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"amiDistributionConfiguration" Text -> AmiDistributionConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (AmiDistributionConfiguration -> Pair)
-> Maybe AmiDistributionConfiguration -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe AmiDistributionConfiguration
amiDistributionConfiguration,
            (Text
"launchTemplateConfigurations" Text -> NonEmpty LaunchTemplateConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (NonEmpty LaunchTemplateConfiguration -> Pair)
-> Maybe (NonEmpty LaunchTemplateConfiguration) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty LaunchTemplateConfiguration)
launchTemplateConfigurations,
            (Text
"licenseConfigurationArns" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (NonEmpty Text -> Pair) -> Maybe (NonEmpty Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Text)
licenseConfigurationArns,
            (Text
"containerDistributionConfiguration" Text -> ContainerDistributionConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (ContainerDistributionConfiguration -> Pair)
-> Maybe ContainerDistributionConfiguration -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ContainerDistributionConfiguration
containerDistributionConfiguration,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"region" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
region)
          ]
      )