# Create and access an instance

Create a Secure Source Manager instance and access its web interface to
prepare for creating repositories and granting users access.

> [!NOTE]
> **Note:** Secure Source Manager doesn't support domain-scoped projects. If your project ID contains a colon (`:`), you must create a new project before using Secure Source Manager.

## Before you begin

<br />

### Required roles


To get the permissions that
you need to create a Secure Source Manager instance,

ask your administrator to grant you the
[Instance Owner](https://docs.cloud.google.com/iam/docs/roles-permissions/securesourcemanager#securesourcemanager.instanceOwner) (`roles/securesourcemanager.instanceOwner`) IAM role on the Google Cloud project.


> [!NOTE]
> **Note:** The [Secure Source Manager Admin role](https://docs.cloud.google.com/iam/docs/roles-permissions/securesourcemanager#securesourcemanager.admin) (`roles/securesourcemanager.admin`) or [IAM basic role](https://docs.cloud.google.com/iam/docs/roles-overview#basic) of Owner (`roles/owner`) on your project also contains permissions to create an instance. You shouldn't grant administrator roles or basic roles in a production environment, but you can grant them in a development or test environment.

Secure Source Manager roles don't appear in the Google Cloud console until
they have been granted to a principal. To grant a Secure Source Manager role
for the first time, see
[Grant and revoke IAM roles](https://docs.cloud.google.com/secure-source-manager/docs/grant-iam-roles).

## Create an instance

1. Run the following command to create an instance named `my-instance` in the
   `us-central1` [location](https://docs.cloud.google.com/secure-source-manager/docs/locations). You might be asked to
   authenticate to the gcloud CLI.

       gcloud source-manager instances create my-instance \
           --region=us-central1

   Where:
   - `my-instance` is the name of the instance.
   - `us-central1` is the region where you are creating the instance.

   A long-running create instance operation starts. The output looks similar to
   the following:

       Create request issued for [my-instance].
       done: false
       metadata:
         '@type': type.googleapis.com/google.cloud.securesourcemanager.v1.OperationMetadata
         apiVersion: v1
         createTime: '2023-02-27T20:57:52.315609549Z'
         requestedCancellation: false
         target: projects/PROJECT_ID/locations/us-central1/instances/my-instance
         verb: create
       name: projects/PROJECT_ID/locations/us-central1/operations/operation-1234567894561-5ec69948c0f2b-60dd727f-a9b97a2e

   It can take up to 60 minutes to create the instance.
2. Note the <var translate="no">`OPERATION_NAME`</var> which is the full resource name of the
   operation received in response to your request. It has the following format and
   is required when checking the status of the operation in the next step:

   <br />

   ```none
   projects/PROJECT_ID/locations/LOCATION/operations/OPERATION_ID
   ```

   <br />

   For example:
   `projects/PROJECT_ID/locations/us-central1/operations/operation-1234567894561-5ec69948c0f2b-60dd727f-a9b97a2e`
   where <var translate="no">`PROJECT_ID`</var> is your Google Cloud project.
3. Check the status of the `create` operation by running the following command:

       gcloud source-manager operations describe OPERATION_NAME \
           --region=us-central1

   Replace <var translate="no">`OPERATION_NAME`</var> with the operation name returned in your
   create command response.

   Once the instance is ready, the response will look similar to the following:

       {
       "name": "projects/PROJECT_ID/locations/us-central1/operations/operation-123456789012-5ec69948c0f2b-60dd727f-a9b97a2e",
       "metadata": {
         "@type": "type.googleapis.com/google.cloud.securesourcemanager.v1.OperationMetadata",
         "createTime": "2022-11-01T14:31:32.420469714Z",
         "endTime": "2022-11-01T14:48:34.140378114Z",
         "target": "projects/PROJECT_ID/locations/us-central1/instances/my-instance",
         "verb": "create",
         "requestedCancellation": false,
         "apiVersion": "v1"
       },
       "done": true,
       "response": {
         "@type": "type.googleapis.com/google.cloud.securesourcemanager.v1.Instance",
         "name": "projects/PROJECT_ID/locations/us-central1/instances/my-instance",
         "createTime": "2022-11-01T14:31:32.416413630Z",
         "updateTime": "2022-11-01T14:31:32.416413630Z"
         },
         "state": "ACTIVE",
         "hostConfig": {
           "html": "my-instance-098765432109.us-central1.sourcemanager.dev",
           "api": "my-instance-098765432109-api.us-central1.sourcemanager.dev",
           "gitHttp": "my-instance-098765432109-git.us-central1.sourcemanager.dev"
         }
       }
       }

   Where:
   - `my-instance-098765432109.us-central1.sourcemanager.dev` is the instance HTML URL.
   - <var translate="no">`PROJECT_ID`</var> is your project ID.

   > [!NOTE]
   > **Note:** It's possible for the status check to report completion before the instance is fully operational. If you encounter errors accessing the instance after creation, wait 60 minutes and try again before reaching out for assistance from Secure Source Manager Support at [secure-source-manager-support@google.com](mailto:secure-source-manager-support@google.com).

4. Copy the HTML URL from the successfully created check status command. You
   will need this URL to access the instance using a web browser.

## Access an instance

After the instance is created, you can access the instance through its web
interface using a browser.

> [!NOTE]
> **Note:** To [create repositories](https://docs.cloud.google.com/secure-source-manager/docs/create-repository) in the instance you need the Repo Creator role (`roles/securesourcemanager.repoCreator`) on the instance project and the Instance Repository Creator role (`roles/securesourcemanager.instanceRepositoryCreator`) on the Secure Source Manager instance.

1. To get the HTML URL for your instance, run the following command again:

          gcloud source-manager operations describe OPERATION_NAME \
           --region=us-central1

2. Copy the HTML URL from the successful response from the
   `gcloud source-manager operations describe` command into your browser
   address bar.

3. An Oauth 2.0 screen appears asking if you want to give `sourcemanager.dev`
   access to your Google Cloud account.

4. Click the **Allow** button.

5. The Secure Source Manager web interface opens. You can create and view
   repositories and all associated issues and pull requests from the web
   interface.

## Clean up


To avoid incurring charges to your Google Cloud account for
the resources used on this page, delete the Google Cloud project with the
resources.

> [!CAUTION]
> **Caution** : Deleting a project has the following effects:
>
> - **Everything in the project is deleted.** If you used an existing project for the tasks in this document, when you delete it, you also delete any other work you've done in the project.
> - **Custom project IDs are lost.** When you created this project, you might have created a custom project ID that you want to use in the future. To preserve the URLs that use the project ID, such as an `appspot.com` URL, delete selected resources inside the project instead of deleting the whole project.
>
>
> If you plan to explore multiple architectures, tutorials, or quickstarts, reusing projects
> can help you avoid exceeding project quota limits.

1. In the Google Cloud console, go to the **Manage resources** page.

   [Go to Manage resources](https://console.cloud.google.com/iam-admin/projects)
2. In the project list, select the project that you want to delete, and then click **Delete**.
3. In the dialog, type the project ID, and then click **Shut down** to delete the project.

<br />

## What's next

- [Create and clone a repository](https://docs.cloud.google.com/secure-source-manager/docs/create-clone-repository)
- [Grant users instance access](https://docs.cloud.google.com/secure-source-manager/docs/grant-users-instance-access)
- [Add repository users](https://docs.cloud.google.com/secure-source-manager/docs/add-repository-users)