Skip to content

Commit

Permalink
support enterprise_project_id in ces alarm rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason-Zhang9309 committed May 18, 2021
1 parent c0a0b92 commit fc5527a
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 52 deletions.
1 change: 1 addition & 0 deletions docs/data-sources/enterprise_project.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ DCS | huaweicloud_dcs_instance |
NAT | huaweicloud_nat_gateway | huaweicloud_nat_snat_rule<br>huaweicloud_nat_dnat_rule
CDM | huaweicloud_cdm_cluster |
CDN | huaweicloud_cdn_domain |
CES | huaweicloud_ces_alarmrule |
GaussDB | huaweicloud_gaussdb_cassandra_instance<br>huaweicloud_gaussdb_mysql_instance<br>huaweicloud_gaussdb_opengauss_instance |

## Argument Reference
Expand Down
3 changes: 3 additions & 0 deletions docs/resources/ces_alarmrule.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
9 changes: 9 additions & 0 deletions huaweicloud/resource_huaweicloud_ces_alarmrule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
69 changes: 69 additions & 0 deletions huaweicloud/resource_huaweicloud_ces_alarmrule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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)
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fc5527a

Please sign in to comment.