module Stackctl.AWS.EC2
  ( awsEc2DescribeFirstAvailabilityZoneRegionName
  ) where

import Stackctl.Prelude

import Amazonka.EC2.DescribeAvailabilityZones
import Amazonka.EC2.Types (AvailabilityZone (..))
import Stackctl.AWS.Core

awsEc2DescribeFirstAvailabilityZoneRegionName
  :: (MonadResource m, MonadReader env m, HasAwsEnv env) => m Region
awsEc2DescribeFirstAvailabilityZoneRegionName :: forall (m :: * -> *) env.
(MonadResource m, MonadReader env m, HasAwsEnv env) =>
m Region
awsEc2DescribeFirstAvailabilityZoneRegionName = do
  let req :: DescribeAvailabilityZones
req = DescribeAvailabilityZones
newDescribeAvailabilityZones
  forall (m :: * -> *) env a b.
(MonadResource m, MonadReader env m, HasAwsEnv env, AWSRequest a,
 Typeable a, Typeable (AWSResponse a)) =>
Text -> a -> (AWSResponse a -> Maybe b) -> m b
awsSimple Text
"DescribeAvailabilityZones" DescribeAvailabilityZones
req forall a b. (a -> b) -> a -> b
$ \AWSResponse DescribeAvailabilityZones
resp -> do
    [AvailabilityZone]
azs <- AWSResponse DescribeAvailabilityZones
resp forall s a. s -> Getting a s a -> a
^. Lens' DescribeAvailabilityZonesResponse (Maybe [AvailabilityZone])
describeAvailabilityZonesResponse_availabilityZones
    AvailabilityZone
az <- forall a. [a] -> Maybe a
listToMaybe [AvailabilityZone]
azs
    Text
rn <- AvailabilityZone -> Maybe Text
regionName AvailabilityZone
az
    forall a b. Either a b -> Maybe b
hush forall a b. (a -> b) -> a -> b
$ forall a. FromText a => Text -> Either String a
fromText Text
rn