Skip to content

Commit

Permalink
Merge pull request #156 from volcengine/feat/volc
Browse files Browse the repository at this point in the history
Feat/volc
  • Loading branch information
zpp12354321 committed Jan 11, 2024
2 parents 9f598e5 + 72b1dab commit 87c1039
Show file tree
Hide file tree
Showing 32 changed files with 3,461 additions and 1 deletion.
2 changes: 1 addition & 1 deletion common/common_volcengine_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package common

const (
TerraformProviderName = "terraform-provider-volcengine"
TerraformProviderVersion = "0.0.135"
TerraformProviderVersion = "0.0.136"
)
1 change: 1 addition & 0 deletions docgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ var resourceKeys = map[string]string{
"direct_connect": "DIRECT_CONNECT",
"alb": "ALB",
"bandwidth_package": "BANDWIDTH_PACKAGE",
"cloud_monitor": "CLOUD_MONITOR",
}

type Products struct {
Expand Down
5 changes: 5 additions & 0 deletions example/cloudMonitorContact/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "volcengine_cloud_monitor_contact" "default" {
name = "tf-acc"
email = "192*****72@****.com"
phone = "180****27812"
}
5 changes: 5 additions & 0 deletions example/cloudMonitorContactGroup/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "volcengine_cloud_monitor_contact_group" "foo" {
name = "tfgroup"
description = "tftest"
contacts_id_list = ["1737376113733353472", "1737375997680111616"]
}
31 changes: 31 additions & 0 deletions example/cloudMonitorEventRule/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
resource "volcengine_cloud_monitor_event_rule" "foo" {
status = "enable"
contact_methods = ["Phone", "TLS", "MQ"]
event_source = "ecs"
level = "notice"
rule_name = "tftest1"
effective_time {
start_time = "01:00"
end_time = "22:00"
}
event_type = ["ecs:Disk:DiskError.Redeploy.Canceled"]
contact_group_ids = ["1737941730782699520", "1737940985502777344"]
filter_pattern {
type = ["ecs:Disk:DiskError.Redeploy.Canceled"]
source = "ecs"
}
message_queue {
instance_id = "kafka-cnoe4rfrsqfb1d64"
vpc_id = "vpc-2d68hz41j7qio58ozfd6jxgtb"
type = "kafka"
region = "*****"
topic = "tftest"
}
tls_target {
project_name = "tf-test"
region_name_cn = "*****"
region_name_en = "*****"
project_id = "17ba378d-de43-495e-8906-03ae6567b376"
topic_id = "7ce12237-6670-44a7-9d79-2e36961586e6"
}
}
43 changes: 43 additions & 0 deletions example/cloudMonitorRule/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
resource "volcengine_cloud_monitor_rule" "foo" {
rule_name = "acc-test-rule"
description = "acc-test"
namespace = "VCM_ECS"
sub_namespace = "Storage"
level = "warning"
enable_state = "disable"
evaluation_count = 5
effect_start_at = "00:15"
effect_end_at = "22:55"
silence_time = 5
alert_methods = ["Email", "Webhook"]
web_hook = "http://alert.volc.com/callback"
contact_group_ids = ["174284616403161****"]
multiple_conditions = true
condition_operator = "||"
regions = ["cn-beijing"]
original_dimensions {
key = "ResourceID"
value = ["*"]
}
original_dimensions {
key = "DiskName"
value = ["vda", "vda1"]
}
conditions {
metric_name = "DiskUsageAvail"
metric_unit = "Megabytes"
statistics = "avg"
comparison_operator = ">"
threshold = "100"
}
conditions {
metric_name = "DiskUsageUtilization"
metric_unit = "Percent"
statistics = "avg"
comparison_operator = ">"
threshold = "90"
}
recovery_notify {
enable = true
}
}
3 changes: 3 additions & 0 deletions example/dataCloudMonitorContactGroups/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "volcengine_cloud_monitor_contact_groups" "foo"{
name = "tftest"
}
3 changes: 3 additions & 0 deletions example/dataCloudMonitorContacts/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "volcengine_cloud_monitor_contacts" "foo" {
ids = ["17******516", "1712**********0"]
}
3 changes: 3 additions & 0 deletions example/dataCloudMonitorEventRules/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "volcengine_cloud_monitor_event_rules" "foo"{
rule_name = "tftest"
}
3 changes: 3 additions & 0 deletions example/dataCloudMonitorRules/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "volcengine_cloud_monitor_rules" "foo" {
ids = ["174402785374661****"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package cloud_monitor_contact

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
ve "github.com/volcengine/terraform-provider-volcengine/common"
)

func DataSourceVolcengineCloudMonitorContacts() *schema.Resource {
return &schema.Resource{
Read: dataSourceVolcengineCloudMonitorContactsRead,
Schema: map[string]*schema.Schema{
"ids": {
Type: schema.TypeSet,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Set: schema.HashString,
Description: "A list of Contact IDs.",
},
"output_file": {
Type: schema.TypeString,
Optional: true,
Description: "File name where to save data source results.",
},
"total_count": {
Type: schema.TypeInt,
Computed: true,
Description: "The total count of query.",
},
"contacts": {
Description: "The collection of query.",
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: "The ID of contact.",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "The name of contact.",
},
"phone": {
Type: schema.TypeString,
Computed: true,
Description: "The phone of contact.",
},
"email": {
Type: schema.TypeString,
Computed: true,
Description: "The email of contact.",
},
},
},
},
},
}
}

func dataSourceVolcengineCloudMonitorContactsRead(d *schema.ResourceData, meta interface{}) error {
service := NewService(meta.(*ve.SdkClient))
return ve.DefaultDispatcher().Data(service, d, DataSourceVolcengineCloudMonitorContacts())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package cloud_monitor_contact

import (
"fmt"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
ve "github.com/volcengine/terraform-provider-volcengine/common"
)

/*
Import
CloudMonitor Contact can be imported using the id, e.g.
```
$ terraform import volcengine_cloud_monitor_contact.default 145258255725730****
```
*/

func ResourceVolcengineCloudMonitorContact() *schema.Resource {
return &schema.Resource{
Create: resourceVolcengineCloudMonitorContactCreate,
Read: resourceVolcengineCloudMonitorContactRead,
Update: resourceVolcengineCloudMonitorContactUpdate,
Delete: resourceVolcengineCloudMonitorContactDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(30 * time.Minute),
Update: schema.DefaultTimeout(30 * time.Minute),
Delete: schema.DefaultTimeout(30 * time.Minute),
},
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "The name of contact.",
},
"email": {
Type: schema.TypeString,
Required: true,
Description: "The email of contact.",
},
"phone": {
Type: schema.TypeString,
Optional: true,
Description: "The phone of contact.",
},
},
}
}

func resourceVolcengineCloudMonitorContactCreate(d *schema.ResourceData, meta interface{}) (err error) {
service := NewService(meta.(*ve.SdkClient))
err = ve.DefaultDispatcher().Create(service, d, ResourceVolcengineCloudMonitorContact())
if err != nil {
return fmt.Errorf("error on creating Contact %q, %w", d.Id(), err)
}
return resourceVolcengineCloudMonitorContactRead(d, meta)
}

func resourceVolcengineCloudMonitorContactRead(d *schema.ResourceData, meta interface{}) (err error) {
service := NewService(meta.(*ve.SdkClient))
err = ve.DefaultDispatcher().Read(service, d, ResourceVolcengineCloudMonitorContact())
if err != nil {
return fmt.Errorf("error on reading Contact %q, %w", d.Id(), err)
}
return err
}

func resourceVolcengineCloudMonitorContactUpdate(d *schema.ResourceData, meta interface{}) (err error) {
service := NewService(meta.(*ve.SdkClient))
err = ve.DefaultDispatcher().Update(service, d, ResourceVolcengineCloudMonitorContact())
if err != nil {
return fmt.Errorf("error on updating Contact %q, %w", d.Id(), err)
}
return resourceVolcengineCloudMonitorContactRead(d, meta)
}

func resourceVolcengineCloudMonitorContactDelete(d *schema.ResourceData, meta interface{}) (err error) {
service := NewService(meta.(*ve.SdkClient))
err = ve.DefaultDispatcher().Delete(service, d, ResourceVolcengineCloudMonitorContact())
if err != nil {
return fmt.Errorf("error on deleting Contact %q, %w", d.Id(), err)
}
return err
}
Loading

0 comments on commit 87c1039

Please sign in to comment.