-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Resource: alicloud_schedulerx_app_group; New Resource: alicloud_s…
…chedulerx_job; resource/alicloud_schedulerx_namespace: add new attribute namespace_uid.
- Loading branch information
1 parent
0ed2303
commit 981e821
Showing
12 changed files
with
2,601 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,322 @@ | ||
// Package alicloud. This file is generated automatically. Please do not modify it manually, thank you! | ||
package alicloud | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
util "github.com/alibabacloud-go/tea-utils/service" | ||
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func resourceAliCloudSchedulerxAppGroup() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceAliCloudSchedulerxAppGroupCreate, | ||
Read: resourceAliCloudSchedulerxAppGroupRead, | ||
Update: resourceAliCloudSchedulerxAppGroupUpdate, | ||
Delete: resourceAliCloudSchedulerxAppGroupDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
Timeouts: &schema.ResourceTimeout{ | ||
Create: schema.DefaultTimeout(5 * time.Minute), | ||
Update: schema.DefaultTimeout(5 * time.Minute), | ||
Delete: schema.DefaultTimeout(5 * time.Minute), | ||
}, | ||
Schema: map[string]*schema.Schema{ | ||
"app_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"app_type": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
}, | ||
"app_version": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"delete_jobs": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"enable_log": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
}, | ||
"group_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"max_concurrency": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
}, | ||
"max_jobs": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
ForceNew: true, | ||
}, | ||
"monitor_config_json": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"monitor_contacts_json": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"namespace": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"namespace_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"namespace_source": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"schedule_busy_workers": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceAliCloudSchedulerxAppGroupCreate(d *schema.ResourceData, meta interface{}) error { | ||
|
||
client := meta.(*connectivity.AliyunClient) | ||
|
||
action := "CreateAppGroup" | ||
var request map[string]interface{} | ||
var response map[string]interface{} | ||
query := make(map[string]interface{}) | ||
conn, err := client.NewSchedulerxClient() | ||
if err != nil { | ||
return WrapError(err) | ||
} | ||
request = make(map[string]interface{}) | ||
query["Namespace"] = d.Get("namespace") | ||
query["GroupId"] = d.Get("group_id") | ||
query["RegionId"] = client.RegionId | ||
|
||
if v, ok := d.GetOk("description"); ok { | ||
query["Description"] = StringPointer(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("monitor_config_json"); ok { | ||
query["MonitorConfigJson"] = StringPointer(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("max_jobs"); ok { | ||
query["MaxJobs"] = StringPointer(strconv.Itoa(v.(int))) | ||
} | ||
|
||
if v, ok := d.GetOk("app_type"); ok { | ||
query["AppType"] = StringPointer(strconv.Itoa(v.(int))) | ||
} | ||
|
||
if v, ok := d.GetOk("schedule_busy_workers"); ok { | ||
query["ScheduleBusyWorkers"] = StringPointer(strconv.FormatBool(v.(bool))) | ||
} | ||
|
||
if v, ok := d.GetOk("namespace_source"); ok { | ||
query["NamespaceSource"] = StringPointer(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("namespace_name"); ok { | ||
query["NamespaceName"] = StringPointer(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("enable_log"); ok { | ||
query["EnableLog"] = StringPointer(strconv.FormatBool(v.(bool))) | ||
} | ||
|
||
if v, ok := d.GetOk("app_name"); ok { | ||
query["AppName"] = StringPointer(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("app_version"); ok { | ||
query["AppVersion"] = StringPointer(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("monitor_contacts_json"); ok { | ||
query["MonitorContactsJson"] = StringPointer(v.(string)) | ||
} | ||
|
||
runtime := util.RuntimeOptions{} | ||
runtime.SetAutoretry(true) | ||
wait := incrementalWait(3*time.Second, 5*time.Second) | ||
err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { | ||
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("GET"), StringPointer("2019-04-30"), StringPointer("AK"), query, request, &runtime) | ||
if err != nil { | ||
if NeedRetry(err) { | ||
wait() | ||
return resource.RetryableError(err) | ||
} | ||
return resource.NonRetryableError(err) | ||
} | ||
return nil | ||
}) | ||
addDebug(action, response, request) | ||
|
||
if err != nil { | ||
return WrapErrorf(err, DefaultErrorMsg, "alicloud_schedulerx_app_group", action, AlibabaCloudSdkGoERROR) | ||
} | ||
|
||
d.SetId(fmt.Sprintf("%v:%v", query["Namespace"], query["GroupId"])) | ||
|
||
return resourceAliCloudSchedulerxAppGroupRead(d, meta) | ||
} | ||
|
||
func resourceAliCloudSchedulerxAppGroupRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*connectivity.AliyunClient) | ||
schedulerxServiceV2 := SchedulerxServiceV2{client} | ||
|
||
objectRaw, err := schedulerxServiceV2.DescribeSchedulerxAppGroup(d.Id()) | ||
if err != nil { | ||
if !d.IsNewResource() && NotFoundError(err) { | ||
log.Printf("[DEBUG] Resource alicloud_schedulerx_app_group DescribeSchedulerxAppGroup Failed!!! %s", err) | ||
d.SetId("") | ||
return nil | ||
} | ||
return WrapError(err) | ||
} | ||
|
||
if objectRaw["AppName"] != nil { | ||
d.Set("app_name", objectRaw["AppName"]) | ||
} | ||
if objectRaw["AppVersion"] != nil { | ||
d.Set("app_version", objectRaw["AppVersion"]) | ||
} | ||
if objectRaw["Description"] != nil { | ||
d.Set("description", objectRaw["Description"]) | ||
} | ||
if objectRaw["MaxJobs"] != nil { | ||
d.Set("max_jobs", objectRaw["MaxJobs"]) | ||
} | ||
if objectRaw["GroupId"] != nil { | ||
d.Set("group_id", objectRaw["GroupId"]) | ||
} | ||
|
||
parts := strings.Split(d.Id(), ":") | ||
d.Set("namespace", parts[0]) | ||
|
||
return nil | ||
} | ||
|
||
func resourceAliCloudSchedulerxAppGroupUpdate(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*connectivity.AliyunClient) | ||
var request map[string]interface{} | ||
var response map[string]interface{} | ||
var query map[string]interface{} | ||
update := false | ||
|
||
parts := strings.Split(d.Id(), ":") | ||
action := "UpdateAppGroup" | ||
conn, err := client.NewSchedulerxClient() | ||
if err != nil { | ||
return WrapError(err) | ||
} | ||
request = make(map[string]interface{}) | ||
query = make(map[string]interface{}) | ||
request["Namespace"] = parts[0] | ||
request["GroupId"] = parts[1] | ||
request["RegionId"] = client.RegionId | ||
if d.HasChange("description") { | ||
update = true | ||
request["Description"] = d.Get("description") | ||
} | ||
|
||
if d.HasChange("app_version") { | ||
update = true | ||
request["AppVersion"] = d.Get("app_version") | ||
} | ||
|
||
if v, ok := d.GetOkExists("max_concurrency"); ok { | ||
request["MaxConcurrency"] = v | ||
} | ||
if update { | ||
runtime := util.RuntimeOptions{} | ||
runtime.SetAutoretry(true) | ||
wait := incrementalWait(3*time.Second, 5*time.Second) | ||
err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { | ||
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-04-30"), StringPointer("AK"), query, request, &runtime) | ||
if err != nil { | ||
if NeedRetry(err) { | ||
wait() | ||
return resource.RetryableError(err) | ||
} | ||
return resource.NonRetryableError(err) | ||
} | ||
return nil | ||
}) | ||
addDebug(action, response, request) | ||
if err != nil { | ||
return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR) | ||
} | ||
} | ||
|
||
return resourceAliCloudSchedulerxAppGroupRead(d, meta) | ||
} | ||
|
||
func resourceAliCloudSchedulerxAppGroupDelete(d *schema.ResourceData, meta interface{}) error { | ||
|
||
client := meta.(*connectivity.AliyunClient) | ||
parts := strings.Split(d.Id(), ":") | ||
action := "DeleteAppGroup" | ||
var request map[string]interface{} | ||
var response map[string]interface{} | ||
query := make(map[string]interface{}) | ||
conn, err := client.NewSchedulerxClient() | ||
if err != nil { | ||
return WrapError(err) | ||
} | ||
request = make(map[string]interface{}) | ||
request["Namespace"] = parts[0] | ||
request["GroupId"] = parts[1] | ||
request["RegionId"] = client.RegionId | ||
|
||
if v, ok := d.GetOkExists("delete_jobs"); ok { | ||
request["DeleteJobs"] = v | ||
} | ||
runtime := util.RuntimeOptions{} | ||
runtime.SetAutoretry(true) | ||
wait := incrementalWait(3*time.Second, 5*time.Second) | ||
err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { | ||
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-04-30"), StringPointer("AK"), query, request, &runtime) | ||
|
||
if err != nil { | ||
if NeedRetry(err) { | ||
wait() | ||
return resource.RetryableError(err) | ||
} | ||
return resource.NonRetryableError(err) | ||
} | ||
return nil | ||
}) | ||
addDebug(action, response, request) | ||
|
||
if err != nil { | ||
if NotFoundError(err) { | ||
return nil | ||
} | ||
return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.