Skip to content

Commit

Permalink
Merge pull request #55 from douwentao/dwt_dev
Browse files Browse the repository at this point in the history
fix es_on_k8s
  • Loading branch information
zshongyi authored Dec 19, 2023
2 parents b20c5f3 + 7298d99 commit 91bc87c
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ func resourceAlibabacloudStackElasticsearchOnk8sCreate(d *schema.ResourceData, m
request.QueryParams = map[string]string{
"RegionId": client.RegionId,
"AccessKeySecret": client.SecretKey,
"AccessKeyId": client.AccessKey,
"Product": "elasticsearch-k8s",
"Action": "createInstance",
"Version": "2017-06-13",
Expand Down Expand Up @@ -327,7 +328,7 @@ func resourceAlibabacloudStackElasticsearchOnk8sCreate(d *schema.ResourceData, m
return WrapErrorf(err, IdMsg, d.Id())
}

return resourceAlibabacloudStackElasticsearchOnk8sUpdate(d, meta)
return resourceAlibabacloudStackElasticsearchOnk8sRead(d, meta)
}

func resourceAlibabacloudStackElasticsearchOnk8sRead(d *schema.ResourceData, meta interface{}) error {
Expand Down Expand Up @@ -435,19 +436,19 @@ func resourceAlibabacloudStackElasticsearchOnk8sUpdate(d *schema.ResourceData, m
//d.SetPartial("private_whitelist")
}

if d.HasChange("enable_public") {
content := make(map[string]interface{})
content["networkType"] = string(PUBLIC)
content["nodeType"] = string(WORKER)
content["actionType"] = elasticsearchService.getActionType(d.Get("enable_public").(bool))
if err := elasticsearchService.TriggerNetwork(d, content, meta); err != nil {
return WrapError(err)
}
// if d.HasChange("enable_public") {
// content := make(map[string]interface{})
// content["networkType"] = string(PUBLIC)
// content["nodeType"] = string(WORKER)
// content["actionType"] = elasticsearchService.getActionType(d.Get("enable_public").(bool))
// if err := elasticsearchService.TriggerNetwork(d, content, meta); err != nil {
// return WrapError(err)
// }

//d.SetPartial("enable_public")
}
// //d.SetPartial("enable_public")
// }

if d.Get("enable_public").(bool) == true && d.HasChange("public_whitelist") {
if d.Get("enable_public").(bool) && d.HasChange("public_whitelist") {
content := make(map[string]interface{})
content["networkType"] = string(PUBLIC)
content["nodeType"] = string(WORKER)
Expand All @@ -459,19 +460,19 @@ func resourceAlibabacloudStackElasticsearchOnk8sUpdate(d *schema.ResourceData, m
//d.SetPartial("public_whitelist")
}

if d.HasChange("enable_kibana_public_network") || d.IsNewResource() {
content := make(map[string]interface{})
content["networkType"] = string(PUBLIC)
content["nodeType"] = string(KIBANA)
content["actionType"] = elasticsearchService.getActionType(d.Get("enable_kibana_public_network").(bool))
if err := elasticsearchService.TriggerNetwork(d, content, meta); err != nil {
return WrapError(err)
}
// if d.HasChange("enable_kibana_public_network") || d.IsNewResource() {
// content := make(map[string]interface{})
// content["networkType"] = string(PUBLIC)
// content["nodeType"] = string(KIBANA)
// content["actionType"] = elasticsearchService.getActionType(d.Get("enable_kibana_public_network").(bool))
// if err := elasticsearchService.TriggerNetwork(d, content, meta); err != nil {
// return WrapError(err)
// }

//d.SetPartial("enable_kibana_public_network")
}
// //d.SetPartial("enable_kibana_public_network")
// }

if d.Get("enable_kibana_public_network").(bool) == true && d.HasChange("kibana_whitelist") {
if d.Get("enable_kibana_public_network").(bool) && d.HasChange("kibana_whitelist") {
content := make(map[string]interface{})
content["networkType"] = string(PUBLIC)
content["nodeType"] = string(KIBANA)
Expand All @@ -483,17 +484,17 @@ func resourceAlibabacloudStackElasticsearchOnk8sUpdate(d *schema.ResourceData, m
//d.SetPartial("kibana_whitelist")
}

if d.HasChange("enable_kibana_private_network") {
content := make(map[string]interface{})
content["networkType"] = string(PRIVATE)
content["nodeType"] = string(KIBANA)
content["actionType"] = elasticsearchService.getActionType(d.Get("enable_kibana_private_network").(bool))
if err := elasticsearchService.TriggerNetwork(d, content, meta); err != nil {
return WrapError(err)
}
// if d.HasChange("enable_kibana_private_network") {
// content := make(map[string]interface{})
// content["networkType"] = string(PRIVATE)
// content["nodeType"] = string(KIBANA)
// content["actionType"] = elasticsearchService.getActionType(d.Get("enable_kibana_private_network").(bool))
// if err := elasticsearchService.TriggerNetwork(d, content, meta); err != nil {
// return WrapError(err)
// }

//d.SetPartial("enable_kibana_private_network")
}
// //d.SetPartial("enable_kibana_private_network")
// }

if d.Get("enable_kibana_private_network").(bool) == true && d.HasChange("kibana_private_whitelist") {
content := make(map[string]interface{})
Expand Down Expand Up @@ -529,28 +530,28 @@ func resourceAlibabacloudStackElasticsearchOnk8sUpdate(d *schema.ResourceData, m
//d.SetPartial("client_node_amount")
}

if d.HasChange("protocol") {
// if d.HasChange("protocol") {

if _, err := stateConf.WaitForState(); err != nil {
return WrapErrorf(err, IdMsg, d.Id())
}
// if _, err := stateConf.WaitForState(); err != nil {
// return WrapErrorf(err, IdMsg, d.Id())
// }

var https func(*schema.ResourceData, interface{}) error
// var https func(*schema.ResourceData, interface{}) error

if d.Get("protocol") == "HTTPS" {
https = openHttps
} else if d.Get("protocol") == "HTTP" {
https = closeHttps
}
// if d.Get("protocol") == "HTTPS" {
// https = openHttps
// } else if d.Get("protocol") == "HTTP" {
// https = closeHttps
// }

if nil != https {
if err := https(d, meta); err != nil {
return WrapError(err)
}
}
// if nil != https {
// if err := https(d, meta); err != nil {
// return WrapError(err)
// }
// }

//d.SetPartial("protocol")
}
// //d.SetPartial("protocol")
// }
if d.HasChange("setting_config") {
conn, err := client.NewElasticsearchClient()
if err != nil {
Expand Down Expand Up @@ -672,7 +673,7 @@ func resourceAlibabacloudStackElasticsearchOnk8sUpdate(d *schema.ResourceData, m
}

d.Partial(false)
return resourceAlibabacloudStackElasticsearchOnk8sRead(d, meta)
return nil
}

func resourceAlibabacloudStackElasticsearchOnk8sDelete(d *schema.ResourceData, meta interface{}) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,30 @@ func resourceAlibabacloudStackGraphDatabaseDbInstance() *schema.Resource {
Update: schema.DefaultTimeout(60 * time.Minute),
},
Schema: map[string]*schema.Schema{
"db_instance_ip_array": {
Type: schema.TypeSet,
// "db_instance_ip_array": {
// Type: schema.TypeSet,
// Optional: true,
// Computed: true,
// Elem: &schema.Resource{
// Schema: map[string]*schema.Schema{
// "db_instance_ip_array_attribute": {
// Type: schema.TypeString,
// Optional: true,
// },
// "db_instance_ip_array_name": {
// Type: schema.TypeString,
// Optional: true,
// },
// "security_ips": {
// Type: schema.TypeString,
// Optional: true,
// },
// },
// },
// },
"security_ips": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"db_instance_ip_array_attribute": {
Type: schema.TypeString,
Optional: true,
},
"db_instance_ip_array_name": {
Type: schema.TypeString,
Optional: true,
},
"security_ips": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
"db_instance_category": {
Type: schema.TypeString,
Expand Down Expand Up @@ -100,11 +104,21 @@ func resourceAlibabacloudStackGraphDatabaseDbInstance() *schema.Resource {
},
"vswitch_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"vpc_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"zone_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
},
}
Expand Down Expand Up @@ -132,6 +146,7 @@ func resourceAlibabacloudStackGraphDatabaseDbInstanceCreate(d *schema.ResourceDa
request["ClientToken"] = buildClientToken("CreateDBInstance")
request["RegionId"] = client.RegionId
request["product"] = "gdb"
request["VSwitchId"] = d.Get("vswitch_id")
request["OrganizationId"] = client.Department
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
Expand Down Expand Up @@ -174,22 +189,23 @@ func resourceAlibabacloudStackGraphDatabaseDbInstanceRead(d *schema.ResourceData
d.Set("status", object["DBInstanceStatus"])
d.Set("vswitch_id", object["VSwitchId"])
d.Set("zone_id", object["ZoneId"])
if DBInstanceIPArray, ok := object["DBInstanceIPArray"]; ok {
DBInstanceIPArrayAry, ok := DBInstanceIPArray.([]interface{})
if ok && len(DBInstanceIPArrayAry) > 0 {
DBInstanceIPArraySli := make([]map[string]interface{}, 0)
for _, DBInstanceIPArrayArg := range DBInstanceIPArrayAry {
DBInstanceIPArrayMap := make(map[string]interface{})
DBInstanceIPArrayMap["security_ips"] = DBInstanceIPArrayArg.(map[string]interface{})["SecurityIps"]
DBInstanceIPArrayMap["db_instance_ip_array_name"] = DBInstanceIPArrayArg.(map[string]interface{})["DBInstanceIPArrayName"]
if v, ok := DBInstanceIPArrayArg.(map[string]interface{})["DBInstanceIPArrayAttribute"]; ok {
DBInstanceIPArrayMap["db_instance_ip_array_attribute"] = v
}
DBInstanceIPArraySli = append(DBInstanceIPArraySli, DBInstanceIPArrayMap)
}
d.Set("db_instance_ip_array", DBInstanceIPArraySli)
}
}
d.Set("security_ips", object["SecurityIps"])
// if DBInstanceIPArray, ok := object["DBInstanceIPArray"]; ok {
// DBInstanceIPArrayAry, ok := DBInstanceIPArray.([]interface{})
// if ok && len(DBInstanceIPArrayAry) > 0 {
// DBInstanceIPArraySli := make([]map[string]interface{}, 0)
// for _, DBInstanceIPArrayArg := range DBInstanceIPArrayAry {
// DBInstanceIPArrayMap := make(map[string]interface{})
// DBInstanceIPArrayMap["security_ips"] = DBInstanceIPArrayArg.(map[string]interface{})["SecurityIps"]
// DBInstanceIPArrayMap["db_instance_ip_array_name"] = DBInstanceIPArrayArg.(map[string]interface{})["DBInstanceIPArrayName"]
// if v, ok := DBInstanceIPArrayArg.(map[string]interface{})["DBInstanceIPArrayAttribute"]; ok {
// DBInstanceIPArrayMap["db_instance_ip_array_attribute"] = v
// }
// DBInstanceIPArraySli = append(DBInstanceIPArraySli, DBInstanceIPArrayMap)
// }
// d.Set("db_instance_ip_array", DBInstanceIPArraySli)
// }
// }
return nil
}
func resourceAlibabacloudStackGraphDatabaseDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
Expand Down
Loading

0 comments on commit 91bc87c

Please sign in to comment.