Skip to content

Commit

Permalink
feat(provider): initial signoz terraform provider and alert support (#8)
Browse files Browse the repository at this point in the history
#### Features

- Alerts as code

Signed-off-by: Prashant Shahi <[email protected]>
  • Loading branch information
prashant-shahi authored Jul 8, 2024
1 parent c8b90d5 commit fb42bc0
Show file tree
Hide file tree
Showing 47 changed files with 2,422 additions and 779 deletions.
15 changes: 15 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#### Features

- <Add Feature>

#### Fixes

- <Add Fix>

#### Refactors

- <Add Refactor>

#### Tests

- <Add Test>
1 change: 1 addition & 0 deletions .github/terraform_logo_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .github/terraform_logo_light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ jobs:
uses: crazy-max/ghaction-import-gpg@01dd5d3ca463c7f10f7f4f7b4f177225ac661ee4 # v6.1.0
id: import_gpg
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
gpg_private_key: ${{ secrets.PRIMUS_GPG_PRIVATE_KEY }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@7ec5c2b0c6cdda6e8bbb49444bc797dd33d74dd8 # v5.0.0
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ jobs:
- run: go mod download
- env:
TF_ACC: "1"
run: go test -v -cover ./internal/provider/
run: go test -v -cover ./signoz
timeout-minutes: 10
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ linters:
- unconvert
- unparam
- unused
- vet
- govet
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2021 HashiCorp, Inc.
Copyright (c) 2024-present SigNoz Inc.

Mozilla Public License Version 2.0
==================================
Expand Down
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
# Terraform Provider Scaffolding (Terraform Plugin Framework)
<!-- markdownlint-disable first-line-h1 no-inline-html -->
<a href="https://terraform.io">
<picture>
<source media="(prefers-color-scheme: dark)" srcset=".github/terraform_logo_dark.svg">
<source media="(prefers-color-scheme: light)" srcset=".github/terraform_logo_light.svg">
<img src=".github/terraform_logo_light.svg" alt="Terraform logo" title="Terraform" align="right" height="50">
</picture>
</a>

_This template repository is built on the [Terraform Plugin Framework](https://github.com/hashicorp/terraform-plugin-framework). The template repository built on the [Terraform Plugin SDK](https://github.com/hashicorp/terraform-plugin-sdk) can be found at [terraform-provider-scaffolding](https://github.com/hashicorp/terraform-provider-scaffolding). See [Which SDK Should I Use?](https://developer.hashicorp.com/terraform/plugin/framework-benefits) in the Terraform documentation for additional information._
# Terraform SigNoz Provider

This repository is a *template* for a [Terraform](https://www.terraform.io) provider. It is intended as a starting point for creating Terraform providers, containing:

- A resource and a data source (`internal/provider/`),
- Examples (`examples/`) and generated documentation (`docs/`),
- Miscellaneous meta files.

These files contain boilerplate code that you will need to edit to create your own Terraform provider. Tutorials for creating Terraform providers can be found on the [HashiCorp Developer](https://developer.hashicorp.com/terraform/tutorials/providers-plugin-framework) platform. _Terraform Plugin Framework specific guides are titled accordingly._

Please see the [GitHub template repository documentation](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template) for how to create a new repository from this template on GitHub.

Once you've written your provider, you'll want to [publish it on the Terraform Registry](https://developer.hashicorp.com/terraform/registry/providers/publishing) so that others can use it.
The **SigNoz Provider** enables [Terraform](https://terraform.io) to manage [SigNoz](https://signoz.io) resources.

## Requirements

Expand All @@ -22,8 +19,8 @@ Once you've written your provider, you'll want to [publish it on the Terraform R
## Building The Provider

1. Clone the repository
1. Enter the repository directory
1. Build the provider using the Go `install` command:
2. Enter the repository directory
3. Build the provider using the Go `install` command:

```shell
go install
Expand All @@ -43,15 +40,18 @@ go mod tidy

Then commit the changes to `go.mod` and `go.sum`.

## Using the provider
## Documentation

Fill this in for each provider
To update the documentation edit the files in templates/ and then run make docs.
The files in docs/ are auto-generated and should not be updated manually.

## Developing the Provider

If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (see [Requirements](#requirements) above).
If you wish to work on the provider, you'll first need [Go](http://www.golang.org)
installed on your machine (see [Requirements](#requirements) above).

To compile the provider, run `go install`. This will build the provider and put the provider binary in the `$GOPATH/bin` directory.
To compile the provider, run `go install`. This will build the provider and put the
provider binary in the `$GOPATH/bin` directory.

To generate or update documentation, run `go generate`.

Expand Down
39 changes: 39 additions & 0 deletions docs/data-sources/alert.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "signoz_alert Data Source - signoz"
subcategory: ""
description: |-
Fetches an alert from Signoz using its ID. The ID can be found in the URL of the alert in the Signoz UI.
---

# signoz_alert (Data Source)

Fetches an alert from Signoz using its ID. The ID can be found in the URL of the alert in the Signoz UI.



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `id` (String) ID of the alert.

### Read-Only

- `alert` (String) Name of the alert.
- `alert_type` (String) Type of the alert. Possible values are: METRIC_BASED_ALERT, LOGS_BASED_ALERT, TRACES_BASED_ALERT, and EXCEPTIONS_BASED_ALERT.
- `broadcast_to_all` (Boolean) Whether to broadcast the alert to all the alert channels.
- `condition` (String) Condition of the alert.
- `description` (String) Description of the alert.
- `disabled` (Boolean) Whether the alert is disabled.
- `eval_window` (String) Evaluation window of the alert.
- `frequency` (String) Frequency of the alert.
- `labels` (Map of String) Labels of the alert. Severity is a required label.
- `preferred_channels` (List of String) List of preferred channels of the alert. This is a noop if BroadcastToAll is true.
- `rule_type` (String) Type of the Alert Rule for threshold. Possible values are: threshold_rule and promql_rule.
- `severity` (String) Severity of the alert.
- `source` (String) Source URL of the alert.
- `state` (String) State of the alert. Possible values are: inactive, firing, pending, and disabled.
- `summary` (String) Summary of the alert.
- `version` (String) Version of the alert.
30 changes: 0 additions & 30 deletions docs/data-sources/example.md

This file was deleted.

26 changes: 0 additions & 26 deletions docs/functions/example.md

This file was deleted.

16 changes: 12 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "scaffolding Provider"
page_title: "signoz Provider"
subcategory: ""
description: |-
---

# scaffolding Provider
# signoz Provider



## Example Usage

```terraform
provider "scaffolding" {
provider "signoz" {
# example configuration here
}
```
Expand All @@ -23,4 +23,12 @@ provider "scaffolding" {

### Optional

- `endpoint` (String) Example provider attribute
- `access_token` (String, Sensitive) Access token of the SigNoz API. You can retrieve it from SigNoz UI
with Admin Role ([documentation](https://signoz.io/newsroom/launch-week-1-day-5/#using-access-token)).
Also, you can set it using environment variable SIGNOZ_ACCESS_TOKEN.
- `endpoint` (String) Endpoint of the SigNoz. It is the root URL of the SigNoz UI.
Also, you can set it using environment variable SIGNOZ_ENDPOINT. If not set, it defaults to http://localhost:3301.
- `http_max_retry` (Number) Specifies the max retry limit for the HTTP requests made to SigNoz.
Also, you can set it using environment variable SIGNOZ_HTTP_MAX_RETRY. If not set, it defaults to 10.
- `http_timeout` (Number) Specifies the timeout limit in seconds for the HTTP requests made to SigNoz.
Also, you can set it using environment variable SIGNOZ_HTTP_TIMEOUT. If not set, it defaults to 35.
46 changes: 46 additions & 0 deletions docs/resources/alert.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "signoz_alert Resource - signoz"
subcategory: ""
description: |-
Creates and manages alert resources in SigNoz.
---

# signoz_alert (Resource)

Creates and manages alert resources in SigNoz.



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `alert` (String) Name of the alert.
- `alert_type` (String) Type of the alert. Possible values are: METRIC_BASED_ALERT, LOGS_BASED_ALERT, TRACES_BASED_ALERT, and EXCEPTIONS_BASED_ALERT.
- `condition` (String) Condition of the alert.
- `severity` (String) Severity of the alert. Possible values are: info, warning, error, and critical.

### Optional

- `broadcast_to_all` (Boolean) Whether to broadcast the alert to all the alerting channels. By default, the alert is only sent to the preferred channels.
- `description` (String) Description of the alert.
- `disabled` (Boolean) Whether the alert is disabled.
- `eval_window` (String) The evaluation window of the alert. By default, it is 5m0s.
- `frequency` (String) The frequency of the alert. By default, it is 1m0s.
- `labels` (Map of String) Labels of the alert. Severity is a required label.
- `preferred_channels` (List of String) Preferred channels of the alert. By default, it is empty.
- `rule_type` (String) Type of the alert. Possible values are: threshold_rule and promql_rule.
- `source` (String) Source of the alert. By default, it is <SIGNOZ_ENDPOINT>/alerts.
- `summary` (String) Summary of the alert.
- `version` (String) Version of the alert. By default, it is v4.

### Read-Only

- `create_at` (String) Creation time of the alert.
- `create_by` (String) Creator of the alert.
- `id` (String) Autogenerated unique ID for the alert.
- `state` (String) State of the alert.
- `update_at` (String) Last update time of the alert.
- `update_by` (String) Last updater of the alert.
31 changes: 0 additions & 31 deletions docs/resources/example.md

This file was deleted.

20 changes: 20 additions & 0 deletions examples/data-sources/alert/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
terraform {
required_providers {
signoz = {
source = "registry.terraform.io/signoz/signoz"
}
}
}

provider "signoz" {
endpoint = "http://localhost:3301"
# access_token = "ACCESS_TOKEN"
}

data "signoz_alert" "get_alert" {
id = "5"
}

output "alert" {
value = data.signoz_alert.get_alert
}
3 changes: 0 additions & 3 deletions examples/data-sources/scaffolding_example/data-source.tf

This file was deleted.

10 changes: 10 additions & 0 deletions examples/install-verification/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_providers {
signoz = {
source = "registry.terraform.io/signoz/signoz"
}
}
}
provider "signoz" {}

data "signoz_alert" "example" {}
2 changes: 1 addition & 1 deletion examples/provider/provider.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
provider "scaffolding" {
provider "signoz" {
# example configuration here
}
Loading

0 comments on commit fb42bc0

Please sign in to comment.