{-# 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.ECS.Types.PortMapping
-- 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.ECS.Types.PortMapping where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.ECS.Types.ApplicationProtocol
import Amazonka.ECS.Types.TransportProtocol
import qualified Amazonka.Prelude as Prelude

-- | Port mappings allow containers to access ports on the host container
-- instance to send or receive traffic. Port mappings are specified as part
-- of the container definition.
--
-- If you use containers in a task with the @awsvpc@ or @host@ network
-- mode, specify the exposed ports using @containerPort@. The @hostPort@
-- can be left blank or it must be the same value as the @containerPort@.
--
-- You can\'t expose the same container port for multiple protocols. If you
-- attempt this, an error is returned.
--
-- After a task reaches the @RUNNING@ status, manual and automatic host and
-- container port assignments are visible in the @networkBindings@ section
-- of DescribeTasks API responses.
--
-- /See:/ 'newPortMapping' smart constructor.
data PortMapping = PortMapping'
  { -- | The application protocol that\'s used for the port mapping. This
    -- parameter only applies to Service Connect. We recommend that you set
    -- this parameter to be consistent with the protocol that your application
    -- uses. If you set this parameter, Amazon ECS adds protocol-specific
    -- connection handling to the Service Connect proxy. If you set this
    -- parameter, Amazon ECS adds protocol-specific telemetry in the Amazon ECS
    -- console and CloudWatch.
    --
    -- If you don\'t set a value for this parameter, then TCP is used. However,
    -- Amazon ECS doesn\'t add protocol-specific telemetry for TCP.
    --
    -- Tasks that run in a namespace can use short names to connect to services
    -- in the namespace. Tasks can connect to services across all of the
    -- clusters in the namespace. Tasks connect through a managed proxy
    -- container that collects logs and metrics for increased visibility. Only
    -- the tasks that Amazon ECS services create are supported with Service
    -- Connect. For more information, see
    -- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-connect.html Service Connect>
    -- in the /Amazon Elastic Container Service Developer Guide/.
    PortMapping -> Maybe ApplicationProtocol
appProtocol :: Prelude.Maybe ApplicationProtocol,
    -- | The port number on the container that\'s bound to the user-specified or
    -- automatically assigned host port.
    --
    -- If you use containers in a task with the @awsvpc@ or @host@ network
    -- mode, specify the exposed ports using @containerPort@.
    --
    -- If you use containers in a task with the @bridge@ network mode and you
    -- specify a container port and not a host port, your container
    -- automatically receives a host port in the ephemeral port range. For more
    -- information, see @hostPort@. Port mappings that are automatically
    -- assigned in this way do not count toward the 100 reserved ports limit of
    -- a container instance.
    PortMapping -> Maybe Int
containerPort :: Prelude.Maybe Prelude.Int,
    -- | The port number range on the container that\'s bound to the dynamically
    -- mapped host port range.
    --
    -- The following rules apply when you specify a @containerPortRange@:
    --
    -- -   You must use either the @bridge@ network mode or the @awsvpc@
    --     network mode.
    --
    -- -   This parameter is available for both the EC2 and Fargate launch
    --     types.
    --
    -- -   This parameter is available for both the Linux and Windows operating
    --     systems.
    --
    -- -   The container instance must have at least version 1.67.0 of the
    --     container agent and at least version 1.67.0-1 of the @ecs-init@
    --     package
    --
    -- -   You can specify a maximum of 100 port ranges per container.
    --
    -- -   You do not specify a @hostPortRange@. The value of the
    --     @hostPortRange@ is set as follows:
    --
    --     -   For containers in a task with the @awsvpc@ network mode, the
    --         @hostPort@ is set to the same value as the @containerPort@. This
    --         is a static mapping strategy.
    --
    --     -   For containers in a task with the @bridge@ network mode, the
    --         Amazon ECS agent finds open host ports from the default
    --         ephemeral range and passes it to docker to bind them to the
    --         container ports.
    --
    -- -   The @containerPortRange@ valid values are between 1 and 65535.
    --
    -- -   A port can only be included in one port mapping per container.
    --
    -- -   You cannot specify overlapping port ranges.
    --
    -- -   The first port in the range must be less than last port in the
    --     range.
    --
    -- -   Docker recommends that you turn off the docker-proxy in the Docker
    --     daemon config file when you have a large number of ports.
    --
    --     For more information, see
    --     <https://github.com/moby/moby/issues/11185 Issue #11185> on the
    --     Github website.
    --
    --     For information about how to turn off the docker-proxy in the Docker
    --     daemon config file, see
    --     <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/bootstrap_container_instance.html#bootstrap_docker_daemon Docker daemon>
    --     in the /Amazon ECS Developer Guide/.
    --
    -- You can call
    -- <https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DescribeTasks.html DescribeTasks>
    -- to view the @hostPortRange@ which are the host ports that are bound to
    -- the container ports.
    PortMapping -> Maybe Text
containerPortRange :: Prelude.Maybe Prelude.Text,
    -- | The port number on the container instance to reserve for your container.
    --
    -- If you specify a @containerPortRange@, leave this field empty and the
    -- value of the @hostPort@ is set as follows:
    --
    -- -   For containers in a task with the @awsvpc@ network mode, the
    --     @hostPort@ is set to the same value as the @containerPort@. This is
    --     a static mapping strategy.
    --
    -- -   For containers in a task with the @bridge@ network mode, the Amazon
    --     ECS agent finds open ports on the host and automaticaly binds them
    --     to the container ports. This is a dynamic mapping strategy.
    --
    -- If you use containers in a task with the @awsvpc@ or @host@ network
    -- mode, the @hostPort@ can either be left blank or set to the same value
    -- as the @containerPort@.
    --
    -- If you use containers in a task with the @bridge@ network mode, you can
    -- specify a non-reserved host port for your container port mapping, or you
    -- can omit the @hostPort@ (or set it to @0@) while specifying a
    -- @containerPort@ and your container automatically receives a port in the
    -- ephemeral port range for your container instance operating system and
    -- Docker version.
    --
    -- The default ephemeral port range for Docker version 1.6.0 and later is
    -- listed on the instance under
    -- @\/proc\/sys\/net\/ipv4\/ip_local_port_range@. If this kernel parameter
    -- is unavailable, the default ephemeral port range from 49153 through
    -- 65535 is used. Do not attempt to specify a host port in the ephemeral
    -- port range as these are reserved for automatic assignment. In general,
    -- ports below 32768 are outside of the ephemeral port range.
    --
    -- The default reserved ports are 22 for SSH, the Docker ports 2375 and
    -- 2376, and the Amazon ECS container agent ports 51678-51680. Any host
    -- port that was previously specified in a running task is also reserved
    -- while the task is running. That is, after a task stops, the host port is
    -- released. The current reserved ports are displayed in the
    -- @remainingResources@ of DescribeContainerInstances output. A container
    -- instance can have up to 100 reserved ports at a time. This number
    -- includes the default reserved ports. Automatically assigned ports
    -- aren\'t included in the 100 reserved ports quota.
    PortMapping -> Maybe Int
hostPort :: Prelude.Maybe Prelude.Int,
    -- | The name that\'s used for the port mapping. This parameter only applies
    -- to Service Connect. This parameter is the name that you use in the
    -- @serviceConnectConfiguration@ of a service. The name can include up to
    -- 64 characters. The characters can include lowercase letters, numbers,
    -- underscores (_), and hyphens (-). The name can\'t start with a hyphen.
    --
    -- For more information, see
    -- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-connect.html Service Connect>
    -- in the /Amazon Elastic Container Service Developer Guide/.
    PortMapping -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The protocol used for the port mapping. Valid values are @tcp@ and
    -- @udp@. The default is @tcp@.
    PortMapping -> Maybe TransportProtocol
protocol :: Prelude.Maybe TransportProtocol
  }
  deriving (PortMapping -> PortMapping -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PortMapping -> PortMapping -> Bool
$c/= :: PortMapping -> PortMapping -> Bool
== :: PortMapping -> PortMapping -> Bool
$c== :: PortMapping -> PortMapping -> Bool
Prelude.Eq, ReadPrec [PortMapping]
ReadPrec PortMapping
Int -> ReadS PortMapping
ReadS [PortMapping]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PortMapping]
$creadListPrec :: ReadPrec [PortMapping]
readPrec :: ReadPrec PortMapping
$creadPrec :: ReadPrec PortMapping
readList :: ReadS [PortMapping]
$creadList :: ReadS [PortMapping]
readsPrec :: Int -> ReadS PortMapping
$creadsPrec :: Int -> ReadS PortMapping
Prelude.Read, Int -> PortMapping -> ShowS
[PortMapping] -> ShowS
PortMapping -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PortMapping] -> ShowS
$cshowList :: [PortMapping] -> ShowS
show :: PortMapping -> String
$cshow :: PortMapping -> String
showsPrec :: Int -> PortMapping -> ShowS
$cshowsPrec :: Int -> PortMapping -> ShowS
Prelude.Show, forall x. Rep PortMapping x -> PortMapping
forall x. PortMapping -> Rep PortMapping x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PortMapping x -> PortMapping
$cfrom :: forall x. PortMapping -> Rep PortMapping x
Prelude.Generic)

-- |
-- Create a value of 'PortMapping' 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:
--
-- 'appProtocol', 'portMapping_appProtocol' - The application protocol that\'s used for the port mapping. This
-- parameter only applies to Service Connect. We recommend that you set
-- this parameter to be consistent with the protocol that your application
-- uses. If you set this parameter, Amazon ECS adds protocol-specific
-- connection handling to the Service Connect proxy. If you set this
-- parameter, Amazon ECS adds protocol-specific telemetry in the Amazon ECS
-- console and CloudWatch.
--
-- If you don\'t set a value for this parameter, then TCP is used. However,
-- Amazon ECS doesn\'t add protocol-specific telemetry for TCP.
--
-- Tasks that run in a namespace can use short names to connect to services
-- in the namespace. Tasks can connect to services across all of the
-- clusters in the namespace. Tasks connect through a managed proxy
-- container that collects logs and metrics for increased visibility. Only
-- the tasks that Amazon ECS services create are supported with Service
-- Connect. For more information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-connect.html Service Connect>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- 'containerPort', 'portMapping_containerPort' - The port number on the container that\'s bound to the user-specified or
-- automatically assigned host port.
--
-- If you use containers in a task with the @awsvpc@ or @host@ network
-- mode, specify the exposed ports using @containerPort@.
--
-- If you use containers in a task with the @bridge@ network mode and you
-- specify a container port and not a host port, your container
-- automatically receives a host port in the ephemeral port range. For more
-- information, see @hostPort@. Port mappings that are automatically
-- assigned in this way do not count toward the 100 reserved ports limit of
-- a container instance.
--
-- 'containerPortRange', 'portMapping_containerPortRange' - The port number range on the container that\'s bound to the dynamically
-- mapped host port range.
--
-- The following rules apply when you specify a @containerPortRange@:
--
-- -   You must use either the @bridge@ network mode or the @awsvpc@
--     network mode.
--
-- -   This parameter is available for both the EC2 and Fargate launch
--     types.
--
-- -   This parameter is available for both the Linux and Windows operating
--     systems.
--
-- -   The container instance must have at least version 1.67.0 of the
--     container agent and at least version 1.67.0-1 of the @ecs-init@
--     package
--
-- -   You can specify a maximum of 100 port ranges per container.
--
-- -   You do not specify a @hostPortRange@. The value of the
--     @hostPortRange@ is set as follows:
--
--     -   For containers in a task with the @awsvpc@ network mode, the
--         @hostPort@ is set to the same value as the @containerPort@. This
--         is a static mapping strategy.
--
--     -   For containers in a task with the @bridge@ network mode, the
--         Amazon ECS agent finds open host ports from the default
--         ephemeral range and passes it to docker to bind them to the
--         container ports.
--
-- -   The @containerPortRange@ valid values are between 1 and 65535.
--
-- -   A port can only be included in one port mapping per container.
--
-- -   You cannot specify overlapping port ranges.
--
-- -   The first port in the range must be less than last port in the
--     range.
--
-- -   Docker recommends that you turn off the docker-proxy in the Docker
--     daemon config file when you have a large number of ports.
--
--     For more information, see
--     <https://github.com/moby/moby/issues/11185 Issue #11185> on the
--     Github website.
--
--     For information about how to turn off the docker-proxy in the Docker
--     daemon config file, see
--     <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/bootstrap_container_instance.html#bootstrap_docker_daemon Docker daemon>
--     in the /Amazon ECS Developer Guide/.
--
-- You can call
-- <https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DescribeTasks.html DescribeTasks>
-- to view the @hostPortRange@ which are the host ports that are bound to
-- the container ports.
--
-- 'hostPort', 'portMapping_hostPort' - The port number on the container instance to reserve for your container.
--
-- If you specify a @containerPortRange@, leave this field empty and the
-- value of the @hostPort@ is set as follows:
--
-- -   For containers in a task with the @awsvpc@ network mode, the
--     @hostPort@ is set to the same value as the @containerPort@. This is
--     a static mapping strategy.
--
-- -   For containers in a task with the @bridge@ network mode, the Amazon
--     ECS agent finds open ports on the host and automaticaly binds them
--     to the container ports. This is a dynamic mapping strategy.
--
-- If you use containers in a task with the @awsvpc@ or @host@ network
-- mode, the @hostPort@ can either be left blank or set to the same value
-- as the @containerPort@.
--
-- If you use containers in a task with the @bridge@ network mode, you can
-- specify a non-reserved host port for your container port mapping, or you
-- can omit the @hostPort@ (or set it to @0@) while specifying a
-- @containerPort@ and your container automatically receives a port in the
-- ephemeral port range for your container instance operating system and
-- Docker version.
--
-- The default ephemeral port range for Docker version 1.6.0 and later is
-- listed on the instance under
-- @\/proc\/sys\/net\/ipv4\/ip_local_port_range@. If this kernel parameter
-- is unavailable, the default ephemeral port range from 49153 through
-- 65535 is used. Do not attempt to specify a host port in the ephemeral
-- port range as these are reserved for automatic assignment. In general,
-- ports below 32768 are outside of the ephemeral port range.
--
-- The default reserved ports are 22 for SSH, the Docker ports 2375 and
-- 2376, and the Amazon ECS container agent ports 51678-51680. Any host
-- port that was previously specified in a running task is also reserved
-- while the task is running. That is, after a task stops, the host port is
-- released. The current reserved ports are displayed in the
-- @remainingResources@ of DescribeContainerInstances output. A container
-- instance can have up to 100 reserved ports at a time. This number
-- includes the default reserved ports. Automatically assigned ports
-- aren\'t included in the 100 reserved ports quota.
--
-- 'name', 'portMapping_name' - The name that\'s used for the port mapping. This parameter only applies
-- to Service Connect. This parameter is the name that you use in the
-- @serviceConnectConfiguration@ of a service. The name can include up to
-- 64 characters. The characters can include lowercase letters, numbers,
-- underscores (_), and hyphens (-). The name can\'t start with a hyphen.
--
-- For more information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-connect.html Service Connect>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- 'protocol', 'portMapping_protocol' - The protocol used for the port mapping. Valid values are @tcp@ and
-- @udp@. The default is @tcp@.
newPortMapping ::
  PortMapping
newPortMapping :: PortMapping
newPortMapping =
  PortMapping'
    { $sel:appProtocol:PortMapping' :: Maybe ApplicationProtocol
appProtocol = forall a. Maybe a
Prelude.Nothing,
      $sel:containerPort:PortMapping' :: Maybe Int
containerPort = forall a. Maybe a
Prelude.Nothing,
      $sel:containerPortRange:PortMapping' :: Maybe Text
containerPortRange = forall a. Maybe a
Prelude.Nothing,
      $sel:hostPort:PortMapping' :: Maybe Int
hostPort = forall a. Maybe a
Prelude.Nothing,
      $sel:name:PortMapping' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing,
      $sel:protocol:PortMapping' :: Maybe TransportProtocol
protocol = forall a. Maybe a
Prelude.Nothing
    }

-- | The application protocol that\'s used for the port mapping. This
-- parameter only applies to Service Connect. We recommend that you set
-- this parameter to be consistent with the protocol that your application
-- uses. If you set this parameter, Amazon ECS adds protocol-specific
-- connection handling to the Service Connect proxy. If you set this
-- parameter, Amazon ECS adds protocol-specific telemetry in the Amazon ECS
-- console and CloudWatch.
--
-- If you don\'t set a value for this parameter, then TCP is used. However,
-- Amazon ECS doesn\'t add protocol-specific telemetry for TCP.
--
-- Tasks that run in a namespace can use short names to connect to services
-- in the namespace. Tasks can connect to services across all of the
-- clusters in the namespace. Tasks connect through a managed proxy
-- container that collects logs and metrics for increased visibility. Only
-- the tasks that Amazon ECS services create are supported with Service
-- Connect. For more information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-connect.html Service Connect>
-- in the /Amazon Elastic Container Service Developer Guide/.
portMapping_appProtocol :: Lens.Lens' PortMapping (Prelude.Maybe ApplicationProtocol)
portMapping_appProtocol :: Lens' PortMapping (Maybe ApplicationProtocol)
portMapping_appProtocol = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortMapping' {Maybe ApplicationProtocol
appProtocol :: Maybe ApplicationProtocol
$sel:appProtocol:PortMapping' :: PortMapping -> Maybe ApplicationProtocol
appProtocol} -> Maybe ApplicationProtocol
appProtocol) (\s :: PortMapping
s@PortMapping' {} Maybe ApplicationProtocol
a -> PortMapping
s {$sel:appProtocol:PortMapping' :: Maybe ApplicationProtocol
appProtocol = Maybe ApplicationProtocol
a} :: PortMapping)

-- | The port number on the container that\'s bound to the user-specified or
-- automatically assigned host port.
--
-- If you use containers in a task with the @awsvpc@ or @host@ network
-- mode, specify the exposed ports using @containerPort@.
--
-- If you use containers in a task with the @bridge@ network mode and you
-- specify a container port and not a host port, your container
-- automatically receives a host port in the ephemeral port range. For more
-- information, see @hostPort@. Port mappings that are automatically
-- assigned in this way do not count toward the 100 reserved ports limit of
-- a container instance.
portMapping_containerPort :: Lens.Lens' PortMapping (Prelude.Maybe Prelude.Int)
portMapping_containerPort :: Lens' PortMapping (Maybe Int)
portMapping_containerPort = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortMapping' {Maybe Int
containerPort :: Maybe Int
$sel:containerPort:PortMapping' :: PortMapping -> Maybe Int
containerPort} -> Maybe Int
containerPort) (\s :: PortMapping
s@PortMapping' {} Maybe Int
a -> PortMapping
s {$sel:containerPort:PortMapping' :: Maybe Int
containerPort = Maybe Int
a} :: PortMapping)

-- | The port number range on the container that\'s bound to the dynamically
-- mapped host port range.
--
-- The following rules apply when you specify a @containerPortRange@:
--
-- -   You must use either the @bridge@ network mode or the @awsvpc@
--     network mode.
--
-- -   This parameter is available for both the EC2 and Fargate launch
--     types.
--
-- -   This parameter is available for both the Linux and Windows operating
--     systems.
--
-- -   The container instance must have at least version 1.67.0 of the
--     container agent and at least version 1.67.0-1 of the @ecs-init@
--     package
--
-- -   You can specify a maximum of 100 port ranges per container.
--
-- -   You do not specify a @hostPortRange@. The value of the
--     @hostPortRange@ is set as follows:
--
--     -   For containers in a task with the @awsvpc@ network mode, the
--         @hostPort@ is set to the same value as the @containerPort@. This
--         is a static mapping strategy.
--
--     -   For containers in a task with the @bridge@ network mode, the
--         Amazon ECS agent finds open host ports from the default
--         ephemeral range and passes it to docker to bind them to the
--         container ports.
--
-- -   The @containerPortRange@ valid values are between 1 and 65535.
--
-- -   A port can only be included in one port mapping per container.
--
-- -   You cannot specify overlapping port ranges.
--
-- -   The first port in the range must be less than last port in the
--     range.
--
-- -   Docker recommends that you turn off the docker-proxy in the Docker
--     daemon config file when you have a large number of ports.
--
--     For more information, see
--     <https://github.com/moby/moby/issues/11185 Issue #11185> on the
--     Github website.
--
--     For information about how to turn off the docker-proxy in the Docker
--     daemon config file, see
--     <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/bootstrap_container_instance.html#bootstrap_docker_daemon Docker daemon>
--     in the /Amazon ECS Developer Guide/.
--
-- You can call
-- <https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DescribeTasks.html DescribeTasks>
-- to view the @hostPortRange@ which are the host ports that are bound to
-- the container ports.
portMapping_containerPortRange :: Lens.Lens' PortMapping (Prelude.Maybe Prelude.Text)
portMapping_containerPortRange :: Lens' PortMapping (Maybe Text)
portMapping_containerPortRange = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortMapping' {Maybe Text
containerPortRange :: Maybe Text
$sel:containerPortRange:PortMapping' :: PortMapping -> Maybe Text
containerPortRange} -> Maybe Text
containerPortRange) (\s :: PortMapping
s@PortMapping' {} Maybe Text
a -> PortMapping
s {$sel:containerPortRange:PortMapping' :: Maybe Text
containerPortRange = Maybe Text
a} :: PortMapping)

-- | The port number on the container instance to reserve for your container.
--
-- If you specify a @containerPortRange@, leave this field empty and the
-- value of the @hostPort@ is set as follows:
--
-- -   For containers in a task with the @awsvpc@ network mode, the
--     @hostPort@ is set to the same value as the @containerPort@. This is
--     a static mapping strategy.
--
-- -   For containers in a task with the @bridge@ network mode, the Amazon
--     ECS agent finds open ports on the host and automaticaly binds them
--     to the container ports. This is a dynamic mapping strategy.
--
-- If you use containers in a task with the @awsvpc@ or @host@ network
-- mode, the @hostPort@ can either be left blank or set to the same value
-- as the @containerPort@.
--
-- If you use containers in a task with the @bridge@ network mode, you can
-- specify a non-reserved host port for your container port mapping, or you
-- can omit the @hostPort@ (or set it to @0@) while specifying a
-- @containerPort@ and your container automatically receives a port in the
-- ephemeral port range for your container instance operating system and
-- Docker version.
--
-- The default ephemeral port range for Docker version 1.6.0 and later is
-- listed on the instance under
-- @\/proc\/sys\/net\/ipv4\/ip_local_port_range@. If this kernel parameter
-- is unavailable, the default ephemeral port range from 49153 through
-- 65535 is used. Do not attempt to specify a host port in the ephemeral
-- port range as these are reserved for automatic assignment. In general,
-- ports below 32768 are outside of the ephemeral port range.
--
-- The default reserved ports are 22 for SSH, the Docker ports 2375 and
-- 2376, and the Amazon ECS container agent ports 51678-51680. Any host
-- port that was previously specified in a running task is also reserved
-- while the task is running. That is, after a task stops, the host port is
-- released. The current reserved ports are displayed in the
-- @remainingResources@ of DescribeContainerInstances output. A container
-- instance can have up to 100 reserved ports at a time. This number
-- includes the default reserved ports. Automatically assigned ports
-- aren\'t included in the 100 reserved ports quota.
portMapping_hostPort :: Lens.Lens' PortMapping (Prelude.Maybe Prelude.Int)
portMapping_hostPort :: Lens' PortMapping (Maybe Int)
portMapping_hostPort = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortMapping' {Maybe Int
hostPort :: Maybe Int
$sel:hostPort:PortMapping' :: PortMapping -> Maybe Int
hostPort} -> Maybe Int
hostPort) (\s :: PortMapping
s@PortMapping' {} Maybe Int
a -> PortMapping
s {$sel:hostPort:PortMapping' :: Maybe Int
hostPort = Maybe Int
a} :: PortMapping)

-- | The name that\'s used for the port mapping. This parameter only applies
-- to Service Connect. This parameter is the name that you use in the
-- @serviceConnectConfiguration@ of a service. The name can include up to
-- 64 characters. The characters can include lowercase letters, numbers,
-- underscores (_), and hyphens (-). The name can\'t start with a hyphen.
--
-- For more information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-connect.html Service Connect>
-- in the /Amazon Elastic Container Service Developer Guide/.
portMapping_name :: Lens.Lens' PortMapping (Prelude.Maybe Prelude.Text)
portMapping_name :: Lens' PortMapping (Maybe Text)
portMapping_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortMapping' {Maybe Text
name :: Maybe Text
$sel:name:PortMapping' :: PortMapping -> Maybe Text
name} -> Maybe Text
name) (\s :: PortMapping
s@PortMapping' {} Maybe Text
a -> PortMapping
s {$sel:name:PortMapping' :: Maybe Text
name = Maybe Text
a} :: PortMapping)

-- | The protocol used for the port mapping. Valid values are @tcp@ and
-- @udp@. The default is @tcp@.
portMapping_protocol :: Lens.Lens' PortMapping (Prelude.Maybe TransportProtocol)
portMapping_protocol :: Lens' PortMapping (Maybe TransportProtocol)
portMapping_protocol = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PortMapping' {Maybe TransportProtocol
protocol :: Maybe TransportProtocol
$sel:protocol:PortMapping' :: PortMapping -> Maybe TransportProtocol
protocol} -> Maybe TransportProtocol
protocol) (\s :: PortMapping
s@PortMapping' {} Maybe TransportProtocol
a -> PortMapping
s {$sel:protocol:PortMapping' :: Maybe TransportProtocol
protocol = Maybe TransportProtocol
a} :: PortMapping)

instance Data.FromJSON PortMapping where
  parseJSON :: Value -> Parser PortMapping
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"PortMapping"
      ( \Object
x ->
          Maybe ApplicationProtocol
-> Maybe Int
-> Maybe Text
-> Maybe Int
-> Maybe Text
-> Maybe TransportProtocol
-> PortMapping
PortMapping'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"appProtocol")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"containerPort")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"containerPortRange")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"hostPort")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"name")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"protocol")
      )

instance Prelude.Hashable PortMapping where
  hashWithSalt :: Int -> PortMapping -> Int
hashWithSalt Int
_salt PortMapping' {Maybe Int
Maybe Text
Maybe ApplicationProtocol
Maybe TransportProtocol
protocol :: Maybe TransportProtocol
name :: Maybe Text
hostPort :: Maybe Int
containerPortRange :: Maybe Text
containerPort :: Maybe Int
appProtocol :: Maybe ApplicationProtocol
$sel:protocol:PortMapping' :: PortMapping -> Maybe TransportProtocol
$sel:name:PortMapping' :: PortMapping -> Maybe Text
$sel:hostPort:PortMapping' :: PortMapping -> Maybe Int
$sel:containerPortRange:PortMapping' :: PortMapping -> Maybe Text
$sel:containerPort:PortMapping' :: PortMapping -> Maybe Int
$sel:appProtocol:PortMapping' :: PortMapping -> Maybe ApplicationProtocol
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ApplicationProtocol
appProtocol
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
containerPort
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
containerPortRange
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
hostPort
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe TransportProtocol
protocol

instance Prelude.NFData PortMapping where
  rnf :: PortMapping -> ()
rnf PortMapping' {Maybe Int
Maybe Text
Maybe ApplicationProtocol
Maybe TransportProtocol
protocol :: Maybe TransportProtocol
name :: Maybe Text
hostPort :: Maybe Int
containerPortRange :: Maybe Text
containerPort :: Maybe Int
appProtocol :: Maybe ApplicationProtocol
$sel:protocol:PortMapping' :: PortMapping -> Maybe TransportProtocol
$sel:name:PortMapping' :: PortMapping -> Maybe Text
$sel:hostPort:PortMapping' :: PortMapping -> Maybe Int
$sel:containerPortRange:PortMapping' :: PortMapping -> Maybe Text
$sel:containerPort:PortMapping' :: PortMapping -> Maybe Int
$sel:appProtocol:PortMapping' :: PortMapping -> Maybe ApplicationProtocol
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ApplicationProtocol
appProtocol
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
containerPort
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
containerPortRange
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
hostPort
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe TransportProtocol
protocol

instance Data.ToJSON PortMapping where
  toJSON :: PortMapping -> Value
toJSON PortMapping' {Maybe Int
Maybe Text
Maybe ApplicationProtocol
Maybe TransportProtocol
protocol :: Maybe TransportProtocol
name :: Maybe Text
hostPort :: Maybe Int
containerPortRange :: Maybe Text
containerPort :: Maybe Int
appProtocol :: Maybe ApplicationProtocol
$sel:protocol:PortMapping' :: PortMapping -> Maybe TransportProtocol
$sel:name:PortMapping' :: PortMapping -> Maybe Text
$sel:hostPort:PortMapping' :: PortMapping -> Maybe Int
$sel:containerPortRange:PortMapping' :: PortMapping -> Maybe Text
$sel:containerPort:PortMapping' :: PortMapping -> Maybe Int
$sel:appProtocol:PortMapping' :: PortMapping -> Maybe ApplicationProtocol
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"appProtocol" 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 ApplicationProtocol
appProtocol,
            (Key
"containerPort" 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
containerPort,
            (Key
"containerPortRange" 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
containerPortRange,
            (Key
"hostPort" 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
hostPort,
            (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,
            (Key
"protocol" 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 TransportProtocol
protocol
          ]
      )