|
5 | 5 | "encoding/json"
|
6 | 6 | "fmt"
|
7 | 7 | "log"
|
| 8 | + "net/http" |
8 | 9 | "strings"
|
9 | 10 | "time"
|
10 | 11 |
|
@@ -38,6 +39,7 @@ type dmsError struct {
|
38 | 39 | // @API RocketMQ POST /v2/{engine}/{project_id}/instances/{instance_id}/extend
|
39 | 40 | // @API RocketMQ PUT /v2/{project_id}/rocketmq/instances/{instance_id}/configs
|
40 | 41 | // @API RocketMQ GET /v2/{project_id}/rocketmq/instances/{instance_id}/configs
|
| 42 | +// @API RocketMQ POST /v2/{project_id}/{engine}/instances/{instance_id}/plain-ssl-switch |
41 | 43 | // @API EIP GET /v1/{project_id}/publicips
|
42 | 44 | // @API BSS GET /v2/orders/customer-orders/details/{order_id}
|
43 | 45 | // @API BSS POST /v2/orders/subscriptions/resources/autorenew/{instance_id}
|
@@ -184,6 +186,14 @@ func ResourceDmsRocketMQInstance() *schema.Resource {
|
184 | 186 | Computed: true,
|
185 | 187 | Description: `Specifies the instance configs.`,
|
186 | 188 | },
|
| 189 | + // From the behavior of the Console page, this parameter is required. |
| 190 | + // In order to ensure that the default value is returned in future, set Computed behavior. |
| 191 | + "tls_mode": { |
| 192 | + Type: schema.TypeString, |
| 193 | + Optional: true, |
| 194 | + Computed: true, |
| 195 | + Description: `The TLS mode of the instance.`, |
| 196 | + }, |
187 | 197 | "status": {
|
188 | 198 | Type: schema.TypeString,
|
189 | 199 | Computed: true,
|
@@ -506,6 +516,7 @@ func buildCreateRocketmqInstanceBodyParams(d *schema.ResourceData, cfg *config.C
|
506 | 516 | "publicip_id": utils.ValueIgnoreEmpty(d.Get("publicip_id")),
|
507 | 517 | "broker_num": utils.ValueIgnoreEmpty(d.Get("broker_num")),
|
508 | 518 | "enterprise_project_id": utils.ValueIgnoreEmpty(cfg.GetEnterpriseProjectID(d)),
|
| 519 | + "tls_mode": utils.ValueIgnoreEmpty(d.Get("tls_mode")), |
509 | 520 | }
|
510 | 521 | if chargingMode, ok := d.GetOk("charging_mode"); ok && chargingMode == "prePaid" {
|
511 | 522 | bodyParams["bss_param"] = buildCreateRocketmqInstanceBodyBssParams(d)
|
@@ -579,6 +590,46 @@ func buildRocketmqConfigsRequestBody(configs []interface{}) []map[string]string
|
579 | 590 | return rst
|
580 | 591 | }
|
581 | 592 |
|
| 593 | +func updateRocketmqInstanceTLSMode(ctx context.Context, client *golangsdk.ServiceClient, timeout time.Duration, |
| 594 | + instanceId string, tlsMode string) error { |
| 595 | + httpUrl := "v2/{project_id}/rocketmq/instances/{instance_id}/plain-ssl-switch" |
| 596 | + updatePath := client.Endpoint + httpUrl |
| 597 | + updatePath = strings.ReplaceAll(updatePath, "{project_id}", client.ProjectID) |
| 598 | + updatePath = strings.ReplaceAll(updatePath, "{instance_id}", instanceId) |
| 599 | + |
| 600 | + updateOpt := golangsdk.RequestOpts{ |
| 601 | + KeepResponseBody: true, |
| 602 | + JSONBody: map[string]interface{}{ |
| 603 | + "tls_mode": tlsMode, |
| 604 | + }, |
| 605 | + } |
| 606 | + |
| 607 | + retryFunc := func() (interface{}, bool, error) { |
| 608 | + resp, err := client.Request("POST", updatePath, &updateOpt) |
| 609 | + retry, err := handleMultiOperationsError(err) |
| 610 | + return resp, retry, err |
| 611 | + } |
| 612 | + resp, err := common.RetryContextWithWaitForState(&common.RetryContextWithWaitForStateParam{ |
| 613 | + Ctx: ctx, |
| 614 | + RetryFunc: retryFunc, |
| 615 | + WaitFunc: rocketmqInstanceStateRefreshFunc(client, instanceId), |
| 616 | + WaitTarget: []string{"RUNNING"}, |
| 617 | + Timeout: timeout, |
| 618 | + DelayTimeout: 10 * time.Second, |
| 619 | + PollInterval: 20 * time.Second, |
| 620 | + }) |
| 621 | + if err != nil { |
| 622 | + return err |
| 623 | + } |
| 624 | + |
| 625 | + respBody, err := utils.FlattenResponse(resp.(*http.Response)) |
| 626 | + if err != nil { |
| 627 | + return err |
| 628 | + } |
| 629 | + |
| 630 | + return waitForInstanceTaskStatusCompleted(ctx, client, instanceId, utils.PathSearch("job_id", respBody, "").(string), timeout) |
| 631 | +} |
| 632 | + |
582 | 633 | func resourceDmsRocketMQInstanceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
|
583 | 634 | cfg := meta.(*config.Config)
|
584 | 635 | region := cfg.GetRegion(d)
|
@@ -714,6 +765,14 @@ func resourceDmsRocketMQInstanceUpdate(ctx context.Context, d *schema.ResourceDa
|
714 | 765 | }
|
715 | 766 | }
|
716 | 767 |
|
| 768 | + if d.HasChange("tls_mode") { |
| 769 | + err = updateRocketmqInstanceTLSMode(ctx, updateRocketmqInstanceClient, d.Timeout(schema.TimeoutUpdate), |
| 770 | + instanceId, d.Get("tls_mode").(string)) |
| 771 | + if err != nil { |
| 772 | + return diag.Errorf("error updating SSL mode of the RocketMQ instance (%s): %s", instanceId, err) |
| 773 | + } |
| 774 | + } |
| 775 | + |
717 | 776 | return resourceDmsRocketMQInstanceRead(ctx, d, meta)
|
718 | 777 | }
|
719 | 778 |
|
@@ -882,6 +941,7 @@ func resourceDmsRocketMQInstanceRead(_ context.Context, d *schema.ResourceData,
|
882 | 941 | d.Set("resource_spec_code", utils.PathSearch("resource_spec_code", getRocketmqInstanceRespBody, nil)),
|
883 | 942 | d.Set("cross_vpc_accesses", crossVpcAccess),
|
884 | 943 | d.Set("charging_mode", chargingMode),
|
| 944 | + d.Set("tls_mode", utils.PathSearch("tls_mode", getRocketmqInstanceRespBody, nil)), |
885 | 945 | )
|
886 | 946 |
|
887 | 947 | // get configs
|
|
0 commit comments