Skip to content

Commit 19bcd68

Browse files
author
“guojunchu”
committed
add cfs and tcr attribute
1 parent bc50aa5 commit 19bcd68

File tree

35 files changed

+903
-45
lines changed

35 files changed

+903
-45
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
ENHANCEMENTS:
44

55
* Resource `tencentcloud_instance` add `cam_role_name` to support binding role to cvm instance.
6+
* Resource `tencentcloud_tcr_instance` add `public_operation` to control public network access.
7+
* Resource `tencentcloud_cfs_file_system` add `storage_type` to change file service StorageType.
68

79
BUG FIXES:
810

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
github.com/mattn/go-colorable v0.1.6 // indirect
1616
github.com/mitchellh/go-homedir v1.1.0
1717
github.com/pkg/errors v0.9.1
18-
github.com/tencentcloud/tencentcloud-sdk-go v1.0.112
18+
github.com/tencentcloud/tencentcloud-sdk-go v1.0.119
1919
github.com/yangwenmai/ratelimit v0.0.0-20180104140304-44221c2292e1
2020
github.com/zclconf/go-cty v1.4.2 // indirect
2121
golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,8 @@ github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2 h1:Xr9gkxfOP0K
443443
github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2/go.mod h1:yHp0ai0Z9gUljN3o0xMhYJnH/IcvkdTBOX2fmJ93JEM=
444444
github.com/tencentcloud/tencentcloud-sdk-go v1.0.112 h1:/vDVXeIWSVteNNJULedeWnqrcQxJlMDSQfxdwkc2XgI=
445445
github.com/tencentcloud/tencentcloud-sdk-go v1.0.112/go.mod h1:asUz5BPXxgoPGaRgZaVm1iGcUAuHyYUo1nXqKa83cvI=
446+
github.com/tencentcloud/tencentcloud-sdk-go v1.0.119 h1:wjidEbe8rWoQNfUEzILykgi4SO1LYjC4tNRY7RN8chI=
447+
github.com/tencentcloud/tencentcloud-sdk-go v1.0.119/go.mod h1:asUz5BPXxgoPGaRgZaVm1iGcUAuHyYUo1nXqKa83cvI=
446448
github.com/tetafro/godot v0.3.7 h1:+mecr7RKrUKB5UQ1gwqEMn13sDKTyDR8KNIquB9mm+8=
447449
github.com/tetafro/godot v0.3.7/go.mod h1:/7NLHhv08H1+8DNj0MElpAACw1ajsCuf3TKNQxA5S+0=
448450
github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e h1:RumXZ56IrCj4CL+g1b9OL/oH0QnsF976bC8xQFYUD5Q=

tencentcloud/extension_cfs.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ const (
44
CFS_PROTOCOL_NFS = "NFS"
55
CFS_PROTOCOL_CIFS = "CIFS"
66

7+
CFS_STORAGETYPE_SD = "SD"
8+
CFS_STORAGETYPE_HP = "HP"
9+
710
CFS_FILE_SYSTEM_STATUS_CREATING = "creating"
811
CFS_FILE_SYSTEM_STATUS_SUCCESS = "available"
912
CFS_FILE_SYSTEM_STATUS_FAILED = "create_failed"
@@ -17,6 +20,11 @@ const (
1720
CFS_USER_PERMISSION_NO_ROOT_SQUASH = "no_root_squash"
1821
)
1922

23+
var CFS_STORAGETYPE = []string{
24+
CFS_STORAGETYPE_SD,
25+
CFS_STORAGETYPE_HP,
26+
}
27+
2028
var CFS_PROTOCOL = []string{
2129
CFS_PROTOCOL_NFS,
2230
CFS_PROTOCOL_CIFS,

tencentcloud/resource_tc_cfs_file_system.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ func resourceTencentCloudCfsFileSystem() *schema.Resource {
7272
ForceNew: true,
7373
Description: "File service protocol. Valid values are `NFS` and `CIFS`. and the default is `NFS`.",
7474
},
75+
"storage_type": {
76+
Type: schema.TypeString,
77+
Optional: true,
78+
Default: CFS_STORAGETYPE_SD,
79+
ValidateFunc: validateAllowedStringValue(CFS_STORAGETYPE),
80+
ForceNew: true,
81+
Description: "File service StorageType. Valid values are `SD` and `HP`. and the default is `SD`.",
82+
},
83+
7584
"vpc_id": {
7685
Type: schema.TypeString,
7786
Required: true,
@@ -121,14 +130,15 @@ func resourceTencentCloudCfsFileSystemCreate(d *schema.ResourceData, meta interf
121130
request.Protocol = helper.String(d.Get("protocol").(string))
122131
request.VpcId = helper.String(d.Get("vpc_id").(string))
123132
request.SubnetId = helper.String(d.Get("subnet_id").(string))
133+
request.StorageType = helper.String(d.Get("storage_type").(string))
124134
if v, ok := d.GetOk("name"); ok {
125135
request.FsName = helper.String(v.(string))
126136
}
127137
if v, ok := d.GetOk("mount_ip"); ok {
128138
request.MountIP = helper.String(v.(string))
129139
}
130140
request.NetInterface = helper.String("VPC")
131-
request.StorageType = helper.String("SD")
141+
request.StorageType = helper.String(d.Get("storage_type").(string))
132142

133143
fsId := ""
134144
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
@@ -218,6 +228,7 @@ func resourceTencentCloudCfsFileSystemRead(d *schema.ResourceData, meta interfac
218228
_ = d.Set("access_group_id", fileSystem.PGroup.PGroupId)
219229
_ = d.Set("protocol", fileSystem.Protocol)
220230
_ = d.Set("create_time", fileSystem.CreationTime)
231+
_ = d.Set("storage_type", fileSystem.StorageType)
221232

222233
var mountTarget *cfs.MountInfo
223234
err = resource.Retry(readRetryTimeout, func() *resource.RetryError {

tencentcloud/resource_tc_cfs_file_system_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ resource "tencentcloud_cfs_file_system" "foo" {
143143
protocol = "NFS"
144144
vpc_id = tencentcloud_vpc.vpc.id
145145
subnet_id = tencentcloud_subnet.subnet.id
146+
storage_type = "SD"
146147
}
147148
`
148149

@@ -172,6 +173,7 @@ resource "tencentcloud_cfs_file_system" "foo" {
172173
protocol = "NFS"
173174
vpc_id = tencentcloud_vpc.vpc.id
174175
subnet_id = tencentcloud_subnet.subnet.id
176+
storage_type = "SD"
175177
176178
tags = {
177179
test = "test-tf"

tencentcloud/resource_tc_tcr_instance.go

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,23 @@ func resourceTencentCloudTcrInstance() *schema.Resource {
6262
ForceNew: true,
6363
Description: "The available tags within this TCR instance.",
6464
},
65+
"public_operation": {
66+
Type: schema.TypeString,
67+
Optional: true,
68+
ForceNew: true,
69+
Description: "Control public network access. Valid values are:`Create`, `Delete`.",
70+
},
6571
//Computed values
6672
"status": {
6773
Type: schema.TypeString,
6874
Computed: true,
6975
Description: "Status of the TCR instance.",
7076
},
77+
"public_status": {
78+
Type: schema.TypeString,
79+
Computed: true,
80+
Description: "Status of the TCR instance public network access.",
81+
},
7182
"public_domain": {
7283
Type: schema.TypeString,
7384
Computed: true,
@@ -97,11 +108,11 @@ func resourceTencentCloudTcrInstanceCreate(d *schema.ResourceData, meta interfac
97108
tcrService := TCRService{client: meta.(*TencentCloudClient).apiV3Conn}
98109

99110
var (
100-
name = d.Get("name").(string)
101-
insType = d.Get("instance_type").(string)
102-
tags = helper.GetTags(d, "tags")
103-
outErr, inErr error
104-
instanceId string
111+
name = d.Get("name").(string)
112+
insType = d.Get("instance_type").(string)
113+
tags = helper.GetTags(d, "tags")
114+
outErr, inErr error
115+
instanceId, operation string
105116
)
106117

107118
outErr = resource.Retry(writeRetryTimeout, func() *resource.RetryError {
@@ -135,6 +146,34 @@ func resourceTencentCloudTcrInstanceCreate(d *schema.ResourceData, meta interfac
135146
return err
136147
}
137148

149+
outErr = resource.Retry(writeRetryTimeout, func() *resource.RetryError {
150+
if v, ok := d.GetOk("public_operation"); ok {
151+
operation = v.(string)
152+
inErr = tcrService.ManageTCRExternalEndpoint(ctx, instanceId, operation)
153+
if inErr != nil {
154+
return retryError(inErr)
155+
}
156+
}
157+
return nil
158+
})
159+
if outErr != nil {
160+
return outErr
161+
}
162+
163+
outErr = resource.Retry(writeRetryTimeout, func() *resource.RetryError {
164+
if v, ok := d.GetOk("public_operation"); ok {
165+
operation = v.(string)
166+
inErr = tcrService.ManageTCRExternalEndpoint(ctx, instanceId, operation)
167+
if inErr != nil {
168+
return retryError(inErr)
169+
}
170+
}
171+
return nil
172+
})
173+
if outErr != nil {
174+
return outErr
175+
}
176+
138177
return resourceTencentCloudTcrInstanceRead(d, meta)
139178
}
140179

@@ -164,11 +203,35 @@ func resourceTencentCloudTcrInstanceRead(d *schema.ResourceData, meta interface{
164203
return nil
165204
}
166205

206+
publicStatus, has, outErr := tcrService.DescribeExternalEndpointStatus(ctx, d.Id())
207+
if outErr != nil {
208+
outErr = resource.Retry(readRetryTimeout, func() *resource.RetryError {
209+
publicStatus, has, inErr = tcrService.DescribeExternalEndpointStatus(ctx, d.Id())
210+
if inErr != nil {
211+
return retryError(inErr)
212+
}
213+
return nil
214+
})
215+
}
216+
if outErr != nil {
217+
return outErr
218+
}
219+
if !has {
220+
d.SetId("")
221+
return nil
222+
}
223+
if publicStatus == "Opening" || publicStatus == "Opened" {
224+
_ = d.Set("public_operation", "Create")
225+
} else if publicStatus == "Closed" {
226+
_ = d.Set("public_operation", "Delete")
227+
}
228+
167229
_ = d.Set("name", instance.RegistryName)
168230
_ = d.Set("instance_type", instance.RegistryType)
169231
_ = d.Set("status", instance.Status)
170232
_ = d.Set("public_domain", instance.PublicDomain)
171233
_ = d.Set("internal_end_point", instance.InternalEndpoint)
234+
_ = d.Set("public_status", publicStatus)
172235

173236
tags := make(map[string]string, len(instance.TagSpecification.Tags))
174237
for _, tag := range instance.TagSpecification.Tags {

tencentcloud/resource_tc_tcr_instance_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestAccTencentCloudTCRInstance_basic_and_update(t *testing.T) {
1818
{
1919
Config: testAccTCRInstance_basic,
2020
Check: resource.ComposeAggregateTestCheckFunc(
21-
resource.TestCheckResourceAttr("tencentcloud_tcr_instance.mytcr_instance", "name", "testacctcrinstance"),
21+
resource.TestCheckResourceAttr("tencentcloud_tcr_instance.mytcr_instance", "name", "testacctcrinstance1"),
2222
resource.TestCheckResourceAttr("tencentcloud_tcr_instance.mytcr_instance", "instance_type", "basic"),
2323
resource.TestCheckResourceAttr("tencentcloud_tcr_instance.mytcr_instance", "tags.test", "test"),
2424
resource.TestCheckResourceAttr("tencentcloud_tcr_instance.mytcr_instance", "delete_bucket", "true"),
@@ -93,9 +93,10 @@ func testAccCheckTCRInstanceExists(n string) resource.TestCheckFunc {
9393

9494
const testAccTCRInstance_basic = `
9595
resource "tencentcloud_tcr_instance" "mytcr_instance" {
96-
name = "testacctcrinstance"
96+
name = "testacctcrinstance1"
9797
instance_type = "basic"
9898
delete_bucket = true
99+
public_operation = "Create"
99100
100101
tags ={
101102
test = "test"
@@ -104,10 +105,10 @@ resource "tencentcloud_tcr_instance" "mytcr_instance" {
104105

105106
const testAccTCRInstance_basic_update_remark = `
106107
resource "tencentcloud_tcr_instance" "mytcr_instance" {
107-
name = "testacctcrinstance"
108+
name = "testacctcrinstance2"
108109
instance_type = "basic"
109110
delete_bucket = true
110-
111+
public_operation = "Create"
111112
tags ={
112113
tf = "tf"
113114
}

tencentcloud/service_tencentcloud_tcr.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,59 @@ func (me *TCRService) CreateTCRInstance(ctx context.Context, name string, instan
5151
return
5252
}
5353

54+
func (me *TCRService) ManageTCRExternalEndpoint(ctx context.Context, instanceId, operation string) (errRet error) {
55+
logId := getLogId(ctx)
56+
request := tcr.NewManageExternalEndpointRequest()
57+
defer func() {
58+
if errRet != nil {
59+
log.Printf("[CRITAL]%s api[%s] fail,reason[%s]", logId, request.GetAction(), errRet.Error())
60+
}
61+
}()
62+
request.Operation = &operation
63+
request.RegistryId = &instanceId
64+
65+
ratelimit.Check(request.GetAction())
66+
response, err := me.client.UseTCRClient().ManageExternalEndpoint(request)
67+
if err != nil {
68+
errRet = err
69+
return
70+
}
71+
if response == nil || response.Response == nil || response.Response.RegistryId == nil {
72+
errRet = fmt.Errorf("TencentCloud SDK return nil response, %s", request.GetAction())
73+
}
74+
75+
return
76+
}
77+
78+
func (me *TCRService) DescribeExternalEndpointStatus(ctx context.Context, instanceId string) (status string, has bool, errRet error) {
79+
logId := getLogId(ctx)
80+
request := tcr.NewDescribeExternalEndpointStatusRequest()
81+
defer func() {
82+
if errRet != nil {
83+
log.Printf("[CRITAL]%s api[%s] fail,reason[%s]", logId, request.GetAction(), errRet.Error())
84+
}
85+
}()
86+
request.RegistryId = &instanceId
87+
88+
ratelimit.Check(request.GetAction())
89+
response, err := me.client.UseTCRClient().DescribeExternalEndpointStatus(request)
90+
if err != nil {
91+
errRet = err
92+
return
93+
}
94+
if response == nil || response.Response == nil {
95+
errRet = fmt.Errorf("TencentCloud SDK return nil response, %s", request.GetAction())
96+
return
97+
}
98+
if response.Response.Status == nil {
99+
errRet = fmt.Errorf("TencentCloud SDK return more than one instances, instanceId %s, %s", instanceId, request.GetAction())
100+
return
101+
}
102+
has = true
103+
status = *response.Response.Status
104+
return
105+
}
106+
54107
func (me *TCRService) DescribeTCRInstanceById(ctx context.Context, instanceId string) (instance *tcr.Registry, has bool, errRet error) {
55108
logId := getLogId(ctx)
56109
request := tcr.NewDescribeInstancesRequest()

vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cam/v20190116/client.go

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)