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

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

-- |
-- Module      : Amazonka.Organizations.CreateOrganization
-- 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)
--
-- Creates an AWS organization. The account whose user is calling the
-- @CreateOrganization@ operation automatically becomes the
-- <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_getting-started_concepts.html#account management account>
-- of the new organization.
--
-- This operation must be called using credentials from the account that is
-- to become the new organization\'s management account. The principal must
-- also have the relevant IAM permissions.
--
-- By default (or if you set the @FeatureSet@ parameter to @ALL@), the new
-- organization is created with all features enabled and service control
-- policies automatically enabled in the root. If you instead choose to
-- create the organization supporting only the consolidated billing
-- features by setting the @FeatureSet@ parameter to
-- @CONSOLIDATED_BILLING\"@, no policy types are enabled by default, and
-- you can\'t use organization policies
module Amazonka.Organizations.CreateOrganization
  ( -- * Creating a Request
    CreateOrganization (..),
    newCreateOrganization,

    -- * Request Lenses
    createOrganization_featureSet,

    -- * Destructuring the Response
    CreateOrganizationResponse (..),
    newCreateOrganizationResponse,

    -- * Response Lenses
    createOrganizationResponse_organization,
    createOrganizationResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Organizations.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newCreateOrganization' smart constructor.
data CreateOrganization = CreateOrganization'
  { -- | Specifies the feature set supported by the new organization. Each
    -- feature set supports different levels of functionality.
    --
    -- -   @CONSOLIDATED_BILLING@: All member accounts have their bills
    --     consolidated to and paid by the management account. For more
    --     information, see
    --     <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_getting-started_concepts.html#feature-set-cb-only Consolidated billing>
    --     in the /AWS Organizations User Guide./
    --
    --     The consolidated billing feature subset isn\'t available for
    --     organizations in the AWS GovCloud (US) Region.
    --
    -- -   @ALL@: In addition to all the features supported by the consolidated
    --     billing feature set, the management account can also apply any
    --     policy type to any member account in the organization. For more
    --     information, see
    --     <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_getting-started_concepts.html#feature-set-all All features>
    --     in the /AWS Organizations User Guide./
    CreateOrganization -> Maybe OrganizationFeatureSet
featureSet :: Prelude.Maybe OrganizationFeatureSet
  }
  deriving (CreateOrganization -> CreateOrganization -> Bool
(CreateOrganization -> CreateOrganization -> Bool)
-> (CreateOrganization -> CreateOrganization -> Bool)
-> Eq CreateOrganization
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateOrganization -> CreateOrganization -> Bool
$c/= :: CreateOrganization -> CreateOrganization -> Bool
== :: CreateOrganization -> CreateOrganization -> Bool
$c== :: CreateOrganization -> CreateOrganization -> Bool
Prelude.Eq, ReadPrec [CreateOrganization]
ReadPrec CreateOrganization
Int -> ReadS CreateOrganization
ReadS [CreateOrganization]
(Int -> ReadS CreateOrganization)
-> ReadS [CreateOrganization]
-> ReadPrec CreateOrganization
-> ReadPrec [CreateOrganization]
-> Read CreateOrganization
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateOrganization]
$creadListPrec :: ReadPrec [CreateOrganization]
readPrec :: ReadPrec CreateOrganization
$creadPrec :: ReadPrec CreateOrganization
readList :: ReadS [CreateOrganization]
$creadList :: ReadS [CreateOrganization]
readsPrec :: Int -> ReadS CreateOrganization
$creadsPrec :: Int -> ReadS CreateOrganization
Prelude.Read, Int -> CreateOrganization -> ShowS
[CreateOrganization] -> ShowS
CreateOrganization -> String
(Int -> CreateOrganization -> ShowS)
-> (CreateOrganization -> String)
-> ([CreateOrganization] -> ShowS)
-> Show CreateOrganization
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateOrganization] -> ShowS
$cshowList :: [CreateOrganization] -> ShowS
show :: CreateOrganization -> String
$cshow :: CreateOrganization -> String
showsPrec :: Int -> CreateOrganization -> ShowS
$cshowsPrec :: Int -> CreateOrganization -> ShowS
Prelude.Show, (forall x. CreateOrganization -> Rep CreateOrganization x)
-> (forall x. Rep CreateOrganization x -> CreateOrganization)
-> Generic CreateOrganization
forall x. Rep CreateOrganization x -> CreateOrganization
forall x. CreateOrganization -> Rep CreateOrganization x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateOrganization x -> CreateOrganization
$cfrom :: forall x. CreateOrganization -> Rep CreateOrganization x
Prelude.Generic)

-- |
-- Create a value of 'CreateOrganization' 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:
--
-- 'featureSet', 'createOrganization_featureSet' - Specifies the feature set supported by the new organization. Each
-- feature set supports different levels of functionality.
--
-- -   @CONSOLIDATED_BILLING@: All member accounts have their bills
--     consolidated to and paid by the management account. For more
--     information, see
--     <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_getting-started_concepts.html#feature-set-cb-only Consolidated billing>
--     in the /AWS Organizations User Guide./
--
--     The consolidated billing feature subset isn\'t available for
--     organizations in the AWS GovCloud (US) Region.
--
-- -   @ALL@: In addition to all the features supported by the consolidated
--     billing feature set, the management account can also apply any
--     policy type to any member account in the organization. For more
--     information, see
--     <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_getting-started_concepts.html#feature-set-all All features>
--     in the /AWS Organizations User Guide./
newCreateOrganization ::
  CreateOrganization
newCreateOrganization :: CreateOrganization
newCreateOrganization =
  CreateOrganization' :: Maybe OrganizationFeatureSet -> CreateOrganization
CreateOrganization' {$sel:featureSet:CreateOrganization' :: Maybe OrganizationFeatureSet
featureSet = Maybe OrganizationFeatureSet
forall a. Maybe a
Prelude.Nothing}

-- | Specifies the feature set supported by the new organization. Each
-- feature set supports different levels of functionality.
--
-- -   @CONSOLIDATED_BILLING@: All member accounts have their bills
--     consolidated to and paid by the management account. For more
--     information, see
--     <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_getting-started_concepts.html#feature-set-cb-only Consolidated billing>
--     in the /AWS Organizations User Guide./
--
--     The consolidated billing feature subset isn\'t available for
--     organizations in the AWS GovCloud (US) Region.
--
-- -   @ALL@: In addition to all the features supported by the consolidated
--     billing feature set, the management account can also apply any
--     policy type to any member account in the organization. For more
--     information, see
--     <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_getting-started_concepts.html#feature-set-all All features>
--     in the /AWS Organizations User Guide./
createOrganization_featureSet :: Lens.Lens' CreateOrganization (Prelude.Maybe OrganizationFeatureSet)
createOrganization_featureSet :: (Maybe OrganizationFeatureSet -> f (Maybe OrganizationFeatureSet))
-> CreateOrganization -> f CreateOrganization
createOrganization_featureSet = (CreateOrganization -> Maybe OrganizationFeatureSet)
-> (CreateOrganization
    -> Maybe OrganizationFeatureSet -> CreateOrganization)
-> Lens
     CreateOrganization
     CreateOrganization
     (Maybe OrganizationFeatureSet)
     (Maybe OrganizationFeatureSet)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateOrganization' {Maybe OrganizationFeatureSet
featureSet :: Maybe OrganizationFeatureSet
$sel:featureSet:CreateOrganization' :: CreateOrganization -> Maybe OrganizationFeatureSet
featureSet} -> Maybe OrganizationFeatureSet
featureSet) (\s :: CreateOrganization
s@CreateOrganization' {} Maybe OrganizationFeatureSet
a -> CreateOrganization
s {$sel:featureSet:CreateOrganization' :: Maybe OrganizationFeatureSet
featureSet = Maybe OrganizationFeatureSet
a} :: CreateOrganization)

instance Core.AWSRequest CreateOrganization where
  type
    AWSResponse CreateOrganization =
      CreateOrganizationResponse
  request :: CreateOrganization -> Request CreateOrganization
request = Service -> CreateOrganization -> Request CreateOrganization
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateOrganization
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateOrganization)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateOrganization))
-> Logger
-> Service
-> Proxy CreateOrganization
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateOrganization)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Organization -> Int -> CreateOrganizationResponse
CreateOrganizationResponse'
            (Maybe Organization -> Int -> CreateOrganizationResponse)
-> Either String (Maybe Organization)
-> Either String (Int -> CreateOrganizationResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Key -> Either String (Maybe Organization)
forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Core..?> Key
"Organization")
            Either String (Int -> CreateOrganizationResponse)
-> Either String Int -> Either String CreateOrganizationResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable CreateOrganization

instance Prelude.NFData CreateOrganization

instance Core.ToHeaders CreateOrganization where
  toHeaders :: CreateOrganization -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateOrganization -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"AWSOrganizationsV20161128.CreateOrganization" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON CreateOrganization where
  toJSON :: CreateOrganization -> Value
toJSON CreateOrganization' {Maybe OrganizationFeatureSet
featureSet :: Maybe OrganizationFeatureSet
$sel:featureSet:CreateOrganization' :: CreateOrganization -> Maybe OrganizationFeatureSet
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Key
"FeatureSet" Key -> OrganizationFeatureSet -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Core..=) (OrganizationFeatureSet -> Pair)
-> Maybe OrganizationFeatureSet -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe OrganizationFeatureSet
featureSet]
      )

instance Core.ToPath CreateOrganization where
  toPath :: CreateOrganization -> ByteString
toPath = ByteString -> CreateOrganization -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery CreateOrganization where
  toQuery :: CreateOrganization -> QueryString
toQuery = QueryString -> CreateOrganization -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newCreateOrganizationResponse' smart constructor.
data CreateOrganizationResponse = CreateOrganizationResponse'
  { -- | A structure that contains details about the newly created organization.
    CreateOrganizationResponse -> Maybe Organization
organization :: Prelude.Maybe Organization,
    -- | The response's http status code.
    CreateOrganizationResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateOrganizationResponse -> CreateOrganizationResponse -> Bool
(CreateOrganizationResponse -> CreateOrganizationResponse -> Bool)
-> (CreateOrganizationResponse
    -> CreateOrganizationResponse -> Bool)
-> Eq CreateOrganizationResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateOrganizationResponse -> CreateOrganizationResponse -> Bool
$c/= :: CreateOrganizationResponse -> CreateOrganizationResponse -> Bool
== :: CreateOrganizationResponse -> CreateOrganizationResponse -> Bool
$c== :: CreateOrganizationResponse -> CreateOrganizationResponse -> Bool
Prelude.Eq, Int -> CreateOrganizationResponse -> ShowS
[CreateOrganizationResponse] -> ShowS
CreateOrganizationResponse -> String
(Int -> CreateOrganizationResponse -> ShowS)
-> (CreateOrganizationResponse -> String)
-> ([CreateOrganizationResponse] -> ShowS)
-> Show CreateOrganizationResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateOrganizationResponse] -> ShowS
$cshowList :: [CreateOrganizationResponse] -> ShowS
show :: CreateOrganizationResponse -> String
$cshow :: CreateOrganizationResponse -> String
showsPrec :: Int -> CreateOrganizationResponse -> ShowS
$cshowsPrec :: Int -> CreateOrganizationResponse -> ShowS
Prelude.Show, (forall x.
 CreateOrganizationResponse -> Rep CreateOrganizationResponse x)
-> (forall x.
    Rep CreateOrganizationResponse x -> CreateOrganizationResponse)
-> Generic CreateOrganizationResponse
forall x.
Rep CreateOrganizationResponse x -> CreateOrganizationResponse
forall x.
CreateOrganizationResponse -> Rep CreateOrganizationResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateOrganizationResponse x -> CreateOrganizationResponse
$cfrom :: forall x.
CreateOrganizationResponse -> Rep CreateOrganizationResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateOrganizationResponse' 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:
--
-- 'organization', 'createOrganizationResponse_organization' - A structure that contains details about the newly created organization.
--
-- 'httpStatus', 'createOrganizationResponse_httpStatus' - The response's http status code.
newCreateOrganizationResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateOrganizationResponse
newCreateOrganizationResponse :: Int -> CreateOrganizationResponse
newCreateOrganizationResponse Int
pHttpStatus_ =
  CreateOrganizationResponse' :: Maybe Organization -> Int -> CreateOrganizationResponse
CreateOrganizationResponse'
    { $sel:organization:CreateOrganizationResponse' :: Maybe Organization
organization =
        Maybe Organization
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateOrganizationResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A structure that contains details about the newly created organization.
createOrganizationResponse_organization :: Lens.Lens' CreateOrganizationResponse (Prelude.Maybe Organization)
createOrganizationResponse_organization :: (Maybe Organization -> f (Maybe Organization))
-> CreateOrganizationResponse -> f CreateOrganizationResponse
createOrganizationResponse_organization = (CreateOrganizationResponse -> Maybe Organization)
-> (CreateOrganizationResponse
    -> Maybe Organization -> CreateOrganizationResponse)
-> Lens
     CreateOrganizationResponse
     CreateOrganizationResponse
     (Maybe Organization)
     (Maybe Organization)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateOrganizationResponse' {Maybe Organization
organization :: Maybe Organization
$sel:organization:CreateOrganizationResponse' :: CreateOrganizationResponse -> Maybe Organization
organization} -> Maybe Organization
organization) (\s :: CreateOrganizationResponse
s@CreateOrganizationResponse' {} Maybe Organization
a -> CreateOrganizationResponse
s {$sel:organization:CreateOrganizationResponse' :: Maybe Organization
organization = Maybe Organization
a} :: CreateOrganizationResponse)

-- | The response's http status code.
createOrganizationResponse_httpStatus :: Lens.Lens' CreateOrganizationResponse Prelude.Int
createOrganizationResponse_httpStatus :: (Int -> f Int)
-> CreateOrganizationResponse -> f CreateOrganizationResponse
createOrganizationResponse_httpStatus = (CreateOrganizationResponse -> Int)
-> (CreateOrganizationResponse
    -> Int -> CreateOrganizationResponse)
-> Lens
     CreateOrganizationResponse CreateOrganizationResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateOrganizationResponse' {Int
httpStatus :: Int
$sel:httpStatus:CreateOrganizationResponse' :: CreateOrganizationResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: CreateOrganizationResponse
s@CreateOrganizationResponse' {} Int
a -> CreateOrganizationResponse
s {$sel:httpStatus:CreateOrganizationResponse' :: Int
httpStatus = Int
a} :: CreateOrganizationResponse)

instance Prelude.NFData CreateOrganizationResponse