Skip to content

Commit

Permalink
resource/alicloud_schedulerx_app_group: Support modify monitor_config…
Browse files Browse the repository at this point in the history
…_json and monitor_contacts_json.
  • Loading branch information
ChenHanZhang committed Jan 16, 2025
1 parent 3b76ac7 commit de0376d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 48 deletions.
30 changes: 25 additions & 5 deletions alicloud/resource_alicloud_schedulerx_app_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,12 @@ func resourceAliCloudSchedulerxAppGroupCreate(d *schema.ResourceData, meta inter
return WrapError(err)
}
request = make(map[string]interface{})
query["Namespace"] = d.Get("namespace")
query["GroupId"] = d.Get("group_id")
if v, ok := d.GetOk("namespace"); ok {
query["Namespace"] = v
}
if v, ok := d.GetOk("group_id"); ok {
query["GroupId"] = v
}
query["RegionId"] = client.RegionId

if v, ok := d.GetOk("description"); ok {
Expand Down Expand Up @@ -209,12 +213,18 @@ func resourceAliCloudSchedulerxAppGroupRead(d *schema.ResourceData, meta interfa
if objectRaw["MaxJobs"] != nil {
d.Set("max_jobs", objectRaw["MaxJobs"])
}
if objectRaw["MonitorConfigJson"] != nil {
d.Set("monitor_config_json", objectRaw["MonitorConfigJson"])
}
if objectRaw["MonitorContactsJson"] != nil {
d.Set("monitor_contacts_json", objectRaw["MonitorContactsJson"])
}
if objectRaw["GroupId"] != nil {
d.Set("group_id", objectRaw["GroupId"])
}

parts := strings.Split(d.Id(), ":")
d.Set("namespace", parts[0])
if objectRaw["Namespace"] != nil {
d.Set("namespace", objectRaw["Namespace"])
}

return nil
}
Expand Down Expand Up @@ -242,11 +252,21 @@ func resourceAliCloudSchedulerxAppGroupUpdate(d *schema.ResourceData, meta inter
request["Description"] = d.Get("description")
}

if d.HasChange("monitor_config_json") {
update = true
request["MonitorConfigJson"] = d.Get("monitor_config_json")
}

if d.HasChange("app_version") {
update = true
request["AppVersion"] = d.Get("app_version")
}

if d.HasChange("monitor_contacts_json") {
update = true
request["MonitorContactsJson"] = d.Get("monitor_contacts_json")
}

if v, ok := d.GetOkExists("max_concurrency"); ok {
request["MaxConcurrency"] = v
}
Expand Down
44 changes: 22 additions & 22 deletions alicloud/resource_alicloud_schedulerx_app_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ import (
)

// Test Schedulerx AppGroup. >>> Resource test cases, automatically generated.
// Case 预发环境_20241220_杭州reigon 9654
func TestAccAliCloudSchedulerxAppGroup_basic9654(t *testing.T) {
// Case 预发环境_20250110_乌兰察布(代码只部署到乌兰察布,用这个用例测试) 9957
func TestAccAliCloudSchedulerxAppGroup_basic9957(t *testing.T) {
var v map[string]interface{}
resourceId := "alicloud_schedulerx_app_group.default"
ra := resourceAttrInit(resourceId, AlicloudSchedulerxAppGroupMap9654)
ra := resourceAttrInit(resourceId, AlicloudSchedulerxAppGroupMap9957)
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} {
return &SchedulerxServiceV2{testAccProvider.Meta().(*connectivity.AliyunClient)}
}, "DescribeSchedulerxAppGroup")
rac := resourceAttrCheckInit(rc, ra)
testAccCheck := rac.resourceAttrMapUpdateSet()
rand := acctest.RandIntRange(10000, 99999)
name := fmt.Sprintf("tf-testacc%sschedulerxappgroup%d", defaultRegionToTest, rand)
testAccConfig := resourceTestAccConfigFunc(resourceId, name, AlicloudSchedulerxAppGroupBasicDependence9654)
testAccConfig := resourceTestAccConfigFunc(resourceId, name, AlicloudSchedulerxAppGroupBasicDependence9957)
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
Expand All @@ -36,66 +36,66 @@ func TestAccAliCloudSchedulerxAppGroup_basic9654(t *testing.T) {
"namespace": "${alicloud_schedulerx_namespace.CreateNameSpace.namespace_uid}",
"group_id": "test-appgroup-pop-autotest",
"description": "appgroup 资源用例自动生成",
"monitor_contacts_json": "[{\\\"userName\\\":\\\"张三\\\",\\\"userPhone\\\":\\\"89756******\\\"},{\\\"userName\\\":\\\"李四\\\",\\\"ding\\\":\\\"http://www.example.com\\\"}]",
"monitor_contacts_json": "[{\\\"name\\\":\\\"用户-手机\\\"},{\\\"name\\\":\\\"用户-钉钉\\\"}]",
"enable_log": "false",
"app_name": "test-appgroup-pop-autotest",
"app_version": "1",
"namespace_name": "default",
"monitor_config_json": "{\\\"sendChannel\\\":\\\"sms,ding\\\"}",
"monitor_config_json": "{\\\"sendChannel\\\":\\\"sms,ding\\\",\\\"alarmType\\\": \\\"Contacts\\\",\\\"webhookIsAtAll\\\": \\\"false\\\"}",
"app_type": "1",
"max_jobs": "100",
"namespace_source": "schedulerx",
"schedule_busy_workers": "false",
"delete_jobs": "false",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"namespace": CHECKSET,
"group_id": "test-appgroup-pop-autotest",
"description": "appgroup 资源用例自动生成",
"monitor_contacts_json": "[{\"userName\":\"张三\",\"userPhone\":\"89756******\"},{\"userName\":\"李四\",\"ding\":\"http://www.example.com\"}]",
"monitor_contacts_json": CHECKSET,
"enable_log": "false",
"app_name": "test-appgroup-pop-autotest",
"app_version": "1",
"app_version": CHECKSET,
"namespace_name": "default",
"monitor_config_json": "{\"sendChannel\":\"sms,ding\"}",
"monitor_config_json": CHECKSET,
"app_type": "1",
"max_jobs": "100",
"namespace_source": "schedulerx",
"schedule_busy_workers": "false",
"delete_jobs": "false",
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"description": "appgroup 资源用例自动生成_update",
"app_version": "2",
"max_concurrency": "500",
"delete_jobs": "true",
"description": "appgroup 资源用例自动生成_update",
"monitor_contacts_json": "[{\\\"name\\\":\\\"用户-飞书\\\"},{\\\"name\\\":\\\"用户-钉钉\\\"}]",
"app_version": "2",
"monitor_config_json": "{\\\"sendChannel\\\":\\\"sms,ding\\\",\\\"alarmType\\\": \\\"Contacts\\\",\\\"webhookIsAtAll\\\": \\\"true\\\"}",
"max_concurrency": "500",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"description": "appgroup 资源用例自动生成_update",
"app_version": "2",
"max_concurrency": "500",
"delete_jobs": "true",
"description": "appgroup 资源用例自动生成_update",
"monitor_contacts_json": CHECKSET,
"app_version": CHECKSET,
"monitor_config_json": CHECKSET,
"max_concurrency": "500",
}),
),
},
{
ResourceName: resourceId,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"app_type", "enable_log", "max_concurrency", "monitor_config_json", "monitor_contacts_json", "namespace_name", "namespace_source", "schedule_busy_workers", "delete_jobs"},
ImportStateVerifyIgnore: []string{"app_type", "enable_log", "max_concurrency", "namespace_name", "namespace_source", "schedule_busy_workers"},
},
},
})
}

var AlicloudSchedulerxAppGroupMap9654 = map[string]string{}
var AlicloudSchedulerxAppGroupMap9957 = map[string]string{}

func AlicloudSchedulerxAppGroupBasicDependence9654(name string) string {
func AlicloudSchedulerxAppGroupBasicDependence9957(name string) string {
return fmt.Sprintf(`
variable "name" {
default = "%s"
Expand Down
2 changes: 1 addition & 1 deletion alicloud/service_alicloud_schedulerx_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ func (s *SchedulerxServiceV2) DescribeSchedulerxAppGroup(id string) (object map[
if len(parts) != 2 {
err = WrapError(fmt.Errorf("invalid Resource Id %s. Expected parts' length %d, got %d", id, 2, len(parts)))
}
action := "GetAppGroup"
conn, err := client.NewSchedulerxClient()
if err != nil {
return object, WrapError(err)
Expand All @@ -198,6 +197,7 @@ func (s *SchedulerxServiceV2) DescribeSchedulerxAppGroup(id string) (object map[
request["GroupId"] = parts[1]
request["Namespace"] = parts[0]
request["RegionId"] = client.RegionId
action := "GetAppGroup"

runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
Expand Down
32 changes: 12 additions & 20 deletions website/docs/r/schedulerx_app_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,12 @@ Provides a Schedulerx App Group resource.

For information about Schedulerx App Group and how to use it, see [What is App Group](https://www.alibabacloud.com/help/en/).

-> **NOTE:** Available since v1.240.0.
-> **NOTE:** Available since v1.242.0.

## Example Usage

Basic Usage

<div style="display: block;margin-bottom: 40px;"><div class="oics-button" style="float: right;position: absolute;margin-bottom: 10px;">
<a href="https://api.aliyun.com/terraform?resource=alicloud_schedulerx_app_group&exampleId=7c4026fb-fc32-b667-2eb4-7dc928fd7538610bd0b9&activeTab=example&spm=docs.r.schedulerx_app_group.0.7c4026fbfc&intl_lang=EN_US" target="_blank">
<img alt="Open in AliCloud" src="https://img.alicdn.com/imgextra/i1/O1CN01hjjqXv1uYUlY56FyX_!!6000000006049-55-tps-254-36.svg" style="max-height: 44px; max-width: 100%;">
</a>
</div></div>

```terraform
variable "name" {
default = "terraform-example"
Expand All @@ -37,24 +31,22 @@ provider "alicloud" {
resource "alicloud_schedulerx_namespace" "CreateNameSpace" {
namespace_name = var.name
description = var.name
description = "由appgroup 资源测试用例前置步骤创建"
}
resource "alicloud_schedulerx_app_group" "default" {
max_jobs = "100"
monitor_contacts_json = jsonencode([{ "userName" : "name1", "userPhone" : "89756******" }, { "userName" : "name2", "ding" : "http://www.example.com" }])
delete_jobs = "false"
app_type = "1"
namespace_source = "schedulerx"
namespace = alicloud_schedulerx_namespace.CreateNameSpace.namespace_uid
group_id = "example-appgroup-pop-autoexample"
namespace_name = "default"
description = var.name
monitor_config_json = jsonencode({ "sendChannel" : "sms,ding" })
app_version = "1"
description = "appgroup 资源用例自动生成"
monitor_contacts_json = "[{\"name\":\"唐涛-手机\"},{\"name\":\"唐涛-钉钉\"}]"
app_name = "example-appgroup-pop-autoexample"
namespace = alicloud_schedulerx_namespace.CreateNameSpace.namespace_uid
enable_log = "false"
schedule_busy_workers = "false"
app_version = "1"
namespace_name = "default"
monitor_config_json = "{\"sendChannel\":\"sms,ding\",\"alarmType\": \"Contacts\",\"webhookIsAtAll\": \"false\"}"
app_type = "1"
max_jobs = "100"
namespace_source = "schedulerx"
}
```

Expand Down

0 comments on commit de0376d

Please sign in to comment.