in alicloud/resource_alicloud_sae_application.go [2153:3254]
func resourceAliCloudSaeApplicationUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*connectivity.AliyunClient)
saeService := SaeService{client}
var response map[string]interface{}
var err error
d.Partial(true)
if d.HasChange("tags") {
if err := saeService.SetResourceTags(d, "application"); err != nil {
return WrapError(err)
}
d.SetPartial("tags")
}
update := false
deployApplicationReq := map[string]*string{
"AppId": StringPointer(d.Id()),
}
if !d.IsNewResource() && d.HasChange("replicas") {
update = true
}
deployApplicationReq["Replicas"] = StringPointer(strconv.Itoa(d.Get("replicas").(int)))
if !d.IsNewResource() && d.HasChange("vswitch_id") {
update = true
}
if v, ok := d.GetOk("vswitch_id"); ok {
deployApplicationReq["VSwitchId"] = StringPointer(v.(string))
}
if d.HasChange("package_version") {
update = true
}
if v, ok := d.GetOk("package_version"); ok {
deployApplicationReq["PackageVersion"] = StringPointer(v.(string))
}
if !d.IsNewResource() && d.HasChange("package_url") {
update = true
}
if v, ok := d.GetOk("package_url"); ok {
deployApplicationReq["PackageUrl"] = StringPointer(v.(string))
}
if !d.IsNewResource() && d.HasChange("image_url") {
update = true
}
if v, ok := d.GetOk("image_url"); ok {
deployApplicationReq["ImageUrl"] = StringPointer(v.(string))
}
if !d.IsNewResource() && d.HasChange("cpu") {
update = true
}
if v, ok := d.GetOk("cpu"); ok {
deployApplicationReq["Cpu"] = StringPointer(strconv.Itoa(v.(int)))
}
if !d.IsNewResource() && d.HasChange("memory") {
update = true
}
if v, ok := d.GetOk("memory"); ok {
deployApplicationReq["Memory"] = StringPointer(strconv.Itoa(v.(int)))
}
if !d.IsNewResource() && d.HasChange("command") {
update = true
}
if v, ok := d.GetOk("command"); ok {
deployApplicationReq["Command"] = StringPointer(v.(string))
}
if !d.IsNewResource() && d.HasChange("web_container") {
update = true
}
if v, ok := d.GetOk("web_container"); ok {
deployApplicationReq["WebContainer"] = StringPointer(v.(string))
}
if !d.IsNewResource() && d.HasChange("jdk") {
update = true
}
if v, ok := d.GetOk("jdk"); ok {
deployApplicationReq["Jdk"] = StringPointer(v.(string))
}
if !d.IsNewResource() && d.HasChange("jar_start_options") {
update = true
}
if v, ok := d.GetOk("jar_start_options"); ok {
deployApplicationReq["JarStartOptions"] = StringPointer(v.(string))
}
if !d.IsNewResource() && d.HasChange("jar_start_args") {
update = true
}
if v, ok := d.GetOk("jar_start_args"); ok {
deployApplicationReq["JarStartArgs"] = StringPointer(v.(string))
}
if d.HasChange("auto_enable_application_scaling_rule") {
update = true
}
if v, ok := d.GetOk("auto_enable_application_scaling_rule"); ok {
deployApplicationReq["AutoEnableApplicationScalingRule"] = StringPointer(strconv.FormatBool(v.(bool)))
}
if d.HasChange("batch_wait_time") {
update = true
}
if v, ok := d.GetOk("batch_wait_time"); ok {
deployApplicationReq["BatchWaitTime"] = StringPointer(strconv.Itoa(v.(int)))
}
if d.HasChange("change_order_desc") {
update = true
}
if v, ok := d.GetOk("change_order_desc"); ok {
deployApplicationReq["ChangeOrderDesc"] = StringPointer(v.(string))
}
if !d.IsNewResource() && d.HasChange("edas_container_version") {
update = true
}
if v, ok := d.GetOk("edas_container_version"); ok {
deployApplicationReq["EdasContainerVersion"] = StringPointer(v.(string))
}
if d.HasChange("enable_ahas") {
update = true
if v, ok := d.GetOk("enable_ahas"); ok {
deployApplicationReq["EnableAhas"] = StringPointer(v.(string))
}
}
if d.HasChange("enable_grey_tag_route") {
update = true
}
if v, ok := d.GetOkExists("enable_grey_tag_route"); ok {
deployApplicationReq["EnableGreyTagRoute"] = StringPointer(strconv.FormatBool(v.(bool)))
}
if d.HasChange("min_ready_instances") {
update = true
}
if v, ok := d.GetOk("min_ready_instances"); ok {
deployApplicationReq["MinReadyInstances"] = StringPointer(strconv.Itoa(v.(int)))
}
if d.HasChange("min_ready_instance_ratio") {
update = true
}
if v, ok := d.GetOk("min_ready_instance_ratio"); ok {
deployApplicationReq["MinReadyInstanceRatio"] = StringPointer(strconv.Itoa(v.(int)))
}
if !d.IsNewResource() && d.HasChange("oss_ak_id") {
update = true
}
if v, ok := d.GetOk("oss_ak_id"); ok {
deployApplicationReq["OssAkId"] = StringPointer(v.(string))
}
if !d.IsNewResource() && d.HasChange("oss_ak_secret") {
update = true
}
if v, ok := d.GetOk("oss_ak_secret"); ok {
deployApplicationReq["OssAkSecret"] = StringPointer(v.(string))
}
if !d.IsNewResource() && d.HasChange("php_arms_config_location") {
update = true
}
if v, ok := d.GetOk("php_arms_config_location"); ok {
deployApplicationReq["PhpArmsConfigLocation"] = StringPointer(v.(string))
}
if !d.IsNewResource() && d.HasChange("php_config") {
update = true
}
if v, ok := d.GetOk("php_config"); ok {
deployApplicationReq["PhpConfig"] = StringPointer(v.(string))
}
if !d.IsNewResource() && d.HasChange("php_config_location") {
update = true
}
if v, ok := d.GetOk("php_config_location"); ok {
deployApplicationReq["PhpConfigLocation"] = StringPointer(v.(string))
}
if !d.IsNewResource() && d.HasChange("security_group_id") {
update = true
}
if v, ok := d.GetOk("security_group_id"); ok {
deployApplicationReq["SecurityGroupId"] = StringPointer(v.(string))
}
if !d.IsNewResource() && d.HasChange("termination_grace_period_seconds") {
update = true
}
if v, ok := d.GetOk("termination_grace_period_seconds"); ok {
deployApplicationReq["TerminationGracePeriodSeconds"] = StringPointer(strconv.Itoa(v.(int)))
}
if !d.IsNewResource() && d.HasChange("timezone") {
update = true
}
if v, ok := d.GetOk("timezone"); ok {
deployApplicationReq["Timezone"] = StringPointer(v.(string))
}
if !d.IsNewResource() && d.HasChange("war_start_options") {
update = true
}
if v, ok := d.GetOk("war_start_options"); ok {
deployApplicationReq["WarStartOptions"] = StringPointer(v.(string))
}
if !d.IsNewResource() && d.HasChange("acr_instance_id") {
update = true
}
if v, ok := d.GetOk("acr_instance_id"); ok {
deployApplicationReq["AcrInstanceId"] = StringPointer(v.(string))
}
if !d.IsNewResource() && d.HasChange("acr_assume_role_arn") {
update = true
}
if v, ok := d.GetOk("acr_assume_role_arn"); ok {
deployApplicationReq["AcrAssumeRoleArn"] = StringPointer(v.(string))
}
if !d.IsNewResource() && d.HasChange("micro_registration") {
update = true
}
if v, ok := d.GetOk("micro_registration"); ok {
deployApplicationReq["MicroRegistration"] = StringPointer(v.(string))
}
if !d.IsNewResource() && d.HasChange("envs") {
update = true
}
if v, ok := d.GetOk("envs"); ok {
deployApplicationReq["Envs"] = StringPointer(v.(string))
}
if !d.IsNewResource() && d.HasChange("sls_configs") {
update = true
}
if v, ok := d.GetOk("sls_configs"); ok {
deployApplicationReq["SlsConfigs"] = StringPointer(v.(string))
}
if !d.IsNewResource() && d.HasChange("php") {
update = true
}
if v, ok := d.GetOk("php"); ok {
deployApplicationReq["Php"] = StringPointer(v.(string))
}
if !d.IsNewResource() && d.HasChange("image_pull_secrets") {
update = true
}
if v, ok := d.GetOk("image_pull_secrets"); ok {
deployApplicationReq["ImagePullSecrets"] = StringPointer(v.(string))
}
if !d.IsNewResource() && d.HasChange("command_args_v2") {
update = true
if v, ok := d.GetOk("command_args_v2"); ok {
deployApplicationReq["CommandArgs"] = StringPointer(convertListToJsonString(v.([]interface{})))
}
}
if !d.IsNewResource() && d.HasChange("custom_host_alias_v2") {
update = true
if v, ok := d.GetOk("custom_host_alias_v2"); ok {
customHostAliasMaps := make([]map[string]interface{}, 0)
for _, customHostAlias := range v.([]interface{}) {
customHostAliasMap := map[string]interface{}{}
customHostAliasArg := customHostAlias.(map[string]interface{})
if hostName, ok := customHostAliasArg["host_name"]; ok && hostName.(string) != "" {
customHostAliasMap["hostName"] = hostName
}
if ip, ok := customHostAliasArg["ip"]; ok && ip.(string) != "" {
customHostAliasMap["ip"] = ip
}
customHostAliasMaps = append(customHostAliasMaps, customHostAliasMap)
}
customHostAliasJson, err := convertListMapToJsonString(customHostAliasMaps)
if err != nil {
return WrapError(err)
}
deployApplicationReq["CustomHostAlias"] = StringPointer(customHostAliasJson)
}
}
if !d.IsNewResource() && d.HasChange("oss_mount_descs_v2") {
update = true
if v, ok := d.GetOk("oss_mount_descs_v2"); ok {
ossMountDescsMaps := make([]map[string]interface{}, 0)
for _, ossMountDescs := range v.([]interface{}) {
ossMountDescsMap := map[string]interface{}{}
ossMountDescsArg := ossMountDescs.(map[string]interface{})
if bucketName, ok := ossMountDescsArg["bucket_name"]; ok && bucketName.(string) != "" {
ossMountDescsMap["bucketName"] = bucketName
}
if bucketPath, ok := ossMountDescsArg["bucket_path"]; ok && bucketPath.(string) != "" {
ossMountDescsMap["bucketPath"] = bucketPath
}
if mountPath, ok := ossMountDescsArg["mount_path"]; ok && mountPath.(string) != "" {
ossMountDescsMap["mountPath"] = mountPath
}
if readOnly, ok := ossMountDescsArg["read_only"]; ok {
ossMountDescsMap["readOnly"] = readOnly
}
ossMountDescsMaps = append(ossMountDescsMaps, ossMountDescsMap)
}
ossMountDescsJson, err := convertListMapToJsonString(ossMountDescsMaps)
if err != nil {
return WrapError(err)
}
deployApplicationReq["OssMountDescs"] = StringPointer(ossMountDescsJson)
}
}
if !d.IsNewResource() && d.HasChange("config_map_mount_desc_v2") {
update = true
if v, ok := d.GetOk("config_map_mount_desc_v2"); ok {
configMapMountDescMaps := make([]map[string]interface{}, 0)
for _, configMapMountDesc := range v.([]interface{}) {
configMapMountDescMap := map[string]interface{}{}
configMapMountDescArg := configMapMountDesc.(map[string]interface{})
if configMapId, ok := configMapMountDescArg["config_map_id"]; ok && configMapId.(string) != "" {
configMapMountDescMap["configMapId"] = configMapId
}
if mountPath, ok := configMapMountDescArg["mount_path"]; ok && mountPath.(string) != "" {
configMapMountDescMap["mountPath"] = mountPath
}
if key, ok := configMapMountDescArg["key"]; ok && key.(string) != "" {
configMapMountDescMap["key"] = key
}
configMapMountDescMaps = append(configMapMountDescMaps, configMapMountDescMap)
}
configMapMountDescJson, err := convertListMapToJsonString(configMapMountDescMaps)
if err != nil {
return WrapError(err)
}
deployApplicationReq["ConfigMapMountDesc"] = StringPointer(configMapMountDescJson)
}
}
if !d.IsNewResource() && d.HasChange("liveness_v2") {
update = true
if v, ok := d.GetOk("liveness_v2"); ok {
livenessMap := map[string]interface{}{}
for _, livenessList := range v.([]interface{}) {
livenessArg := livenessList.(map[string]interface{})
if initialDelaySeconds, ok := livenessArg["initial_delay_seconds"]; ok {
livenessMap["initialDelaySeconds"] = initialDelaySeconds
}
if periodSeconds, ok := livenessArg["period_seconds"]; ok {
livenessMap["periodSeconds"] = periodSeconds
}
if timeoutSeconds, ok := livenessArg["timeout_seconds"]; ok {
livenessMap["timeoutSeconds"] = timeoutSeconds
}
if exec, ok := livenessArg["exec"]; ok && len(exec.([]interface{})) > 0 {
execMap := map[string]interface{}{}
for _, execList := range exec.([]interface{}) {
execArg := execList.(map[string]interface{})
if command, ok := execArg["command"]; ok {
execMap["command"] = command
}
}
livenessMap["exec"] = execMap
}
if tcpSocket, ok := livenessArg["tcp_socket"]; ok && len(tcpSocket.([]interface{})) > 0 {
tcpSocketMap := map[string]interface{}{}
for _, tcpSocketList := range tcpSocket.([]interface{}) {
tcpSocketArg := tcpSocketList.(map[string]interface{})
if port, ok := tcpSocketArg["port"]; ok {
tcpSocketMap["port"] = port
}
}
livenessMap["tcpSocket"] = tcpSocketMap
}
if httpGet, ok := livenessArg["http_get"]; ok && len(httpGet.([]interface{})) > 0 {
httpGetMap := map[string]interface{}{}
for _, httpGetList := range httpGet.([]interface{}) {
httpGetArg := httpGetList.(map[string]interface{})
if path, ok := httpGetArg["path"]; ok && path.(string) != "" {
httpGetMap["path"] = path
}
if port, ok := httpGetArg["port"]; ok {
httpGetMap["port"] = port
}
if scheme, ok := httpGetArg["scheme"]; ok && scheme.(string) != "" {
httpGetMap["scheme"] = scheme
}
if keyWord, ok := httpGetArg["key_word"]; ok && keyWord.(string) != "" {
httpGetMap["keyWord"] = keyWord
if isContainKeyWord, ok := d.GetOkExists("liveness_v2.0.http_get.0.is_contain_key_word"); ok {
httpGetMap["isContainKeyWord"] = isContainKeyWord
}
}
}
livenessMap["httpGet"] = httpGetMap
}
}
livenessJson, err := convertMaptoJsonString(livenessMap)
if err != nil {
return WrapError(err)
}
deployApplicationReq["Liveness"] = StringPointer(livenessJson)
}
}
if !d.IsNewResource() && d.HasChange("readiness_v2") {
update = true
if v, ok := d.GetOk("readiness_v2"); ok {
readinessMap := map[string]interface{}{}
for _, readinessList := range v.([]interface{}) {
readinessArg := readinessList.(map[string]interface{})
if initialDelaySeconds, ok := readinessArg["initial_delay_seconds"]; ok {
readinessMap["initialDelaySeconds"] = initialDelaySeconds
}
if periodSeconds, ok := readinessArg["period_seconds"]; ok {
readinessMap["periodSeconds"] = periodSeconds
}
if timeoutSeconds, ok := readinessArg["timeout_seconds"]; ok {
readinessMap["timeoutSeconds"] = timeoutSeconds
}
if exec, ok := readinessArg["exec"]; ok && len(exec.([]interface{})) > 0 {
execMap := map[string]interface{}{}
for _, execList := range exec.([]interface{}) {
execArg := execList.(map[string]interface{})
if command, ok := execArg["command"]; ok {
execMap["command"] = command
}
}
readinessMap["exec"] = execMap
}
if tcpSocket, ok := readinessArg["tcp_socket"]; ok && len(tcpSocket.([]interface{})) > 0 {
tcpSocketMap := map[string]interface{}{}
for _, tcpSocketList := range tcpSocket.([]interface{}) {
tcpSocketArg := tcpSocketList.(map[string]interface{})
if port, ok := tcpSocketArg["port"]; ok {
tcpSocketMap["port"] = port
}
}
readinessMap["tcpSocket"] = tcpSocketMap
}
if httpGet, ok := readinessArg["http_get"]; ok && len(httpGet.([]interface{})) > 0 {
httpGetMap := map[string]interface{}{}
for _, httpGetList := range httpGet.([]interface{}) {
httpGetArg := httpGetList.(map[string]interface{})
if path, ok := httpGetArg["path"]; ok && path.(string) != "" {
httpGetMap["path"] = path
}
if port, ok := httpGetArg["port"]; ok {
httpGetMap["port"] = port
}
if scheme, ok := httpGetArg["scheme"]; ok && scheme.(string) != "" {
httpGetMap["scheme"] = scheme
}
if keyWord, ok := httpGetArg["key_word"]; ok && keyWord.(string) != "" {
httpGetMap["keyWord"] = keyWord
if isContainKeyWord, ok := d.GetOkExists("readiness_v2.0.http_get.0.is_contain_key_word"); ok {
httpGetMap["isContainKeyWord"] = isContainKeyWord
}
}
}
readinessMap["httpGet"] = httpGetMap
}
}
readinessJson, err := convertMaptoJsonString(readinessMap)
if err != nil {
return WrapError(err)
}
deployApplicationReq["Readiness"] = StringPointer(readinessJson)
}
}
if !d.IsNewResource() && d.HasChange("post_start_v2") {
update = true
if v, ok := d.GetOk("post_start_v2"); ok {
postStartMap := map[string]interface{}{}
for _, postStartList := range v.([]interface{}) {
postStartArg := postStartList.(map[string]interface{})
if exec, ok := postStartArg["exec"]; ok && len(exec.([]interface{})) > 0 {
execMap := map[string]interface{}{}
for _, execList := range exec.([]interface{}) {
execArg := execList.(map[string]interface{})
if command, ok := execArg["command"]; ok {
execMap["command"] = command
}
}
postStartMap["exec"] = execMap
}
}
postStartJson, err := convertMaptoJsonString(postStartMap)
if err != nil {
return WrapError(err)
}
deployApplicationReq["PostStart"] = StringPointer(postStartJson)
}
}
if !d.IsNewResource() && d.HasChange("pre_stop_v2") {
update = true
if v, ok := d.GetOk("pre_stop_v2"); ok {
preStopMap := map[string]interface{}{}
for _, preStopList := range v.([]interface{}) {
preStopArg := preStopList.(map[string]interface{})
if exec, ok := preStopArg["exec"]; ok && len(exec.([]interface{})) > 0 {
execMap := map[string]interface{}{}
for _, execList := range exec.([]interface{}) {
execArg := execList.(map[string]interface{})
if command, ok := execArg["command"]; ok {
execMap["command"] = command
}
}
preStopMap["exec"] = execMap
}
}
preStopJson, err := convertMaptoJsonString(preStopMap)
if err != nil {
return WrapError(err)
}
deployApplicationReq["PreStop"] = StringPointer(preStopJson)
}
}
if !d.IsNewResource() && d.HasChange("tomcat_config_v2") {
update = true
if v, ok := d.GetOk("tomcat_config_v2"); ok {
tomcatConfigMap := map[string]interface{}{}
for _, tomcatConfigList := range v.([]interface{}) {
tomcatConfigArg := tomcatConfigList.(map[string]interface{})
if port, ok := tomcatConfigArg["port"]; ok {
tomcatConfigMap["port"] = port
}
if maxThreads, ok := tomcatConfigArg["max_threads"]; ok {
tomcatConfigMap["maxThreads"] = maxThreads
}
if contextPath, ok := tomcatConfigArg["context_path"]; ok && contextPath.(string) != "" {
tomcatConfigMap["contextPath"] = contextPath
}
if uriEncoding, ok := tomcatConfigArg["uri_encoding"]; ok && uriEncoding.(string) != "" {
tomcatConfigMap["uriEncoding"] = uriEncoding
}
if useBodyEncodingForUri, ok := tomcatConfigArg["use_body_encoding_for_uri"]; ok && useBodyEncodingForUri.(string) != "" {
tomcatConfigMap["useBodyEncodingForUri"] = useBodyEncodingForUri
}
}
tomcatConfigJson, err := convertMaptoJsonString(tomcatConfigMap)
if err != nil {
return WrapError(err)
}
deployApplicationReq["TomcatConfig"] = StringPointer(tomcatConfigJson)
}
}
if d.HasChange("update_strategy_v2") {
update = true
if v, ok := d.GetOk("update_strategy_v2"); ok {
updateStrategyMap := map[string]interface{}{}
for _, updateStrategyList := range v.([]interface{}) {
updateStrategyArg := updateStrategyList.(map[string]interface{})
if updateStrategyType, ok := updateStrategyArg["type"]; ok && updateStrategyType.(string) != "" {
updateStrategyMap["type"] = updateStrategyType
}
if batchUpdate, ok := updateStrategyArg["batch_update"]; ok && len(batchUpdate.([]interface{})) > 0 {
batchUpdateMap := map[string]interface{}{}
for _, batchUpdateList := range batchUpdate.([]interface{}) {
batchUpdateArg := batchUpdateList.(map[string]interface{})
if releaseType, ok := batchUpdateArg["release_type"]; ok && releaseType.(string) != "" {
batchUpdateMap["releaseType"] = releaseType
}
if batch, ok := batchUpdateArg["batch"]; ok {
batchUpdateMap["batch"] = batch
}
if batchWaitTime, ok := batchUpdateArg["batch_wait_time"]; ok {
batchUpdateMap["batchWaitTime"] = batchWaitTime
}
}
updateStrategyMap["batchUpdate"] = batchUpdateMap
}
}
updateStrategyJson, err := convertMaptoJsonString(updateStrategyMap)
if err != nil {
return WrapError(err)
}
deployApplicationReq["UpdateStrategy"] = StringPointer(updateStrategyJson)
}
}
if !d.IsNewResource() && d.HasChange("nas_configs") {
update = true
}
if v, ok := d.GetOk("nas_configs"); ok {
nasConfigsMaps := make([]map[string]interface{}, 0)
for _, nasConfigs := range v.([]interface{}) {
nasConfigsMap := map[string]interface{}{}
nasConfigsArg := nasConfigs.(map[string]interface{})
if nasId, ok := nasConfigsArg["nas_id"]; ok && nasId.(string) != "" {
nasConfigsMap["nasId"] = nasId
}
if nasPath, ok := nasConfigsArg["nas_path"]; ok && nasPath.(string) != "" {
nasConfigsMap["nasPath"] = nasPath
}
if mountPath, ok := nasConfigsArg["mount_path"]; ok && mountPath.(string) != "" {
nasConfigsMap["mountPath"] = mountPath
}
if mountDomain, ok := nasConfigsArg["mount_domain"]; ok && mountDomain.(string) != "" {
nasConfigsMap["mountDomain"] = mountDomain
}
if readOnly, ok := nasConfigsArg["read_only"]; ok {
nasConfigsMap["readOnly"] = readOnly
}
nasConfigsMaps = append(nasConfigsMaps, nasConfigsMap)
}
nasConfigsJson, err := convertListMapToJsonString(nasConfigsMaps)
if err != nil {
return WrapError(err)
}
deployApplicationReq["NasConfigs"] = StringPointer(nasConfigsJson)
}
if !d.IsNewResource() && d.HasChange("kafka_configs") {
update = true
}
if v, ok := d.GetOk("kafka_configs"); ok {
kafkaConfigsMap := map[string]interface{}{}
for _, kafkaConfigsList := range v.([]interface{}) {
kafkaConfigsArg := kafkaConfigsList.(map[string]interface{})
if kafkaInstanceId, ok := kafkaConfigsArg["kafka_instance_id"]; ok && kafkaInstanceId.(string) != "" {
kafkaConfigsMap["kafkaInstanceId"] = kafkaInstanceId
}
if kafkaEndpoint, ok := kafkaConfigsArg["kafka_endpoint"]; ok && kafkaEndpoint.(string) != "" {
kafkaConfigsMap["kafkaEndpoint"] = kafkaEndpoint
}
if kafkaConfigsValue, ok := kafkaConfigsArg["kafka_configs"]; ok && len(kafkaConfigsValue.([]interface{})) > 0 {
kafkaConfigsValueMaps := make([]map[string]interface{}, 0)
for _, kafkaConfigsValueList := range kafkaConfigsValue.([]interface{}) {
kafkaConfigsValueMap := map[string]interface{}{}
kafkaConfigsValueArg := kafkaConfigsValueList.(map[string]interface{})
if logType, ok := kafkaConfigsValueArg["log_type"]; ok && logType.(string) != "" {
kafkaConfigsValueMap["logType"] = logType
}
if logDir, ok := kafkaConfigsValueArg["log_dir"]; ok && logDir.(string) != "" {
kafkaConfigsValueMap["logDir"] = logDir
}
if kafkaTopic, ok := kafkaConfigsValueArg["kafka_topic"]; ok && kafkaTopic.(string) != "" {
kafkaConfigsValueMap["kafkaTopic"] = kafkaTopic
}
kafkaConfigsValueMaps = append(kafkaConfigsValueMaps, kafkaConfigsValueMap)
}
kafkaConfigsMap["kafkaConfigs"] = kafkaConfigsValueMaps
}
}
kafkaConfigsJson, err := convertMaptoJsonString(kafkaConfigsMap)
if err != nil {
return WrapError(err)
}
deployApplicationReq["KafkaConfigs"] = StringPointer(kafkaConfigsJson)
}
if !d.IsNewResource() && d.HasChange("pvtz_discovery_svc") {
update = true
}
if v, ok := d.GetOk("pvtz_discovery_svc"); ok {
pvtzDiscoverySvcMap := map[string]interface{}{}
for _, pvtzDiscoverySvcList := range v.([]interface{}) {
pvtzDiscoverySvcArg := pvtzDiscoverySvcList.(map[string]interface{})
if serviceName, ok := pvtzDiscoverySvcArg["service_name"]; ok && serviceName.(string) != "" {
pvtzDiscoverySvcMap["serviceName"] = serviceName
}
if namespaceId, ok := pvtzDiscoverySvcArg["namespace_id"]; ok && namespaceId.(string) != "" {
pvtzDiscoverySvcMap["namespaceId"] = namespaceId
}
if enable, ok := pvtzDiscoverySvcArg["enable"]; ok {
pvtzDiscoverySvcMap["enable"] = enable
}
if portProtocols, ok := pvtzDiscoverySvcArg["port_protocols"]; ok && len(portProtocols.([]interface{})) > 0 {
portProtocolsMaps := make([]map[string]interface{}, 0)
for _, portProtocolsList := range portProtocols.([]interface{}) {
portProtocolsMap := map[string]interface{}{}
portProtocolsArg := portProtocolsList.(map[string]interface{})
if port, ok := portProtocolsArg["port"]; ok {
portProtocolsMap["port"] = port
}
if protocol, ok := portProtocolsArg["protocol"]; ok && protocol.(string) != "" {
portProtocolsMap["protocol"] = protocol
}
portProtocolsMaps = append(portProtocolsMaps, portProtocolsMap)
}
pvtzDiscoverySvcMap["portProtocols"] = portProtocolsMaps
}
}
pvtzDiscoverySvcJson, err := convertMaptoJsonString(pvtzDiscoverySvcMap)
if err != nil {
return WrapError(err)
}
deployApplicationReq["PvtzDiscoverySvc"] = StringPointer(pvtzDiscoverySvcJson)
}
if !d.IsNewResource() && d.HasChange("command_args") {
update = true
if v, ok := d.GetOk("command_args"); ok {
deployApplicationReq["CommandArgs"] = StringPointer(v.(string))
}
}
if !d.IsNewResource() && d.HasChange("custom_host_alias") {
update = true
if v, ok := d.GetOk("custom_host_alias"); ok {
deployApplicationReq["CustomHostAlias"] = StringPointer(v.(string))
}
}
if !d.IsNewResource() && d.HasChange("oss_mount_descs") {
update = true
if v, ok := d.GetOk("oss_mount_descs"); ok {
deployApplicationReq["OssMountDescs"] = StringPointer(v.(string))
}
}
if !d.IsNewResource() && d.HasChange("config_map_mount_desc") {
update = true
if v, ok := d.GetOk("config_map_mount_desc"); ok {
deployApplicationReq["ConfigMapMountDesc"] = StringPointer(v.(string))
}
}
if !d.IsNewResource() && d.HasChange("liveness") {
update = true
if v, ok := d.GetOk("liveness"); ok {
deployApplicationReq["Liveness"] = StringPointer(v.(string))
}
}
if !d.IsNewResource() && d.HasChange("readiness") {
update = true
if v, ok := d.GetOk("readiness"); ok {
deployApplicationReq["Readiness"] = StringPointer(v.(string))
}
}
if !d.IsNewResource() && d.HasChange("post_start") {
update = true
if v, ok := d.GetOk("post_start"); ok {
deployApplicationReq["PostStart"] = StringPointer(v.(string))
}
}
if !d.IsNewResource() && d.HasChange("pre_stop") {
update = true
if v, ok := d.GetOk("pre_stop"); ok {
deployApplicationReq["PreStop"] = StringPointer(v.(string))
}
}
if !d.IsNewResource() && d.HasChange("tomcat_config") {
update = true
if v, ok := d.GetOk("tomcat_config"); ok {
deployApplicationReq["TomcatConfig"] = StringPointer(v.(string))
}
}
if d.HasChange("update_strategy") {
update = true
if v, ok := d.GetOk("update_strategy"); ok {
deployApplicationReq["UpdateStrategy"] = StringPointer(v.(string))
}
}
if update {
action := "/pop/v1/sam/app/deployApplication"
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutUpdate)), func() *resource.RetryError {
response, err = client.RoaPost("sae", "2019-05-06", action, deployApplicationReq, nil, nil, false)
if err != nil {
if IsExpectedErrors(err, []string{"Application.InvalidStatus", "Application.ChangerOrderRunning"}) || NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
addDebug(action, response, deployApplicationReq)
if err != nil {
return WrapErrorf(err, DefaultErrorMsg, d.Id(), "POST "+action, AlibabaCloudSdkGoERROR)
}
responseData := response["Data"].(map[string]interface{})
stateConf := BuildStateConf([]string{}, []string{"2", "8", "11", "12"}, d.Timeout(schema.TimeoutUpdate), 3*time.Second, saeService.SaeApplicationChangeOrderStateRefreshFunc(fmt.Sprint(responseData["ChangeOrderId"]), []string{}))
if _, err := stateConf.WaitForState(); err != nil {
return WrapErrorf(err, IdMsg, d.Id())
}
d.SetPartial("replicas")
d.SetPartial("vswitch_id")
d.SetPartial("package_version")
d.SetPartial("package_url")
d.SetPartial("image_url")
d.SetPartial("cpu")
d.SetPartial("memory")
d.SetPartial("command")
d.SetPartial("web_container")
d.SetPartial("jdk")
d.SetPartial("jar_start_options")
d.SetPartial("jar_start_args")
d.SetPartial("auto_enable_application_scaling_rule")
d.SetPartial("batch_wait_time")
d.SetPartial("change_order_desc")
d.SetPartial("edas_container_version")
d.SetPartial("enable_ahas")
d.SetPartial("enable_grey_tag_route")
d.SetPartial("min_ready_instances")
d.SetPartial("min_ready_instance_ratio")
d.SetPartial("oss_ak_id")
d.SetPartial("oss_ak_secret")
d.SetPartial("php_arms_config_location")
d.SetPartial("php_config")
d.SetPartial("php_config_location")
d.SetPartial("security_group_id")
d.SetPartial("termination_grace_period_seconds")
d.SetPartial("timezone")
d.SetPartial("war_start_options")
d.SetPartial("acr_instance_id")
d.SetPartial("acr_assume_role_arn")
d.SetPartial("micro_registration")
d.SetPartial("envs")
d.SetPartial("sls_configs")
d.SetPartial("php")
d.SetPartial("image_pull_secrets")
d.SetPartial("command_args_v2")
d.SetPartial("custom_host_alias_v2")
d.SetPartial("oss_mount_descs_v2")
d.SetPartial("config_map_mount_desc_v2")
d.SetPartial("liveness_v2")
d.SetPartial("readiness_v2")
d.SetPartial("post_start_v2")
d.SetPartial("pre_stop_v2")
d.SetPartial("tomcat_config_v2")
d.SetPartial("update_strategy_v2")
d.SetPartial("nas_configs")
d.SetPartial("kafka_configs")
d.SetPartial("pvtz_discovery_svc")
d.SetPartial("command_args")
d.SetPartial("custom_host_alias")
d.SetPartial("oss_mount_descs")
d.SetPartial("config_map_mount_desc")
d.SetPartial("liveness")
d.SetPartial("readiness")
d.SetPartial("post_start")
d.SetPartial("pre_stop")
d.SetPartial("tomcat_config")
d.SetPartial("update_strategy")
}
update = false
updateApplicationDescriptionReq := map[string]*string{
"AppId": StringPointer(d.Id()),
}
if !d.IsNewResource() && d.HasChange("app_description") {
update = true
}
if v, ok := d.GetOk("app_description"); ok {
updateApplicationDescriptionReq["AppDescription"] = StringPointer(v.(string))
}
if update {
action := "/pop/v1/sam/app/updateAppDescription"
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutUpdate)), func() *resource.RetryError {
response, err = client.RoaPut("sae", "2019-05-06", action, updateApplicationDescriptionReq, nil, nil, false)
if err != nil {
if IsExpectedErrors(err, []string{"Application.InvalidStatus", "Application.ChangerOrderRunning"}) || NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
addDebug(action, response, updateApplicationDescriptionReq)
if err != nil {
return WrapErrorf(err, DefaultErrorMsg, d.Id(), "POST "+action, AlibabaCloudSdkGoERROR)
}
d.SetPartial("app_description")
}
// 【Exists】update status
if d.HasChange("status") {
object, err := saeService.DescribeApplicationStatus(d.Id())
if err != nil {
return WrapError(err)
}
target := d.Get("status").(string)
if object["CurrentStatus"].(string) != target {
if target == "RUNNING" {
request := map[string]*string{
"AppId": StringPointer(d.Id()),
}
action := "/pop/v1/sam/app/startApplication"
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutUpdate)), func() *resource.RetryError {
response, err = client.RoaPut("sae", "2019-05-06", action, request, nil, nil, true)
if err != nil {
if IsExpectedErrors(err, []string{"Application.ChangerOrderRunning"}) || 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)
}
}
if target == "STOPPED" {
request := map[string]*string{
"AppId": StringPointer(d.Id()),
}
action := "/pop/v1/sam/app/stopApplication"
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutUpdate)), func() *resource.RetryError {
response, err = client.RoaPut("sae", "2019-05-06", action, request, nil, nil, true)
if err != nil {
if IsExpectedErrors(err, []string{"Application.InvalidStatus"}) || 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(), "PUT "+action, AlibabaCloudSdkGoERROR)
}
}
d.SetPartial("status")
}
}
d.Partial(false)
stateConf := BuildStateConf([]string{}, []string{"SUCCESS"}, d.Timeout(schema.TimeoutUpdate), 5*time.Second, saeService.SaeApplicationStateRefreshFunc(d.Id(), []string{"FAIL", "AUTO_BATCH_WAIT", "APPROVED", "WAIT_APPROVAL", "WAIT_BATCH_CONFIRM", "ABORT", "SYSTEM_FAIL"}))
if _, err := stateConf.WaitForState(); err != nil {
return WrapErrorf(err, IdMsg, d.Id())
}
return resourceAliCloudSaeApplicationRead(d, meta)
}