Skip to content

Commit

Permalink
feat: complete the first edition of terraform provider
Browse files Browse the repository at this point in the history
  • Loading branch information
yufeiminds committed Apr 20, 2023
1 parent 577abfc commit 80ef196
Show file tree
Hide file tree
Showing 100 changed files with 3,250 additions and 1,902 deletions.
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,27 @@

The Guance Provider provides resources to manage [Guance Cloud](https://en.guance.com/) resources.

![cover](./cover.png)

## Documentation, questions, and discussions

Official documentation on how to use this provider can be found on the [Terraform Registry](https://registry.terraform.io/providers/guance/guance/latest/docs).

The remainder of this document will focus on the development aspects of the provider.

The resource supports as follows:

* [x] notification
* [x] pipeline
* [x] members
* [x] member group
* [x] alert policy
* [ ] mute
* [ ] monitor, see built-in modules at [terraform-guance-monitor](https://github.com/GuanceCloud/terraform-guance-monitor)
* [ ] dashboard, see built-in modules at [terraform-guance-dashboard](https://github.com/GuanceCloud/terraform-guance-dashboard)

If there are more resources you need, create an [issue]() for free.

## Compatibility

Compatibility table between this provider, the [Terraform Plugin Protocol](https://www.terraform.io/plugin/how-terraform-works#terraform-plugin-protocol)
Expand All @@ -30,14 +45,7 @@ that return all the details about which versions are currently available for a p

### Testing

In order to test the provider, you can run

* `./hack/make -v test:unit` to run provider tests
* `./hack/make -v test:acc` to run provider acceptance tests

Acceptance tests (`testacc`) will spawn
`terraform` and the provider. Read more about their work on the
[official page](https://www.terraform.io/plugin/sdkv2/testing/acceptance-tests).
Guance Cloud Code Generation Pipeline generates this repository. So don't need to test. Please create issues for free.

### Generating documentation

Expand Down
Binary file added cover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
94 changes: 94 additions & 0 deletions examples/alertpolicy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Alert Policy

Alert policy is a set of rules that define when to trigger an alert. You can create alert policies for your data
sources, and set up alert targets to receive alerts.

Guance Cloud supports alert policy management for the results of monitor checks, by sending alert notification emails or
group message notifications, so that you can know about the abnormal data situation of the monitoring in time, find
problems, and solve problems.

Relationships:

```mermaid
graph LR
A[Monitor] --> B[Alert Policy] --> C[Notification]
```

Notes:

1. When a monitor is created, an alert policy must be selected, and the default is selected by default;
2. When a certain alert policy is deleted, the monitor under the deleted alert policy will automatically be classified
into the default.

## Create

The first let me create a resource. We will send the create operation to the resource management service

```terraform
variable "ding_talk_webhook" {
type = string
}
variable "ding_talk_secret" {
type = string
}
variable "email" {
type = string
}
data "guance_members" "demo" {
filter = [
{
name = "email"
values = [var.email]
}
]
}
resource "guance_membergroup" "demo" {
name = "oac-demo"
member_ids = data.guance_members.demo.items[*].id
}
resource "guance_notification" "demo" {
name = "oac-demo"
type = "ding_talk_robot"
ding_talk_robot = {
webhook = var.ding_talk_webhook
secret = var.ding_talk_secret
}
}
resource "guance_alertpolicy" "demo" {
name = "oac-demo"
silent_timeout = 3600
statuses = [
"critical",
"error",
"warning",
"info",
"ok",
"nodata",
"nodata_ok",
"nodata_as_ok",
]
alert_targets = [
{
type = "member_group"
member_group = {
id = guance_membergroup.demo.id
}
},
{
type = "notification"
notification = {
id = guance_notification.demo.id
}
}
]
}
```
65 changes: 65 additions & 0 deletions examples/alertpolicy/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
variable "ding_talk_webhook" {
type = string
}

variable "ding_talk_secret" {
type = string
}

variable "email" {
type = string
}

data "guance_members" "demo" {
filter = [
{
name = "email"
values = [var.email]
}
]
}

resource "guance_membergroup" "demo" {
name = "oac-demo"
member_ids = data.guance_members.demo.items[*].id
}

resource "guance_notification" "demo" {
name = "oac-demo"
type = "ding_talk_robot"
ding_talk_robot = {
webhook = var.ding_talk_webhook
secret = var.ding_talk_secret
}
}

resource "guance_alertpolicy" "demo" {
name = "oac-demo"
silent_timeout = 3600

statuses = [
"critical",
"error",
"warning",
"info",
"ok",
"nodata",
"nodata_ok",
"nodata_as_ok",
]

alert_targets = [
{
type = "member_group"
member_group = {
id = guance_membergroup.demo.id
}
},
{
type = "notification"
notification = {
id = guance_notification.demo.id
}
}
]
}
13 changes: 13 additions & 0 deletions examples/alertpolicy/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

terraform {
required_version = ">=0.12"

required_providers {
guance = {
source = "GuanceCloud/guance"
}
}
}

provider "guance" {
}
19 changes: 19 additions & 0 deletions examples/dashboard/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Dashboard

**WORKING IN PROGRESS!**

A dashboard is a collection of visualizations that you can use to monitor the health of your systems and applications. Dashboards are made up of one or more panels, which are the visualizations themselves. Each panel displays a single metric or a single aggregation of metrics.

Dashboards are a great way to visualize your data and monitor your systems. You can use them to track metrics over time, and to quickly see how your systems are performing. You can also use them to compare metrics from different systems and applications.

Guance Cloud's dashboard is used to clearly show the range in which the metric data values are located. It is suitable for slicing messy data into points.

## Create

The first let me create a resource. We will send the create operation to the resource management service

```terraform
resource "guance_dashboard" "demo" {
name = "oac-demo"
}
```
3 changes: 3 additions & 0 deletions examples/dashboard/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "guance_dashboard" "demo" {
name = "oac-demo"
}
13 changes: 13 additions & 0 deletions examples/dashboard/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

terraform {
required_version = ">=0.12"

required_providers {
guance = {
source = "GuanceCloud/guance"
}
}
}

provider "guance" {
}
41 changes: 41 additions & 0 deletions examples/membergroup/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Member Group

Member group is a collection of members in a workspace, and member groups can be authorized to access the resources in
the workspace.

Member group is an abstract concept, it can be a team, or a department, it can help us build a reasonable organizational
structure, optimize the management efficiency and user experience of the observability platform.

Relationships:

```mermaid
graph LR
A[Workspace] --> B[Member]
A --> C[MemberGroup]
```

## Create

The first let me create a resource. We will send the create operation to the resource management service

```terraform
variable "email" {
type = string
}
data "guance_members" "demo" {
filter = [
{
name = "email"
values = [var.email]
}
]
}
resource "guance_membergroup" "demo" {
name = "oac-demo"
member_ids = data.guance_members.demo.items[*].id
}
```
18 changes: 18 additions & 0 deletions examples/membergroup/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
variable "email" {
type = string
}

data "guance_members" "demo" {
filter = [
{
name = "email"
values = [var.email]
}
]
}

resource "guance_membergroup" "demo" {
name = "oac-demo"
member_ids = data.guance_members.demo.items[*].id
}

13 changes: 13 additions & 0 deletions examples/membergroup/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

terraform {
required_version = ">=0.12"

required_providers {
guance = {
source = "GuanceCloud/guance"
}
}
}

provider "guance" {
}
27 changes: 27 additions & 0 deletions examples/monitor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Monitor

**WORKING IN PROGRESS!**

A monitor is a set of checks that you can run against your data. A monitor watches your data over time and alerts you when certain conditions are met. For example, you can create a monitor that watches the average response time of your website and alerts you when the response time is greater than 1 second.

Monitors are made up of one or more checks. A check is a single test that you can run against your data. For example, you can create a check that watches the average response time of your website. You can also create a check that watches the percentage of 5xx errors in your logs.

Guance Cloud supports defining monitors, users can customize the configuration of detection rules and trigger conditions, and open the monitors to receive related alarm events triggered by the detection rules.

Relationships:

```mermaid
graph LR
A[Monitor] --> B[Alert Policy] --> C[Notification]
```

## Create

The first let me create a resource. We will send the create operation to the resource management service

```terraform
resource "guance_monitor" "demo" {
name = "oac-demo"
}
```
3 changes: 3 additions & 0 deletions examples/monitor/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "guance_monitor" "demo" {
name = "oac-demo"
}
13 changes: 13 additions & 0 deletions examples/monitor/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

terraform {
required_version = ">=0.12"

required_providers {
guance = {
source = "GuanceCloud/guance"
}
}
}

provider "guance" {
}
Loading

0 comments on commit 80ef196

Please sign in to comment.