in alicloud/resource_alicloud_arms_synthetic_task.go [1318:1909]
func resourceAliCloudArmsSyntheticTaskUpdate(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
d.Partial(true)
action := "UpdateTimingSyntheticTask"
var err error
request = make(map[string]interface{})
query = make(map[string]interface{})
query["TaskId"] = d.Id()
request["RegionId"] = client.RegionId
if !d.IsNewResource() && d.HasChange("monitors") {
update = true
}
if v, ok := d.GetOk("monitors"); ok {
monitorsMaps := make([]map[string]interface{}, 0)
for _, dataLoop := range v.([]interface{}) {
dataLoopTmp := dataLoop.(map[string]interface{})
dataLoopMap := make(map[string]interface{})
dataLoopMap["CityCode"] = dataLoopTmp["city_code"]
dataLoopMap["OperatorCode"] = dataLoopTmp["operator_code"]
dataLoopMap["ClientType"] = dataLoopTmp["client_type"]
monitorsMaps = append(monitorsMaps, dataLoopMap)
}
request["Monitors"], _ = convertListMapToJsonString(monitorsMaps)
}
if !d.IsNewResource() && d.HasChange("synthetic_task_name") {
update = true
}
request["Name"] = d.Get("synthetic_task_name")
if !d.IsNewResource() && d.HasChange("frequency") {
update = true
}
request["Frequency"] = d.Get("frequency")
if !d.IsNewResource() && d.HasChange("monitor_conf") {
update = true
}
objectDataLocalMap := make(map[string]interface{})
if v := d.Get("monitor_conf"); !IsNil(v) {
stream_map, _ := jsonpath.Get("$[0].stream[0]", v)
if !IsNil(stream_map) {
stream := make(map[string]interface{})
nodeNative3, _ := jsonpath.Get("$[0].stream[0].target_url", v)
if nodeNative3 != "" {
stream["TargetUrl"] = nodeNative3
}
nodeNative4, _ := jsonpath.Get("$[0].stream[0].white_list", v)
if nodeNative4 != "" {
stream["WhiteList"] = nodeNative4
}
nodeNative5, _ := jsonpath.Get("$[0].stream[0].stream_type", v)
if nodeNative5 != "" {
stream["StreamType"] = nodeNative5
}
nodeNative6, _ := jsonpath.Get("$[0].stream[0].stream_monitor_timeout", v)
if nodeNative6 != "" {
stream["StreamMonitorTimeout"] = nodeNative6
}
nodeNative7, _ := jsonpath.Get("$[0].stream[0].stream_address_type", v)
if nodeNative7 != "" {
stream["StreamAddressType"] = nodeNative7
}
nodeNative8, _ := jsonpath.Get("$[0].stream[0].player_type", v)
if nodeNative8 != "" {
stream["PlayerType"] = nodeNative8
}
nodeNative9, _ := jsonpath.Get("$[0].stream[0].custom_header_content", v)
if nodeNative9 != "" {
stream["CustomHeaderContent"] = nodeNative9
}
objectDataLocalMap["Stream"] = stream
}
netICMP_map, _ := jsonpath.Get("$[0].net_icmp[0]", v)
if !IsNil(netICMP_map) {
netICMP := make(map[string]interface{})
nodeNative10, _ := jsonpath.Get("$[0].net_icmp[0].package_num", v)
if nodeNative10 != "" {
netICMP["PackageNum"] = nodeNative10
}
nodeNative11, _ := jsonpath.Get("$[0].net_icmp[0].package_size", v)
if nodeNative11 != "" {
netICMP["PackageSize"] = nodeNative11
}
nodeNative12, _ := jsonpath.Get("$[0].net_icmp[0].split_package", v)
if nodeNative12 != "" {
netICMP["SplitPackage"] = nodeNative12
}
nodeNative13, _ := jsonpath.Get("$[0].net_icmp[0].interval", v)
if nodeNative13 != "" {
netICMP["Interval"] = nodeNative13
}
nodeNative14, _ := jsonpath.Get("$[0].net_icmp[0].timeout", v)
if nodeNative14 != "" {
netICMP["Timeout"] = nodeNative14
}
nodeNative15, _ := jsonpath.Get("$[0].net_icmp[0].tracert_enable", v)
if nodeNative15 != "" {
netICMP["TracertEnable"] = nodeNative15
}
nodeNative16, _ := jsonpath.Get("$[0].net_icmp[0].tracert_num_max", v)
if nodeNative16 != "" {
netICMP["TracertNumMax"] = nodeNative16
}
nodeNative17, _ := jsonpath.Get("$[0].net_icmp[0].tracert_timeout", v)
if nodeNative17 != "" {
netICMP["TracertTimeout"] = nodeNative17
}
nodeNative18, _ := jsonpath.Get("$[0].net_icmp[0].target_url", v)
if nodeNative18 != "" {
netICMP["TargetUrl"] = nodeNative18
}
objectDataLocalMap["NetICMP"] = netICMP
}
apiHTTP_map, _ := jsonpath.Get("$[0].api_http[0]", v)
if !IsNil(apiHTTP_map) {
apiHTTP := make(map[string]interface{})
nodeNative19, _ := jsonpath.Get("$[0].api_http[0].timeout", v)
if nodeNative19 != "" {
apiHTTP["Timeout"] = nodeNative19
}
nodeNative20, _ := jsonpath.Get("$[0].api_http[0].target_url", v)
if nodeNative20 != "" {
apiHTTP["TargetUrl"] = nodeNative20
}
nodeNative21, _ := jsonpath.Get("$[0].api_http[0].method", v)
if nodeNative21 != "" {
apiHTTP["Method"] = nodeNative21
}
requestBody_map, _ := jsonpath.Get("$[0].api_http[0].request_body[0]", v)
if !IsNil(requestBody_map) {
requestBody := make(map[string]interface{})
nodeNative22, _ := jsonpath.Get("$[0].api_http[0].request_body[0].content", v)
if nodeNative22 != "" {
requestBody["Content"] = nodeNative22
}
nodeNative23, _ := jsonpath.Get("$[0].api_http[0].request_body[0].type", v)
if nodeNative23 != "" {
requestBody["Type"] = nodeNative23
}
apiHTTP["RequestBody"] = requestBody
}
nodeNative24, _ := jsonpath.Get("$[0].api_http[0].connect_timeout", v)
if nodeNative24 != "" {
apiHTTP["ConnectTimeout"] = nodeNative24
}
nodeNative25, _ := jsonpath.Get("$[0].api_http[0].request_headers", v)
if nodeNative25 != "" {
apiHTTP["RequestHeaders"] = nodeNative25
}
objectDataLocalMap["ApiHTTP"] = apiHTTP
}
fileDownload_map, _ := jsonpath.Get("$[0].file_download[0]", v)
if !IsNil(fileDownload_map) {
fileDownload := make(map[string]interface{})
nodeNative26, _ := jsonpath.Get("$[0].file_download[0].target_url", v)
if nodeNative26 != "" {
fileDownload["TargetUrl"] = nodeNative26
}
nodeNative27, _ := jsonpath.Get("$[0].file_download[0].monitor_timeout", v)
if nodeNative27 != "" {
fileDownload["MonitorTimeout"] = nodeNative27
}
nodeNative28, _ := jsonpath.Get("$[0].file_download[0].redirection", v)
if nodeNative28 != "" {
fileDownload["Redirection"] = nodeNative28
}
nodeNative29, _ := jsonpath.Get("$[0].file_download[0].download_kernel", v)
if nodeNative29 != "" {
fileDownload["DownloadKernel"] = nodeNative29
}
nodeNative30, _ := jsonpath.Get("$[0].file_download[0].quick_protocol", v)
if nodeNative30 != "" {
fileDownload["QuickProtocol"] = nodeNative30
}
nodeNative31, _ := jsonpath.Get("$[0].file_download[0].connection_timeout", v)
if nodeNative31 != "" {
fileDownload["ConnectionTimeout"] = nodeNative31
}
nodeNative32, _ := jsonpath.Get("$[0].file_download[0].ignore_certificate_status_error", v)
if nodeNative32 != "" {
fileDownload["IgnoreCertificateStatusError"] = nodeNative32
}
nodeNative33, _ := jsonpath.Get("$[0].file_download[0].ignore_certificate_untrustworthy_error", v)
if nodeNative33 != "" {
fileDownload["IgnoreCertificateUntrustworthyError"] = nodeNative33
}
nodeNative34, _ := jsonpath.Get("$[0].file_download[0].ignore_invalid_host_error", v)
if nodeNative34 != "" {
fileDownload["IgnoreInvalidHostError"] = nodeNative34
}
nodeNative35, _ := jsonpath.Get("$[0].file_download[0].transmission_size", v)
if nodeNative35 != "" {
fileDownload["TransmissionSize"] = nodeNative35
}
nodeNative36, _ := jsonpath.Get("$[0].file_download[0].ignore_certificate_canceled_error", v)
if nodeNative36 != "" {
fileDownload["IgnoreCertificateCanceledError"] = nodeNative36
}
nodeNative37, _ := jsonpath.Get("$[0].file_download[0].ignore_certificate_auth_error", v)
if nodeNative37 != "" {
fileDownload["IgnoreCertificateAuthError"] = nodeNative37
}
nodeNative38, _ := jsonpath.Get("$[0].file_download[0].ignore_certificate_out_of_date_error", v)
if nodeNative38 != "" {
fileDownload["IgnoreCertificateOutOfDateError"] = nodeNative38
}
nodeNative39, _ := jsonpath.Get("$[0].file_download[0].ignore_certificate_using_error", v)
if nodeNative39 != "" {
fileDownload["IgnoreCertificateUsingError"] = nodeNative39
}
nodeNative40, _ := jsonpath.Get("$[0].file_download[0].verify_way", v)
if nodeNative40 != "" {
fileDownload["VerifyWay"] = nodeNative40
}
nodeNative41, _ := jsonpath.Get("$[0].file_download[0].validate_keywords", v)
if nodeNative41 != "" {
fileDownload["ValidateKeywords"] = nodeNative41
}
nodeNative42, _ := jsonpath.Get("$[0].file_download[0].white_list", v)
if nodeNative42 != "" {
fileDownload["WhiteList"] = nodeNative42
}
nodeNative43, _ := jsonpath.Get("$[0].file_download[0].custom_header_content", v)
if nodeNative43 != "" {
fileDownload["CustomHeaderContent"] = nodeNative43
}
objectDataLocalMap["FileDownload"] = fileDownload
}
netTCP_map, _ := jsonpath.Get("$[0].net_tcp[0]", v)
if !IsNil(netTCP_map) {
netTCP := make(map[string]interface{})
nodeNative44, _ := jsonpath.Get("$[0].net_tcp[0].connect_times", v)
if nodeNative44 != "" {
netTCP["ConnectTimes"] = nodeNative44
}
nodeNative45, _ := jsonpath.Get("$[0].net_tcp[0].target_url", v)
if nodeNative45 != "" {
netTCP["TargetUrl"] = nodeNative45
}
nodeNative46, _ := jsonpath.Get("$[0].net_tcp[0].interval", v)
if nodeNative46 != "" {
netTCP["Interval"] = nodeNative46
}
nodeNative47, _ := jsonpath.Get("$[0].net_tcp[0].timeout", v)
if nodeNative47 != "" {
netTCP["Timeout"] = nodeNative47
}
nodeNative48, _ := jsonpath.Get("$[0].net_tcp[0].tracert_enable", v)
if nodeNative48 != "" {
netTCP["TracertEnable"] = nodeNative48
}
nodeNative49, _ := jsonpath.Get("$[0].net_tcp[0].tracert_num_max", v)
if nodeNative49 != "" {
netTCP["TracertNumMax"] = nodeNative49
}
nodeNative50, _ := jsonpath.Get("$[0].net_tcp[0].tracert_timeout", v)
if nodeNative50 != "" {
netTCP["TracertTimeout"] = nodeNative50
}
objectDataLocalMap["NetTCP"] = netTCP
}
netDNS_map, _ := jsonpath.Get("$[0].net_dns[0]", v)
if !IsNil(netDNS_map) {
netDNS := make(map[string]interface{})
nodeNative51, _ := jsonpath.Get("$[0].net_dns[0].timeout", v)
if nodeNative51 != "" {
netDNS["Timeout"] = nodeNative51
}
nodeNative52, _ := jsonpath.Get("$[0].net_dns[0].dns_server_ip_type", v)
if nodeNative52 != "" {
netDNS["DnsServerIpType"] = nodeNative52
}
nodeNative53, _ := jsonpath.Get("$[0].net_dns[0].ns_server", v)
if nodeNative53 != "" {
netDNS["NsServer"] = nodeNative53
}
nodeNative54, _ := jsonpath.Get("$[0].net_dns[0].query_method", v)
if nodeNative54 != "" {
netDNS["QueryMethod"] = nodeNative54
}
nodeNative55, _ := jsonpath.Get("$[0].net_dns[0].target_url", v)
if nodeNative55 != "" {
netDNS["TargetUrl"] = nodeNative55
}
objectDataLocalMap["NetDNS"] = netDNS
}
website_map, _ := jsonpath.Get("$[0].website[0]", v)
if !IsNil(website_map) {
website := make(map[string]interface{})
nodeNative56, _ := jsonpath.Get("$[0].website[0].target_url", v)
if nodeNative56 != "" {
website["TargetUrl"] = nodeNative56
}
nodeNative57, _ := jsonpath.Get("$[0].website[0].automatic_scrolling", v)
if nodeNative57 != "" {
website["AutomaticScrolling"] = nodeNative57
}
nodeNative58, _ := jsonpath.Get("$[0].website[0].custom_header", v)
if nodeNative58 != "" {
website["CustomHeader"] = nodeNative58
}
nodeNative59, _ := jsonpath.Get("$[0].website[0].disable_cache", v)
if nodeNative59 != "" {
website["DisableCache"] = nodeNative59
}
nodeNative60, _ := jsonpath.Get("$[0].website[0].disable_compression", v)
if nodeNative60 != "" {
website["DisableCompression"] = nodeNative60
}
nodeNative61, _ := jsonpath.Get("$[0].website[0].filter_invalid_ip", v)
if nodeNative61 != "" {
website["FilterInvalidIP"] = nodeNative61
}
nodeNative62, _ := jsonpath.Get("$[0].website[0].ignore_certificate_error", v)
if nodeNative62 != "" {
website["IgnoreCertificateError"] = nodeNative62
}
nodeNative63, _ := jsonpath.Get("$[0].website[0].slow_element_threshold", v)
if nodeNative63 != "" {
website["SlowElementThreshold"] = nodeNative63
}
nodeNative64, _ := jsonpath.Get("$[0].website[0].wait_completion_time", v)
if nodeNative64 != "" {
website["WaitCompletionTime"] = nodeNative64
}
nodeNative65, _ := jsonpath.Get("$[0].website[0].verify_string_blacklist", v)
if nodeNative65 != "" {
website["VerifyStringBlacklist"] = nodeNative65
}
nodeNative66, _ := jsonpath.Get("$[0].website[0].verify_string_whitelist", v)
if nodeNative66 != "" {
website["VerifyStringWhitelist"] = nodeNative66
}
nodeNative67, _ := jsonpath.Get("$[0].website[0].element_blacklist", v)
if nodeNative67 != "" {
website["ElementBlacklist"] = nodeNative67
}
nodeNative68, _ := jsonpath.Get("$[0].website[0].dns_hijack_whitelist", v)
if nodeNative68 != "" {
website["DNSHijackWhitelist"] = nodeNative68
}
nodeNative69, _ := jsonpath.Get("$[0].website[0].page_tamper", v)
if nodeNative69 != "" {
website["PageTamper"] = nodeNative69
}
nodeNative70, _ := jsonpath.Get("$[0].website[0].flow_hijack_jump_times", v)
if nodeNative70 != "" {
website["FlowHijackJumpTimes"] = nodeNative70
}
nodeNative71, _ := jsonpath.Get("$[0].website[0].flow_hijack_logo", v)
if nodeNative71 != "" {
website["FlowHijackLogo"] = nodeNative71
}
nodeNative72, _ := jsonpath.Get("$[0].website[0].monitor_timeout", v)
if nodeNative72 != "" {
website["MonitorTimeout"] = nodeNative72
}
nodeNative73, _ := jsonpath.Get("$[0].website[0].redirection", v)
if nodeNative73 != "" {
website["Redirection"] = nodeNative73
}
nodeNative74, _ := jsonpath.Get("$[0].website[0].custom_header_content", v)
if nodeNative74 != "" {
website["CustomHeaderContent"] = nodeNative74
}
objectDataLocalMap["Website"] = website
}
request["MonitorConf"] = convertMapToJsonStringIgnoreError(objectDataLocalMap)
}
if !d.IsNewResource() && d.HasChange("available_assertions") {
update = true
}
if v, ok := d.GetOk("available_assertions"); ok {
availableAssertionsMaps := make([]map[string]interface{}, 0)
for _, dataLoop1 := range v.([]interface{}) {
dataLoop1Tmp := dataLoop1.(map[string]interface{})
dataLoop1Map := make(map[string]interface{})
dataLoop1Map["Type"] = dataLoop1Tmp["type"]
dataLoop1Map["Target"] = dataLoop1Tmp["target"]
dataLoop1Map["Operator"] = dataLoop1Tmp["operator"]
dataLoop1Map["Expect"] = dataLoop1Tmp["expect"]
availableAssertionsMaps = append(availableAssertionsMaps, dataLoop1Map)
}
request["AvailableAssertions"], _ = convertListMapToJsonString(availableAssertionsMaps)
}
if !d.IsNewResource() && d.HasChange("custom_period") {
update = true
}
objectDataLocalMap1 := make(map[string]interface{})
if v := d.Get("custom_period"); !IsNil(v) {
nodeNative79, _ := jsonpath.Get("$[0].end_hour", v)
if nodeNative79 != "" {
objectDataLocalMap1["EndHour"] = nodeNative79
}
nodeNative80, _ := jsonpath.Get("$[0].start_hour", v)
if nodeNative80 != "" {
objectDataLocalMap1["StartHour"] = nodeNative80
}
request["CustomPeriod"] = convertMapToJsonStringIgnoreError(objectDataLocalMap1)
}
if !d.IsNewResource() && d.HasChange("common_setting") {
update = true
}
objectDataLocalMap2 := make(map[string]interface{})
if v := d.Get("common_setting"); !IsNil(v) {
nodeNative81, _ := jsonpath.Get("$[0].ip_type", v)
if nodeNative81 != "" {
objectDataLocalMap2["IpType"] = nodeNative81
}
customHost_map, _ := jsonpath.Get("$[0].custom_host[0]", v)
if !IsNil(customHost_map) {
customHost := make(map[string]interface{})
if v, ok := d.GetOk("common_setting"); ok {
localData2, err := jsonpath.Get("$[0].custom_host[0].hosts", v)
if err != nil {
return WrapError(err)
}
localMaps := make([]map[string]interface{}, 0)
for _, dataLoop2 := range localData2.([]interface{}) {
dataLoop2Tmp := dataLoop2.(map[string]interface{})
dataLoop2Map := make(map[string]interface{})
dataLoop2Map["Domain"] = dataLoop2Tmp["domain"]
dataLoop2Map["Ips"] = dataLoop2Tmp["ips"]
dataLoop2Map["IpType"] = dataLoop2Tmp["ip_type"]
localMaps = append(localMaps, dataLoop2Map)
}
customHost["Hosts"] = localMaps
}
nodeNative86, _ := jsonpath.Get("$[0].custom_host[0].select_type", v)
if nodeNative86 != "" {
customHost["SelectType"] = nodeNative86
}
objectDataLocalMap2["CustomHost"] = customHost
}
nodeNative88, _ := jsonpath.Get("$[0].monitor_samples", v)
if nodeNative88 != "" {
objectDataLocalMap2["MonitorSamples"] = nodeNative88
}
nodeNative89, _ := jsonpath.Get("$[0].is_open_trace", v)
if nodeNative89 != "" {
objectDataLocalMap2["IsOpenTrace"] = nodeNative89
}
nodeNative90, _ := jsonpath.Get("$[0].trace_client_type", v)
if nodeNative90 != "" {
objectDataLocalMap2["TraceClientType"] = nodeNative90
}
nodeNative91, _ := jsonpath.Get("$[0].xtrace_region", v)
if nodeNative91 != "" {
objectDataLocalMap2["XtraceRegion"] = nodeNative91
}
request["CommonSetting"] = convertMapToJsonStringIgnoreError(objectDataLocalMap2)
}
if _, ok := d.GetOk("resource_group_id"); ok && !d.IsNewResource() && d.HasChange("resource_group_id") {
update = true
request["ResourceGroupId"] = d.Get("resource_group_id")
}
if update {
wait := incrementalWait(3*time.Second, 5*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
response, err = client.RpcPost("ARMS", "2019-08-08", action, query, request, true)
if err != nil {
if NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
addDebug(action, response, request)
return nil
})
if err != nil {
return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR)
}
d.SetPartial("synthetic_task_name")
d.SetPartial("frequency")
d.SetPartial("resource_group_id")
}
update = false
action = "ChangeResourceGroup"
request = make(map[string]interface{})
query = make(map[string]interface{})
query["ResourceId"] = d.Id()
request["RegionId"] = client.RegionId
if _, ok := d.GetOk("resource_group_id"); ok && !d.IsNewResource() && d.HasChange("resource_group_id") {
update = true
request["NewResourceGroupId"] = d.Get("resource_group_id")
}
request["ResourceType"] = "SYNTHETICTASK"
if update {
wait := incrementalWait(3*time.Second, 5*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
response, err = client.RpcPost("ARMS", "2019-08-08", action, query, request, true)
if err != nil {
if NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
addDebug(action, response, request)
return nil
})
if err != nil {
return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR)
}
d.SetPartial("resource_group_id")
}
if d.HasChange("status") {
client := meta.(*connectivity.AliyunClient)
armsServiceV2 := ArmsServiceV2{client}
object, err := armsServiceV2.DescribeArmsSyntheticTask(d.Id())
if err != nil {
return WrapError(err)
}
target := d.Get("status").(string)
if object["Status"].(string) != target {
if target == "RUNNING" {
action = "StartTimingSyntheticTask"
request = make(map[string]interface{})
query = make(map[string]interface{})
query["TaskIds"] = "[\"" + d.Id() + "\"]"
request["RegionId"] = client.RegionId
wait := incrementalWait(3*time.Second, 5*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
response, err = client.RpcPost("ARMS", "2019-08-08", action, query, request, true)
if err != nil {
if NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
addDebug(action, response, request)
return nil
})
if err != nil {
return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR)
}
}
if target == "STOP" {
action = "StopTimingSyntheticTask"
request = make(map[string]interface{})
query = make(map[string]interface{})
query["TaskIds"] = "[\"" + d.Id() + "\"]"
request["RegionId"] = client.RegionId
wait := incrementalWait(3*time.Second, 5*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
response, err = client.RpcPost("ARMS", "2019-08-08", action, query, request, true)
if err != nil {
if NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
addDebug(action, response, request)
return nil
})
if err != nil {
return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR)
}
}
}
}
if d.HasChange("tags") {
armsServiceV2 := ArmsServiceV2{client}
if err := armsServiceV2.SetResourceTags(d, "SYNTHETICTASK"); err != nil {
return WrapError(err)
}
d.SetPartial("tags")
}
d.Partial(false)
return resourceAliCloudArmsSyntheticTaskRead(d, meta)
}