# Installation

Installing this extension is made to be as simple as possible. However, due to Firebase Extensions limitations, there are some post installation steps you must undertake. Below is a step-by-step guide from start to finish in how to get this extension up and running. I have also included brief clips showcasing what each step looks like for those that are more visual!

***

{% stepper %}
{% step %}

### Install from Firebase Extensions Hub

<details>

<summary>Installing from Firebase Extensions Hub</summary>

In Firebase Extension Hub, navigate to the Auto Stop Services extension and click the install button.

<img src="https://2606721822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUFZ0hGPRQgoo6wd38pSO%2Fuploads%2FrPVXb8664w99mSaZVdfX%2FCleanShot%202025-02-26%20at%2016.45.14.gif?alt=media&#x26;token=38a1801e-1eea-4863-89d1-2b966e23e53e" alt="Navigate to Extension Hub and install Auto Stop Services via Firebase console" data-size="original">

</details>
{% endstep %}

{% step %}

### Upgrade to Blaze Plan

<details>

<summary>Upgrading to Blaze Plan</summary>

In the Extension Installation menu, upgrade to Blaze Plan (if your project isn't already on this plan). Otherwise continue to the next step.

<img src="https://2606721822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUFZ0hGPRQgoo6wd38pSO%2Fuploads%2FSFWwbXLHw55DdAq3Ahed%2FCleanShot%202025-02-26%20at%2016.47.49.gif?alt=media&#x26;token=f382282d-6f81-489a-b23f-cc705860ff9b" alt="Ensure the project is on Blaze plan, if it is not a prompt will appear during installation asking you to upgrade." data-size="original">

</details>
{% endstep %}

{% step %}

### Configure the Extension

<details>

<summary>Configuring the extension</summary>

Following the steps outlined in the Extension Installation menu, configure the extension as appropriate for your project.

The default settings will work fine too!

A full detail of each parameter can be found in the [Configurable Parameters](#configurable-parameters) section on this page.

<img src="https://2606721822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUFZ0hGPRQgoo6wd38pSO%2Fuploads%2FN1vKVORl9hiCVGhC1noX%2FCleanShot%202025-02-26%20at%2017.10.08.gif?alt=media&#x26;token=f9061ab8-41ec-44f7-b904-b5f212d0a13f" alt="Configure the extension by defining the strategy and any other details. The default is also OK!" data-size="original">

</details>
{% endstep %}

{% step %}

### Verify the Installation

<details>

<summary>Verifying the installation</summary>

Once the extension is installed, verify that there are no error messages and that two functions were created.

In some rare instances the installation may fail. You will see a red dialog appear - just select "retry installation" and you should be good to go!

<img src="https://2606721822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUFZ0hGPRQgoo6wd38pSO%2Fuploads%2FwsKoQnYQeM9IuuIAzWEn%2FCleanShot%202025-02-26%20at%2017.24.19.gif?alt=media&#x26;token=f4704f97-fe52-41e2-a42b-df39f8017f6c" alt="Verify the installation by checking two functions were created and there are no error messages in the extension menu." data-size="original">

</details>
{% endstep %}

{% step %}

### Setup a Budget

<details>

<summary>Setting up a Budget</summary>

You must create a Budget against your project and Billing Account if none exists. When you first upgrade to Blaze plan, you will typically have set this up.

You can setup a budget via Firebase Console (recommended) or GCP.

* **Firebase**: Go to Settings > Usage & Billing. Set a budget and note its name.
* **GCP**: Navigate to Billing > Budgets. Create a new budget, set it, and note the budget name.

![](https://2606721822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUFZ0hGPRQgoo6wd38pSO%2Fuploads%2FppBZTHA8bT78UsYvOlIC%2FCleanShot%202025-02-26%20at%2020.13.25.gif?alt=media\&token=18faf234-790d-4c9a-9248-d0e5d62f11b4)

</details>
{% endstep %}

{% step %}

### Connect the Budget to the Pub/Sub topic

<details>

<summary>Connecting the Budget to the Pub/Sub topic</summary>

This extension installed a Pub/Sub topic with the name you configured during installation. This was the `{TOPIC_NAME}` parameter, which by default is "ext-firebase-trigger-auto-stop".

Navigate to your Budget and select "Connect a pub/sub topic to this budget" and choose the pub/sub topic relating to this extension. Note that in this view you may have to select your project (by clicking "switch project" in the dropdown) for the topic to appear.&#x20;

![](https://2606721822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUFZ0hGPRQgoo6wd38pSO%2Fuploads%2FnOJ3jO9taNjsYtT7tjq7%2FCleanShot%202025-02-26%20at%2020.18.21.gif?alt=media\&token=481d239b-c2bd-4d03-bd46-860058472278)

</details>
{% endstep %}

{% step %}

### Update the Service Account permissions

<details>

<summary>Updating the Service Account permissions</summary>

Finally, you must navigate to IAM and grant IAM roles to the extension's Service Account. The roles will depend on which strategy you have selected.&#x20;

Grant the following IAM roles to `{EXTENSION_NAME}@{PROJECT_ID}.iam.gserviceaccount.com`:

* **Strategy 1:** Grant Project Billing Manager (`roles/billing.projectManager`) to manage project billing settings.
* **Strategy 2:** Service Usage Admin (`roles/serviceusage.serviceUsageAdmin`) for enabling/disabling service APIs.

![](https://2606721822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUFZ0hGPRQgoo6wd38pSO%2Fuploads%2FRFlhg8OJMCGgXvfWmc2Q%2FCleanShot%202025-02-26%20at%2020.30.42.gif?alt=media\&token=4c9e57bd-f052-45a3-85fc-563d8f98ab97)

</details>
{% endstep %}

{% step %}

### You are good to go!

Feel free to test the extension and ensure it is working correctly. See [Testing this Extension](#testing-this-extension) below.
{% endstep %}
{% endstepper %}

***

### Configurable Parameters

&#x20;During the extension installation, you will be asked to configure it with the following parameters:

| Parameter                       | Definition                                                                                                                        | Default Value                  |
| ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ |
| `TOPIC_NAME`                    | The name of the pub/sub topic. A billing alert is published here, which will trigger the auto-stop (if the threshold is reached). | ext-firebase-trigger-auto-stop |
| `BUDGET_STOP_THRESHOLD_PERCENT` | The percentage (0.0-1.0) of the budget that will trigger the stop strategy, default is 1.0 (100%)                                 | 1.0                            |
| `DISABLE_BILLING`               | Enables strategy 1 - to remove the billing account (requires `project billing manager` role)                                      | Yes (true)                     |
| `DISABLE_API_LIST`              | Enables strategy 2 - to disable services (requires `service usage admin` role).                                                   | \[Empty]                       |
| `LOCATION`                      | Defines the deployment location for the cloud function.                                                                           | us-central1                    |
|                                 |                                                                                                                                   |                                |

### Example Pub/Sub Message

When a budget alert fires, the message content will look like the below:

```json
{
  "budgetDisplayName": "Your Budget Name",
  "alertThresholdExceeded": 0.5,
  "costAmount": 500.0,
  "costIntervalStart": "2021-01-01T00:00:00Z",
  "budgetAmount": 1000.0,
  "budgetAmountType": "SPECIFIED_AMOUNT",
  "currencyCode": "USD",
  "schemaVersion": "1.0",
  "notificationType": "ACTUAL",
  "projectId": "your-project-id",
  "billingAccountId": "012345-6789AB-CDEF01"
}
```

The key element of this message is the `alertThresholdExceeded`, all other information is effectively discarded.

### Testing this Extension

Once you have followed the steps, you can submit a message through the pub/sub topic. Any results will be published as logs, which you can monitor.

This example message will not execute any strategy.

```json
{
  "extensionTest": true
}
```

**Example Log**

Below is the log output when sending the test message. Note that this specific example is for Strategy 1 only which requires the Project Billing Manager role, while the Service Usage Admin role is not required.

<figure><img src="https://2606721822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUFZ0hGPRQgoo6wd38pSO%2Fuploads%2FAdn5xQK8eUfIaMW7qjcE%2FCleanShot%202025-02-26%20at%2021.28.36%402x.png?alt=media&#x26;token=e47f9cd3-03b9-4e1e-a06e-8648f0b1ea4f" alt=""><figcaption></figcaption></figure>
