Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add trocket rile #2153

Merged
merged 3 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/2153.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
tencentcloud_trocket_rocketmq_role
```
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.693
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.711
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.755
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.756
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.589
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.692
Expand Down Expand Up @@ -88,7 +88,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.578
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.730
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.691
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/trocket v1.0.746
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/trocket v1.0.756
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse v1.0.755
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tsf v1.0.674
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod v1.0.199
Expand Down
11 changes: 4 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -854,17 +854,16 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.725/go.mod
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.726/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.729/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.730/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.732/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.734/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.736/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.745/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.746/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.748/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.750/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.751/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.754/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.755 h1:mAhmX5bEBbLoLfeQu7y6ygeWFle4Kb4Z5e+sp8QyZcA=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.755/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.756 h1:TpeGo45T48N5OJ6LekUdMt3sjYJi4jis4x5jFo8Vz8A=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.756/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624 h1:nEZqsoqt1pEoaP9JjkHQy3/H00suCfzlHW1qOm2nYD8=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624/go.mod h1:+TXSVyeKwt1IhZRqKPbTREteBcP+K07Q846/ilNzLWA=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.589 h1:LZihgirMH0vsaGScYexxwY0fTss9vHaSZs/YOQUVESg=
Expand Down Expand Up @@ -955,10 +954,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.730 h1:isKxaxm
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.730/go.mod h1:vA9wf067VO5kkEjUgViUw/VA0ALUXE/wbSI1baeuHpI=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.691 h1:D+a7bZnjLoqPAAHSPCOmil4eigXnGPkR1R5G3ybT/+c=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.691/go.mod h1:hsc/CPzbCRXqblCYuE1HuvP3G06OWA9zhAGI6AtEe5U=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/trocket v1.0.746 h1:ZHfhs8xTWUtKHwDJQNd8mGzV2hFifwKOWYDJTbPrOSM=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/trocket v1.0.746/go.mod h1:NS1bkjH/+dhwCFvluZd+uq8h8hbnOHJaFDbkQe0YTm4=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse v1.0.732 h1:hC6bRxIBwjAEnqDsJh8tpY/SqcSfP84exN+cVvHwtd4=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse v1.0.732/go.mod h1:jF0O9bIPZ/oQ+m3qeEfWHLbtsJFKNaiqvdSNGP7AQCI=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/trocket v1.0.756 h1:89M6uA8Y/FC1b88TFxvRManGW+i62Isqg1lW8HjHDvU=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/trocket v1.0.756/go.mod h1:AJAItBOTaarpDpUF7pNp0tuz2Y6H2oFuMcyKouPs1IE=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse v1.0.755 h1:DbYmGORd2zBnry69k6BR9hzEczrOmbNScE92POutYOY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse v1.0.755/go.mod h1:o+ABiUSkJQowYQjJsLBHBJsxy4BosjGVuRAsXas+VlY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tsf v1.0.674 h1:VsMV1/vsgVzespG7jUzraZS/AbAUllVQjmtVAlA9W/M=
Expand Down
2 changes: 2 additions & 0 deletions tencentcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,7 @@ TDMQ for RocketMQ(trocket)
tencentcloud_trocket_rocketmq_instance
tencentcloud_trocket_rocketmq_topic
tencentcloud_trocket_rocketmq_consumer_group
tencentcloud_trocket_rocketmq_role

TDMQ for RabbitMQ(trabbit)
Resource
Expand Down Expand Up @@ -2933,6 +2934,7 @@ func Provider() *schema.Provider {
"tencentcloud_trocket_rocketmq_instance": resourceTencentCloudTrocketRocketmqInstance(),
"tencentcloud_trocket_rocketmq_topic": resourceTencentCloudTrocketRocketmqTopic(),
"tencentcloud_trocket_rocketmq_consumer_group": resourceTencentCloudTrocketRocketmqConsumerGroup(),
"tencentcloud_trocket_rocketmq_role": resourceTencentCloudTrocketRocketmqRole(),
"tencentcloud_dts_sync_job": resourceTencentCloudDtsSyncJob(),
"tencentcloud_dts_sync_config": resourceTencentCloudDtsSyncConfig(),
"tencentcloud_dts_sync_check_job_operation": resourceTencentCloudDtsSyncCheckJobOperation(),
Expand Down
293 changes: 293 additions & 0 deletions tencentcloud/resource_tc_trocket_rocketmq_role.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,293 @@
/*
Provides a resource to create a trocket rocketmq_role

Example Usage

```hcl
resource "tencentcloud_trocket_rocketmq_instance" "rocketmq_instance" {
instance_type = "EXPERIMENT"
name = "test_role"
sku_code = "experiment_500"
remark = "test"
vpc_id = "vpc-xxxxx"
subnet_id = "subnet-xxxxx"
tags = {
tag_key = "rocketmq"
tag_value = "5.x"
}
}

resource "tencentcloud_trocket_rocketmq_role" "rocketmq_role" {
instance_id = tencentcloud_trocket_rocketmq_instance.rocketmq_instance.id
role = "test_role"
remark = "test for terraform"
perm_write = false
perm_read = true
}
```

Import

trocket rocketmq_role can be imported using the id, e.g.

```
terraform import tencentcloud_trocket_rocketmq_role.rocketmq_role instanceId#role
```
*/
package tencentcloud

import (
"context"
"fmt"
"log"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
trocket "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/trocket/v20230308"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)

func resourceTencentCloudTrocketRocketmqRole() *schema.Resource {
return &schema.Resource{
Create: resourceTencentCloudTrocketRocketmqRoleCreate,
Read: resourceTencentCloudTrocketRocketmqRoleRead,
Update: resourceTencentCloudTrocketRocketmqRoleUpdate,
Delete: resourceTencentCloudTrocketRocketmqRoleDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"instance_id": {
Required: true,
Type: schema.TypeString,
ForceNew: true,
Description: "ID of instance.",
},

"role": {
Required: true,
Type: schema.TypeString,
ForceNew: true,
Description: "Name of role.",
},

"remark": {
Required: true,
Type: schema.TypeString,
Description: "remark.",
},

"perm_write": {
Required: true,
Type: schema.TypeBool,
Description: "Whether to enable production permission.",
},

"perm_read": {
Required: true,
Type: schema.TypeBool,
Description: "Whether to enable consumption permission.",
},

"created_time": {
Computed: true,
Type: schema.TypeInt,
Description: "Created time.",
},

"modified_time": {
Computed: true,
Type: schema.TypeInt,
Description: "Modified time.",
},
},
}
}

func resourceTencentCloudTrocketRocketmqRoleCreate(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("resource.tencentcloud_trocket_rocketmq_role.create")()
defer inconsistentCheck(d, meta)()

logId := getLogId(contextNil)

var (
request = trocket.NewCreateRoleRequest()
response = trocket.NewCreateRoleResponse()
instanceId string
role string
)
if v, ok := d.GetOk("instance_id"); ok {
instanceId = v.(string)
request.InstanceId = helper.String(v.(string))
}

if v, ok := d.GetOk("role"); ok {
request.Role = helper.String(v.(string))
}

if v, ok := d.GetOk("remark"); ok {
request.Remark = helper.String(v.(string))
}

if v, ok := d.GetOkExists("perm_write"); ok {
request.PermWrite = helper.Bool(v.(bool))
}

if v, ok := d.GetOkExists("perm_read"); ok {
request.PermRead = helper.Bool(v.(bool))
}

err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
result, e := meta.(*TencentCloudClient).apiV3Conn.UseTrocketClient().CreateRole(request)
if e != nil {
return retryError(e)
} else {
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
}
response = result
return nil
})
if err != nil {
log.Printf("[CRITAL]%s create trocket rocketmqRole failed, reason:%+v", logId, err)
return err
}

role = *response.Response.Role
d.SetId(instanceId + FILED_SP + role)

return resourceTencentCloudTrocketRocketmqRoleRead(d, meta)
}

func resourceTencentCloudTrocketRocketmqRoleRead(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("resource.tencentcloud_trocket_rocketmq_role.read")()
defer inconsistentCheck(d, meta)()

logId := getLogId(contextNil)

ctx := context.WithValue(context.TODO(), logIdKey, logId)

service := TrocketService{client: meta.(*TencentCloudClient).apiV3Conn}

idSplit := strings.Split(d.Id(), FILED_SP)
if len(idSplit) != 2 {
return fmt.Errorf("id is broken,%s", d.Id())
}
instanceId := idSplit[0]
role := idSplit[1]

rocketmqRole, err := service.DescribeTrocketRocketmqRoleById(ctx, instanceId, role)
if err != nil {
return err
}

if rocketmqRole == nil {
d.SetId("")
log.Printf("[WARN]%s resource `TrocketRocketmqRole` [%s] not found, please check if it has been deleted.\n", logId, d.Id())
return nil
}

_ = d.Set("instance_id", instanceId)
_ = d.Set("role", role)

if rocketmqRole.Remark != nil {
_ = d.Set("remark", rocketmqRole.Remark)
}

if rocketmqRole.PermWrite != nil {
_ = d.Set("perm_write", rocketmqRole.PermWrite)
}

if rocketmqRole.PermRead != nil {
_ = d.Set("perm_read", rocketmqRole.PermRead)
}

if rocketmqRole.CreatedTime != nil {
_ = d.Set("created_time", rocketmqRole.CreatedTime)
}

if rocketmqRole.ModifiedTime != nil {
_ = d.Set("modified_time", rocketmqRole.ModifiedTime)
}

return nil
}

func resourceTencentCloudTrocketRocketmqRoleUpdate(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("resource.tencentcloud_trocket_rocketmq_role.update")()
defer inconsistentCheck(d, meta)()

logId := getLogId(contextNil)

request := trocket.NewModifyRoleRequest()

idSplit := strings.Split(d.Id(), FILED_SP)
if len(idSplit) != 2 {
return fmt.Errorf("id is broken,%s", d.Id())
}
instanceId := idSplit[0]
role := idSplit[1]

request.InstanceId = &instanceId
request.Role = &role

mutableArgs := []string{"remark", "perm_write", "perm_read"}
needChange := false

for _, v := range mutableArgs {
if d.HasChange(v) {
needChange = true
}
}

if needChange {
if v, ok := d.GetOk("remark"); ok {
request.Remark = helper.String(v.(string))
}

if v, ok := d.GetOkExists("perm_write"); ok {
request.PermWrite = helper.Bool(v.(bool))
}

if v, ok := d.GetOkExists("perm_read"); ok {
request.PermRead = helper.Bool(v.(bool))
}

err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
result, e := meta.(*TencentCloudClient).apiV3Conn.UseTrocketClient().ModifyRole(request)
if e != nil {
return retryError(e)
} else {
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
}
return nil
})
if err != nil {
log.Printf("[CRITAL]%s update trocket rocketmqRole failed, reason:%+v", logId, err)
return err
}
}
return resourceTencentCloudTrocketRocketmqRoleRead(d, meta)
}

func resourceTencentCloudTrocketRocketmqRoleDelete(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("resource.tencentcloud_trocket_rocketmq_role.delete")()
defer inconsistentCheck(d, meta)()

logId := getLogId(contextNil)
ctx := context.WithValue(context.TODO(), logIdKey, logId)

service := TrocketService{client: meta.(*TencentCloudClient).apiV3Conn}
idSplit := strings.Split(d.Id(), FILED_SP)
if len(idSplit) != 2 {
return fmt.Errorf("id is broken,%s", d.Id())
}
instanceId := idSplit[0]
role := idSplit[1]

if err := service.DeleteTrocketRocketmqRoleById(ctx, instanceId, role); err != nil {
return err
}

return nil
}
Loading
Loading