How to add Magento Cloud users via CLI

How to add Magento Cloud users via CLI

If you're a developer like me, for sure you will prefer to add new users via terminal via Magento Cloud CLI, not just add users, but you can edit, remove, list and edit the permissions via terminal. But in case you want to go to the visual way, I've written the post How to add new users to the Magento Cloud panel.

Magento CLI Commands

Specifically to control your users you have these available commands.

Add a user to the project

magento-cloud user:add

Delete a user

magento-cloud user:delete

List project users

magento-cloud user:list [users]

View or change the user role

magento-cloud user:role

The following examples use the CLI to add a user, configure roles, and modify project assignments and assigned user roles.

To add a user and assign roles:

Use the CLI to add the user. magento-cloud user:add

Follow the prompts to specify the user email address, set the project and environment roles, and add the user:

Enter the user's email address:

Email address:

The user's project role can be 'viewer' ('v') or 'admin' ('a').

Project role [V/a]: a

The user's environment-level roles can be 'viewer', 'contributor', or 'admin'.

development environment role [V/c/a]: c

Summary: Email address:

Project role: contributor

Adding users can result in additional charges.

Are you sure you want to add this user? [Y/n]

Adding the user to the project

This operation triggers the Cloud build and deploy process, which takes your site offline until deployment completes. For production environments, we recommend completing this operation during off-peak hours to prevent service disruptions.

After you add the user, Magento sends an email to the specified address with instructions for accessing the Magento Commerce Cloud project.

The following example changes the environment-level role that is assigned to a user:

magento-cloud user:role --level environment --environment development --role admin

The magento-cloud list command displays all the magento-cloud CLI commands.