> For the complete documentation index, see [llms.txt](https://deep-rock.gitbook.io/auto-stop-services/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://deep-rock.gitbook.io/auto-stop-services/quickstart.md).

# Installation

{% hint style="warning" %}
**Documentation has moved!**

Please go to: <https://deep-rock-development.github.io/auto-stop-firebase-ext/>

\
*This Gitbook is no longer updated.*
{% endhint %}

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="/files/Zzldl1OKsO4Tlq7hl0mZ" 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="/files/eUIoucdoxb9nqvKDvjPY" 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="/files/3I9hBunuWSVt7ah3GRtW" 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="/files/nbAHscDOoFkocnk7Eqeu" 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.

![](/files/IFRBnp3ZzzYX35TlpVHi)

</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;

![](/files/VPy6ThkLi1GRhaNd1Zkr)

</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.

![](/files/M4h213geJ3CXi3q7Un38)

</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="/files/HVLFQUTeeBgIvhOTtSAE" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://deep-rock.gitbook.io/auto-stop-services/quickstart.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
