Skip to content

Commit fb9bafe

Browse files
authored
Merge pull request #602 from junchuguo/master
add cfs and tcr attribute
2 parents bc50aa5 + 0e01577 commit fb9bafe

File tree

35 files changed

+899
-47
lines changed

35 files changed

+899
-47
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 `open_public_network` 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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ 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+
ForceNew: true,
80+
Description: "File service StorageType. Valid values are `SD` and `HP`. and the default is `SD`.",
81+
},
82+
7583
"vpc_id": {
7684
Type: schema.TypeString,
7785
Required: true,
@@ -121,14 +129,15 @@ func resourceTencentCloudCfsFileSystemCreate(d *schema.ResourceData, meta interf
121129
request.Protocol = helper.String(d.Get("protocol").(string))
122130
request.VpcId = helper.String(d.Get("vpc_id").(string))
123131
request.SubnetId = helper.String(d.Get("subnet_id").(string))
132+
request.StorageType = helper.String(d.Get("storage_type").(string))
124133
if v, ok := d.GetOk("name"); ok {
125134
request.FsName = helper.String(v.(string))
126135
}
127136
if v, ok := d.GetOk("mount_ip"); ok {
128137
request.MountIP = helper.String(v.(string))
129138
}
130139
request.NetInterface = helper.String("VPC")
131-
request.StorageType = helper.String("SD")
140+
request.StorageType = helper.String(d.Get("storage_type").(string))
132141

133142
fsId := ""
134143
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
@@ -218,6 +227,7 @@ func resourceTencentCloudCfsFileSystemRead(d *schema.ResourceData, meta interfac
218227
_ = d.Set("access_group_id", fileSystem.PGroup.PGroupId)
219228
_ = d.Set("protocol", fileSystem.Protocol)
220229
_ = d.Set("create_time", fileSystem.CreationTime)
230+
_ = d.Set("storage_type", fileSystem.StorageType)
221231

222232
var mountTarget *cfs.MountInfo
223233
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: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,24 @@ func resourceTencentCloudTcrInstance() *schema.Resource {
6262
ForceNew: true,
6363
Description: "The available tags within this TCR instance.",
6464
},
65+
"open_public_operation": {
66+
Type: schema.TypeBool,
67+
Optional: true,
68+
ForceNew: true,
69+
Default: false,
70+
Description: "Control public network access.",
71+
},
6572
//Computed values
6673
"status": {
6774
Type: schema.TypeString,
6875
Computed: true,
6976
Description: "Status of the TCR instance.",
7077
},
78+
"public_status": {
79+
Type: schema.TypeString,
80+
Computed: true,
81+
Description: "Status of the TCR instance public network access.",
82+
},
7183
"public_domain": {
7284
Type: schema.TypeString,
7385
Computed: true,
@@ -97,11 +109,13 @@ func resourceTencentCloudTcrInstanceCreate(d *schema.ResourceData, meta interfac
97109
tcrService := TCRService{client: meta.(*TencentCloudClient).apiV3Conn}
98110

99111
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
112+
name = d.Get("name").(string)
113+
insType = d.Get("instance_type").(string)
114+
tags = helper.GetTags(d, "tags")
115+
outErr, inErr error
116+
instanceId string
117+
instanceStatus string
118+
operation bool
105119
)
106120

107121
outErr = resource.Retry(writeRetryTimeout, func() *resource.RetryError {
@@ -123,6 +137,7 @@ func resourceTencentCloudTcrInstanceCreate(d *schema.ResourceData, meta interfac
123137
if err != nil {
124138
return retryError(err)
125139
} else if has && *instance.Status == "Running" {
140+
instanceStatus = "Running"
126141
return nil
127142
} else if !has {
128143
return resource.NonRetryableError(fmt.Errorf("create tcr instance fail"))
@@ -134,6 +149,25 @@ func resourceTencentCloudTcrInstanceCreate(d *schema.ResourceData, meta interfac
134149
if err != nil {
135150
return err
136151
}
152+
if instanceStatus == "Running" {
153+
outErr = resource.Retry(writeRetryTimeout, func() *resource.RetryError {
154+
if v, ok := d.GetOk("open_public_operation"); ok {
155+
operation = v.(bool)
156+
if operation {
157+
inErr = tcrService.ManageTCRExternalEndpoint(ctx, instanceId, "Create")
158+
} else {
159+
inErr = tcrService.ManageTCRExternalEndpoint(ctx, instanceId, "Delete")
160+
}
161+
if inErr != nil {
162+
return retryError(inErr)
163+
}
164+
}
165+
return nil
166+
})
167+
if outErr != nil {
168+
return outErr
169+
}
170+
}
137171

138172
return resourceTencentCloudTcrInstanceRead(d, meta)
139173
}
@@ -164,11 +198,35 @@ func resourceTencentCloudTcrInstanceRead(d *schema.ResourceData, meta interface{
164198
return nil
165199
}
166200

201+
publicStatus, has, outErr := tcrService.DescribeExternalEndpointStatus(ctx, d.Id())
202+
if outErr != nil {
203+
outErr = resource.Retry(readRetryTimeout, func() *resource.RetryError {
204+
publicStatus, has, inErr = tcrService.DescribeExternalEndpointStatus(ctx, d.Id())
205+
if inErr != nil {
206+
return retryError(inErr)
207+
}
208+
return nil
209+
})
210+
}
211+
if outErr != nil {
212+
return outErr
213+
}
214+
if !has {
215+
d.SetId("")
216+
return nil
217+
}
218+
if publicStatus == "Opening" || publicStatus == "Opened" {
219+
_ = d.Set("open_public_operation", true)
220+
} else if publicStatus == "Closed" {
221+
_ = d.Set("open_public_operation", false)
222+
}
223+
167224
_ = d.Set("name", instance.RegistryName)
168225
_ = d.Set("instance_type", instance.RegistryType)
169226
_ = d.Set("status", instance.Status)
170227
_ = d.Set("public_domain", instance.PublicDomain)
171228
_ = d.Set("internal_end_point", instance.InternalEndpoint)
229+
_ = d.Set("public_status", publicStatus)
172230

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

tencentcloud/resource_tc_tcr_instance_test.go

Lines changed: 7 additions & 6 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"),
@@ -38,8 +38,9 @@ func TestAccTencentCloudTCRInstance_basic_and_update(t *testing.T) {
3838
Config: testAccTCRInstance_basic_update_remark,
3939
Check: resource.ComposeAggregateTestCheckFunc(
4040
testAccCheckTCRInstanceExists("tencentcloud_tcr_instance.mytcr_instance"),
41-
resource.TestCheckResourceAttr("tencentcloud_tcr_instance.mytcr_instance", "tags.tf", "tf"),
41+
resource.TestCheckResourceAttr("tencentcloud_tcr_instance.mytcr_instance", "tags.test", "test"),
4242
resource.TestCheckResourceAttr("tencentcloud_tcr_instance.mytcr_instance", "delete_bucket", "true"),
43+
resource.TestCheckResourceAttr("tencentcloud_tcr_instance.mytcr_instance", "open_public_operation", "true"),
4344
),
4445
},
4546
},
@@ -93,7 +94,7 @@ func testAccCheckTCRInstanceExists(n string) resource.TestCheckFunc {
9394

9495
const testAccTCRInstance_basic = `
9596
resource "tencentcloud_tcr_instance" "mytcr_instance" {
96-
name = "testacctcrinstance"
97+
name = "testacctcrinstance1"
9798
instance_type = "basic"
9899
delete_bucket = true
99100
@@ -104,11 +105,11 @@ 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 = "testacctcrinstance1"
108109
instance_type = "basic"
109110
delete_bucket = true
110-
111+
open_public_operation = true
111112
tags ={
112-
tf = "tf"
113+
test = "test"
113114
}
114115
}`

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)