in alicloud/resource_alicloud_maxcompute_project.go [455:778]
func resourceAliCloudMaxComputeProjectUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*connectivity.AliyunClient)
var request map[string]interface{}
var response map[string]interface{}
var query map[string]*string
var body map[string]interface{}
update := false
d.Partial(true)
projectName := d.Id()
action := fmt.Sprintf("/api/v1/projects/%s/meta", projectName)
var err error
request = make(map[string]interface{})
query = make(map[string]*string)
body = make(map[string]interface{})
request["projectName"] = d.Id()
if d.HasChange("status") {
update = true
}
if v, ok := d.GetOk("status"); ok || d.HasChange("status") {
request["status"] = v
}
if d.HasChange("properties") {
update = true
}
objectDataLocalMap := make(map[string]interface{})
if v := d.Get("properties"); v != nil {
timezone1, _ := jsonpath.Get("$[0].timezone", v)
if timezone1 != nil && (d.HasChange("properties.0.timezone") || timezone1 != "") {
objectDataLocalMap["timezone"] = timezone1
}
retentionDays1, _ := jsonpath.Get("$[0].retention_days", v)
if retentionDays1 != nil && (d.HasChange("properties.0.retention_days") || retentionDays1 != "") {
objectDataLocalMap["retentionDays"] = retentionDays1
}
allowFullScan1, _ := jsonpath.Get("$[0].allow_full_scan", v)
if allowFullScan1 != nil && (d.HasChange("properties.0.allow_full_scan") || allowFullScan1 != "") {
objectDataLocalMap["allowFullScan"] = allowFullScan1
}
enableDecimal21, _ := jsonpath.Get("$[0].enable_decimal2", v)
if enableDecimal21 != nil && (d.HasChange("properties.0.enable_decimal2") || enableDecimal21 != "") {
objectDataLocalMap["enableDecimal2"] = enableDecimal21
}
tableLifecycle := make(map[string]interface{})
value1, _ := jsonpath.Get("$[0].table_lifecycle[0].value", v)
if value1 != nil && (d.HasChange("properties.0.table_lifecycle.0.value") || value1 != "") {
tableLifecycle["value"] = value1
}
type1, _ := jsonpath.Get("$[0].table_lifecycle[0].type", v)
if type1 != nil && (d.HasChange("properties.0.table_lifecycle.0.type") || type1 != "") {
tableLifecycle["type"] = type1
}
objectDataLocalMap["tableLifecycle"] = tableLifecycle
sqlMeteringMax1, _ := jsonpath.Get("$[0].sql_metering_max", v)
if sqlMeteringMax1 != nil && (d.HasChange("properties.0.sql_metering_max") || sqlMeteringMax1 != "") {
objectDataLocalMap["sqlMeteringMax"] = sqlMeteringMax1
}
typeSystem1, _ := jsonpath.Get("$[0].type_system", v)
if typeSystem1 != nil && (d.HasChange("properties.0.type_system") || typeSystem1 != "") {
objectDataLocalMap["typeSystem"] = typeSystem1
}
encryption := make(map[string]interface{})
enable1, _ := jsonpath.Get("$[0].encryption[0].enable", v)
if enable1 != nil && (d.HasChange("properties.0.encryption.0.enable") || enable1 != "") {
encryption["enable"] = enable1
}
algorithm1, _ := jsonpath.Get("$[0].encryption[0].algorithm", v)
if algorithm1 != nil && (d.HasChange("properties.0.encryption.0.algorithm") || algorithm1 != "") {
encryption["algorithm"] = algorithm1
}
key1, _ := jsonpath.Get("$[0].encryption[0].key", v)
if key1 != nil && (d.HasChange("properties.0.encryption.0.key") || key1 != "") {
encryption["key"] = key1
}
if encryption["enable"] == "true" {
objectDataLocalMap["encryption"] = encryption
}
request["properties"] = objectDataLocalMap
}
body = request
if update {
wait := incrementalWait(3*time.Second, 5*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
response, err = client.RoaPut("MaxCompute", "2022-01-04", action, query, nil, body, true)
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)
}
}
update = false
projectName = d.Id()
action = fmt.Sprintf("/api/v1/projects/%s/quota", projectName)
request = make(map[string]interface{})
query = make(map[string]*string)
body = make(map[string]interface{})
request["projectName"] = d.Id()
if !d.IsNewResource() && d.HasChange("default_quota") {
update = true
}
if v, ok := d.GetOk("default_quota"); ok || d.HasChange("default_quota") {
request["quota"] = v
}
body = request
if update {
wait := incrementalWait(3*time.Second, 5*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
response, err = client.RoaPut("MaxCompute", "2022-01-04", action, query, nil, body, true)
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)
}
}
update = false
projectName = d.Id()
action = fmt.Sprintf("/api/v1/projects/%s/ipWhiteList", projectName)
request = make(map[string]interface{})
query = make(map[string]*string)
body = make(map[string]interface{})
request["projectName"] = d.Id()
if d.HasChange("ip_white_list") {
update = true
}
objectDataLocalMap = make(map[string]interface{})
if v := d.Get("ip_white_list"); v != nil {
ipList1, _ := jsonpath.Get("$[0].ip_list", v)
if ipList1 != nil && (d.HasChange("ip_white_list.0.ip_list") || ipList1 != "") {
objectDataLocalMap["ipList"] = ipList1
}
vpcIpList1, _ := jsonpath.Get("$[0].vpc_ip_list", v)
if vpcIpList1 != nil && (d.HasChange("ip_white_list.0.vpc_ip_list") || vpcIpList1 != "") {
objectDataLocalMap["vpcIpList"] = vpcIpList1
}
request["ipWhiteList"] = objectDataLocalMap
}
body = request
if update {
wait := incrementalWait(3*time.Second, 5*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
response, err = client.RoaPut("MaxCompute", "2022-01-04", action, query, nil, body, true)
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)
}
}
update = false
projectName = d.Id()
action = fmt.Sprintf("/api/v1/projects/%s/security", projectName)
request = make(map[string]interface{})
query = make(map[string]*string)
body = make(map[string]interface{})
request["projectName"] = d.Id()
if d.HasChange("security_properties.0.using_acl") {
update = true
}
if v, ok := d.GetOk("security_properties"); ok || d.HasChange("security_properties") {
jsonPathResult, err := jsonpath.Get("$[0].using_acl", v)
if err == nil && jsonPathResult != "" {
request["usingAcl"] = jsonPathResult
}
}
if d.HasChange("security_properties.0.using_policy") {
update = true
}
if v, ok := d.GetOk("security_properties"); ok || d.HasChange("security_properties") {
jsonPathResult1, err := jsonpath.Get("$[0].using_policy", v)
if err == nil && jsonPathResult1 != "" {
request["usingPolicy"] = jsonPathResult1
}
}
if d.HasChange("security_properties.0.object_creator_has_access_permission") {
update = true
}
if v, ok := d.GetOk("security_properties"); ok || d.HasChange("security_properties") {
jsonPathResult2, err := jsonpath.Get("$[0].object_creator_has_access_permission", v)
if err == nil && jsonPathResult2 != "" {
request["objectCreatorHasAccessPermission"] = jsonPathResult2
}
}
if d.HasChange("security_properties.0.object_creator_has_grant_permission") {
update = true
}
if v, ok := d.GetOk("security_properties"); ok || d.HasChange("security_properties") {
jsonPathResult3, err := jsonpath.Get("$[0].object_creator_has_grant_permission", v)
if err == nil && jsonPathResult3 != "" {
request["objectCreatorHasGrantPermission"] = jsonPathResult3
}
}
if d.HasChange("security_properties.0.label_security") {
update = true
}
if v, ok := d.GetOk("security_properties"); ok || d.HasChange("security_properties") {
jsonPathResult4, err := jsonpath.Get("$[0].label_security", v)
if err == nil && jsonPathResult4 != "" {
request["labelSecurity"] = jsonPathResult4
}
}
if d.HasChange("security_properties.0.enable_download_privilege") {
update = true
}
if v, ok := d.GetOk("security_properties"); ok || d.HasChange("security_properties") {
jsonPathResult5, err := jsonpath.Get("$[0].enable_download_privilege", v)
if err == nil && jsonPathResult5 != "" {
request["enableDownloadPrivilege"] = jsonPathResult5
}
}
if d.HasChange("security_properties") {
update = true
}
objectDataLocalMap = make(map[string]interface{})
if v := d.Get("security_properties"); v != nil {
protected1, _ := jsonpath.Get("$[0].project_protection[0].protected", v)
if protected1 != nil && (d.HasChange("security_properties.0.project_protection.0.protected") || protected1 != "") {
objectDataLocalMap["protected"] = protected1
}
exceptionPolicy1, _ := jsonpath.Get("$[0].project_protection[0].exception_policy", v)
if exceptionPolicy1 != nil && (d.HasChange("security_properties.0.project_protection.0.exception_policy") || exceptionPolicy1 != "") {
objectDataLocalMap["exceptionPolicy"] = exceptionPolicy1
}
request["projectProtection"] = objectDataLocalMap
}
body = request
if update {
wait := incrementalWait(3*time.Second, 5*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
response, err = client.RoaPut("MaxCompute", "2022-01-04", action, query, nil, body, true)
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)
}
}
update = false
projectName = d.Id()
action = fmt.Sprintf("/api/v1/projects/%s/status", projectName)
request = make(map[string]interface{})
query = make(map[string]*string)
body = make(map[string]interface{})
request["projectName"] = d.Id()
if d.HasChange("status") {
update = true
}
if v, ok := d.GetOk("status"); ok || d.HasChange("status") {
request["status"] = v
}
body = request
if update {
wait := incrementalWait(3*time.Second, 5*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
response, err = client.RoaPut("MaxCompute", "2022-01-04", action, query, nil, body, true)
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)
}
}
if d.HasChange("tags") {
maxComputeServiceV2 := MaxComputeServiceV2{client}
if err := maxComputeServiceV2.SetResourceTags(d, "project"); err != nil {
return WrapError(err)
}
}
d.Partial(false)
return resourceAliCloudMaxComputeProjectRead(d, meta)
}