diff --git a/docs/data-sources/enterprise_project.md b/docs/data-sources/enterprise_project.md index 2222ed4bcf..f678862d60 100644 --- a/docs/data-sources/enterprise_project.md +++ b/docs/data-sources/enterprise_project.md @@ -32,6 +32,7 @@ DCS | huaweicloud_dcs_instance | NAT | huaweicloud_nat_gateway | huaweicloud_nat_snat_rule
huaweicloud_nat_dnat_rule CDM | huaweicloud_cdm_cluster | CDN | huaweicloud_cdn_domain | +CES | huaweicloud_ces_alarmrule | GaussDB | huaweicloud_gaussdb_cassandra_instance
huaweicloud_gaussdb_mysql_instance
huaweicloud_gaussdb_opengauss_instance | ## Argument Reference diff --git a/docs/resources/ces_alarmrule.md b/docs/resources/ces_alarmrule.md index 2ab5fbf8ad..30db66d482 100644 --- a/docs/resources/ces_alarmrule.md +++ b/docs/resources/ces_alarmrule.md @@ -70,6 +70,9 @@ The following arguments are supported: * `alarm_action_enabled` - (Optional, Bool) Specifies whether to enable the action to be triggered by an alarm. The default value is true. +* `enterprise_project_id` - (Optional, String, ForceNew) Specifies the enterprise project id of the alarm rule. + Changing this creates a new resource. + -> **Note** If alarm_action_enabled is set to true, either alarm_actions or ok_actions cannot be empty. If alarm_actions and ok_actions coexist, their corresponding notification_list must be of the **same value**. diff --git a/go.mod b/go.mod index acc34f44c0..cfef052bd0 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/hashicorp/errwrap v1.0.0 github.com/hashicorp/go-multierror v1.0.0 github.com/hashicorp/terraform-plugin-sdk v1.16.0 - github.com/huaweicloud/golangsdk v0.0.0-20210517025840-92b32656bde0 + github.com/huaweicloud/golangsdk v0.0.0-20210518015043-4abbff8edf44 github.com/jen20/awspolicyequivalence v1.1.0 github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa // indirect github.com/stretchr/testify v1.4.0 diff --git a/go.sum b/go.sum index 6f9470ddad..7401394fa1 100644 --- a/go.sum +++ b/go.sum @@ -204,8 +204,8 @@ github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596/go.mod github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= -github.com/huaweicloud/golangsdk v0.0.0-20210517025840-92b32656bde0 h1:ap/m0dp+LvmAHQsQmSwYU0yOKxYz2b7iYpbgtUnXO0Y= -github.com/huaweicloud/golangsdk v0.0.0-20210517025840-92b32656bde0/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0= +github.com/huaweicloud/golangsdk v0.0.0-20210518015043-4abbff8edf44 h1:zaFprOpu3ZXBWJ2OLs4SvVJp4u/RMPImhz1131Hdck0= +github.com/huaweicloud/golangsdk v0.0.0-20210518015043-4abbff8edf44/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg= github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= diff --git a/huaweicloud/resource_huaweicloud_ces_alarmrule.go b/huaweicloud/resource_huaweicloud_ces_alarmrule.go index d48764e47b..4752d8293c 100644 --- a/huaweicloud/resource_huaweicloud_ces_alarmrule.go +++ b/huaweicloud/resource_huaweicloud_ces_alarmrule.go @@ -184,6 +184,13 @@ func resourceAlarmRule() *schema.Resource { Default: true, }, + "enterprise_project_id": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Computed: true, + }, + "alarm_state": { Type: schema.TypeString, Computed: true, @@ -305,6 +312,7 @@ func resourceAlarmRuleCreate(d *schema.ResourceData, meta interface{}) error { InsufficientdataActions: getAlarmAction(d, "insufficientdata_actions"), AlarmEnabled: d.Get("alarm_enabled").(bool), AlarmActionEnabled: d.Get("alarm_action_enabled").(bool), + EnterpriseProjectID: GetEnterpriseProjectID(d, config), } log.Printf("[DEBUG] Create %s Options: %#v", nameCESAR, createOpts) @@ -354,6 +362,7 @@ func resourceAlarmRuleRead(d *schema.ResourceData, meta interface{}) error { d.Set("alarm_action_enabled", m["alarm_action_enabled"]), d.Set("alarm_state", m["alarm_state"]), d.Set("update_time", m["update_time"]), + d.Set("enterprise_project_id", m["enterprise_project_id"]), ) if mErr.ErrorOrNil() != nil { return mErr diff --git a/huaweicloud/resource_huaweicloud_ces_alarmrule_test.go b/huaweicloud/resource_huaweicloud_ces_alarmrule_test.go index 823c176444..e68caabc8b 100644 --- a/huaweicloud/resource_huaweicloud_ces_alarmrule_test.go +++ b/huaweicloud/resource_huaweicloud_ces_alarmrule_test.go @@ -50,6 +50,32 @@ func TestAccCESAlarmRule_basic(t *testing.T) { }) } +func TestAccCESAlarmRule_withEpsId(t *testing.T) { + var ar alarmrule.AlarmRule + rName := fmt.Sprintf("tf-acc-%s", acctest.RandString(5)) + resourceName := "huaweicloud_ces_alarmrule.alarmrule_1" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckEpsID(t) }, + Providers: testAccProviders, + CheckDestroy: testCESAlarmRuleDestroy, + Steps: []resource.TestStep{ + { + Config: testCESAlarmRule_withEpsId(rName), + Check: resource.ComposeTestCheckFunc( + testCESAlarmRuleExists(resourceName, &ar), + resource.TestCheckResourceAttr(resourceName, "alarm_name", fmt.Sprintf("rule-%s", rName)), + resource.TestCheckResourceAttr(resourceName, "alarm_enabled", "true"), + resource.TestCheckResourceAttr(resourceName, "alarm_action_enabled", "true"), + resource.TestCheckResourceAttr(resourceName, "alarm_level", "2"), + resource.TestCheckResourceAttr(resourceName, "condition.0.value", "6"), + resource.TestCheckResourceAttr(resourceName, "enterprise_project_id", HW_ENTERPRISE_PROJECT_ID_TEST), + ), + }, + }, + }) +} + func testCESAlarmRuleDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*config.Config) networkingClient, err := config.CesV1Client(HW_REGION_NAME) @@ -132,6 +158,7 @@ resource "huaweicloud_compute_instance" "vm_1" { uuid = data.huaweicloud_vpc_subnet.test.id } } + resource "huaweicloud_smn_topic" "topic_1" { name = "smn-%s" display_name = "The display name of smn topic" @@ -150,11 +177,13 @@ resource "huaweicloud_ces_alarmrule" "alarmrule_1" { metric { namespace = "SYS.ECS" metric_name = "network_outgoing_bytes_rate_inband" + dimensions { name = "instance_id" value = huaweicloud_compute_instance.vm_1.id } } + condition { period = 300 filter = "average" @@ -187,11 +216,13 @@ resource "huaweicloud_ces_alarmrule" "alarmrule_1" { metric { namespace = "SYS.ECS" metric_name = "network_outgoing_bytes_rate_inband" + dimensions { name = "instance_id" value = huaweicloud_compute_instance.vm_1.id } } + condition { period = 300 filter = "average" @@ -210,3 +241,41 @@ resource "huaweicloud_ces_alarmrule" "alarmrule_1" { } `, testCESAlarmRule_base(rName), rName) } + +func testCESAlarmRule_withEpsId(rName string) string { + return fmt.Sprintf(` +%s + +resource "huaweicloud_ces_alarmrule" "alarmrule_1" { + alarm_name = "rule-%s" + alarm_action_enabled = true + enterprise_project_id = "%s" + + metric { + namespace = "SYS.ECS" + metric_name = "network_outgoing_bytes_rate_inband" + + dimensions { + name = "instance_id" + value = huaweicloud_compute_instance.vm_1.id + } + } + + condition { + period = 300 + filter = "average" + comparison_operator = ">" + value = 6 + unit = "B/s" + count = 1 + } + + alarm_actions { + type = "notification" + notification_list = [ + huaweicloud_smn_topic.topic_1.topic_urn + ] + } +} +`, testCESAlarmRule_base(rName), rName, HW_ENTERPRISE_PROJECT_ID_TEST) +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/cloudeyeservice/alarmrule/requests.go b/vendor/github.com/huaweicloud/golangsdk/openstack/cloudeyeservice/alarmrule/requests.go index 17ac4ee15c..d8c66456b0 100644 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/cloudeyeservice/alarmrule/requests.go +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/cloudeyeservice/alarmrule/requests.go @@ -48,6 +48,7 @@ type CreateOpts struct { OkActions []ActionOpts `json:"ok_actions,omitempty"` AlarmEnabled bool `json:"alarm_enabled"` AlarmActionEnabled bool `json:"alarm_action_enabled"` + EnterpriseProjectID string `json:"enterprise_project_id,omitempty"` } func (opts CreateOpts) ToAlarmRuleCreateMap() (map[string]interface{}, error) { diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/cloudeyeservice/alarmrule/results.go b/vendor/github.com/huaweicloud/golangsdk/openstack/cloudeyeservice/alarmrule/results.go index a2d1b9af01..68b9cade8b 100644 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/cloudeyeservice/alarmrule/results.go +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/cloudeyeservice/alarmrule/results.go @@ -58,6 +58,7 @@ type AlarmRule struct { AlarmActionEnabled bool `json:"alarm_action_enabled"` UpdateTime int64 `json:"update_time"` AlarmState string `json:"alarm_state"` + EnterpriseProjectID string `json:"enterprise_project_id"` } type GetResult struct { diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/dds/v3/instances/requests.go b/vendor/github.com/huaweicloud/golangsdk/openstack/dds/v3/instances/requests.go index 5dd697a3b9..7e4b19f9bc 100644 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/dds/v3/instances/requests.go +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/dds/v3/instances/requests.go @@ -8,19 +8,20 @@ import ( ) type CreateOpts struct { - Name string `json:"name" required:"true"` - DataStore DataStore `json:"datastore" required:"true"` - Region string `json:"region" required:"true"` - AvailabilityZone string `json:"availability_zone" required:"true"` - VpcId string `json:"vpc_id" required:"true"` - SubnetId string `json:"subnet_id" required:"true"` - SecurityGroupId string `json:"security_group_id" required:"true"` - Password string `json:"password" required:"true"` - DiskEncryptionId string `json:"disk_encryption_id,omitempty"` - Ssl string `json:"ssl_option,omitempty"` - Mode string `json:"mode" required:"true"` - Flavor []Flavor `json:"flavor" required:"true"` - BackupStrategy BackupStrategy `json:"backup_strategy,omitempty"` + Name string `json:"name" required:"true"` + DataStore DataStore `json:"datastore" required:"true"` + Region string `json:"region" required:"true"` + AvailabilityZone string `json:"availability_zone" required:"true"` + VpcId string `json:"vpc_id" required:"true"` + SubnetId string `json:"subnet_id" required:"true"` + SecurityGroupId string `json:"security_group_id" required:"true"` + Password string `json:"password" required:"true"` + DiskEncryptionId string `json:"disk_encryption_id,omitempty"` + Ssl string `json:"ssl_option,omitempty"` + Mode string `json:"mode" required:"true"` + Flavor []Flavor `json:"flavor" required:"true"` + BackupStrategy BackupStrategy `json:"backup_strategy,omitempty"` + EnterpriseProjectID string `json:"enterprise_project_id,omitempty"` } type DataStore struct { diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/dds/v3/instances/results.go b/vendor/github.com/huaweicloud/golangsdk/openstack/dds/v3/instances/results.go index ba9f25ab70..addc9fead2 100644 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/dds/v3/instances/results.go +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/dds/v3/instances/results.go @@ -14,20 +14,21 @@ type CreateResult struct { } type Instance struct { - Id string `json:"id"` - Name string `json:"name"` - DataStore DataStore `json:"datastore"` - Status string `json:"status"` - Region string `json:"region"` - AvailabilityZone string `json:"availability_zone"` - VpcId string `json:"vpc_id"` - SubnetId string `json:"subnet_id"` - SecurityGroupId string `json:"security_group_id"` - DiskEncryptionId string `json:"disk_encryption_id"` - Ssl string `json:"ssl_option"` - Mode string `json:"mode"` - Flavor []FlavorOpt `json:"flavor"` - BackupStrategy BackupStrategyOpt `json:"backup_strategy"` + Id string `json:"id"` + Name string `json:"name"` + DataStore DataStore `json:"datastore"` + Status string `json:"status"` + Region string `json:"region"` + AvailabilityZone string `json:"availability_zone"` + VpcId string `json:"vpc_id"` + SubnetId string `json:"subnet_id"` + SecurityGroupId string `json:"security_group_id"` + DiskEncryptionId string `json:"disk_encryption_id"` + Ssl string `json:"ssl_option"` + Mode string `json:"mode"` + Flavor []FlavorOpt `json:"flavor"` + BackupStrategy BackupStrategyOpt `json:"backup_strategy"` + EnterpriseProjectID string `json:"enterprise_project_id"` } type FlavorOpt struct { @@ -77,27 +78,28 @@ type ListInstanceResponse struct { } type InstanceResponse struct { - Id string `json:"id"` - Name string `json:"name"` - Status string `json:"status"` - Port string `json:"port"` - Mode string `json:"mode"` - Region string `json:"region"` - DataStore DataStore `json:"datastore"` - Engine string `json:"engine"` - Created string `json:"created"` - Updated string `json:"updated"` - DbUserName string `json:"db_user_name"` - Ssl int `json:"ssl"` - VpcId string `json:"vpc_id"` - SubnetId string `json:"subnet_id"` - SecurityGroupId string `json:"security_group_id"` - BackupStrategy BackupStrategy `json:"backup_strategy"` - MaintenanceWindow string `json:"maintenance_window"` - Groups []Group `json:"groups"` - DiskEncryptionId string `json:"disk_encryption_id"` - TimeZone string `json:"time_zone"` - Actions []string `json:"actions"` + Id string `json:"id"` + Name string `json:"name"` + Status string `json:"status"` + Port string `json:"port"` + Mode string `json:"mode"` + Region string `json:"region"` + DataStore DataStore `json:"datastore"` + Engine string `json:"engine"` + Created string `json:"created"` + Updated string `json:"updated"` + DbUserName string `json:"db_user_name"` + Ssl int `json:"ssl"` + VpcId string `json:"vpc_id"` + SubnetId string `json:"subnet_id"` + SecurityGroupId string `json:"security_group_id"` + BackupStrategy BackupStrategy `json:"backup_strategy"` + MaintenanceWindow string `json:"maintenance_window"` + Groups []Group `json:"groups"` + DiskEncryptionId string `json:"disk_encryption_id"` + TimeZone string `json:"time_zone"` + Actions []string `json:"actions"` + EnterpriseProjectID string `json:"enterprise_project_id"` } type Group struct { diff --git a/vendor/modules.txt b/vendor/modules.txt index 3ef31b1174..3f26015651 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -258,7 +258,7 @@ github.com/hashicorp/terraform-svchost/auth github.com/hashicorp/terraform-svchost/disco # github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d github.com/hashicorp/yamux -# github.com/huaweicloud/golangsdk v0.0.0-20210517025840-92b32656bde0 +# github.com/huaweicloud/golangsdk v0.0.0-20210518015043-4abbff8edf44 ## explicit github.com/huaweicloud/golangsdk github.com/huaweicloud/golangsdk/internal