diff --git a/moto/organizations/models.py b/moto/organizations/models.py index 6fa525113069..8ff334ff3ee6 100644 --- a/moto/organizations/models.py +++ b/moto/organizations/models.py @@ -538,9 +538,9 @@ def list_organizational_units_for_parent( ] def create_account(self, **kwargs: Any) -> Dict[str, Any]: - if ( - self.org is None - or self.account_id not in organizations_backends.master_accounts + if self.org is None or ( + self.account_id != self.org.master_account_id + and self.account_id not in organizations_backends.master_accounts ): raise AWSOrganizationsNotInUseException @@ -554,9 +554,9 @@ def create_account(self, **kwargs: Any) -> Dict[str, Any]: return new_account.create_account_status def close_account(self, **kwargs: Any) -> None: - if ( - self.org is None - or self.account_id not in organizations_backends.master_accounts + if self.org is None or ( + self.account_id != self.org.master_account_id + and self.account_id not in organizations_backends.master_accounts ): raise AWSOrganizationsNotInUseException