Skip to content

Commit f1bf3ad

Browse files
tongyimingmikatong
andauthored
tcr support paypaid (#1515)
* tcr support paypaid * add changelog * update * update Co-authored-by: mikatong <mikatong@tencent.com>
1 parent c80fbc2 commit f1bf3ad

File tree

13 files changed

+252
-157
lines changed

13 files changed

+252
-157
lines changed

.changelog/1515.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_tcr_instance: support paypaid arguments
3+
```

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ require (
3535
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.445
3636
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544
3737
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.412
38-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.577
38+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.578
3939
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.553
4040
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.572
4141
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.335
@@ -71,7 +71,7 @@ require (
7171
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tat v1.0.538
7272
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcaplusdb v1.0.199
7373
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcm v1.0.547
74-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.503
74+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.578
7575
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdcpg v1.0.533
7676
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.0.564
7777
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.573

go.sum

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,9 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.573 h1:H2p5
556556
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.573/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
557557
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.576 h1:6L4MeAnCk1NkuKoSfJvNPxqOrXq/HG9FqV3jl6i5t+w=
558558
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.576/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
559-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.577 h1:7ohRB1Dz8gmOG3XTYmPKKhFraB7AR7Innqv4NEYL60Q=
560559
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.577/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
560+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.578 h1:dfSNB1i1dOgGQ/WBAlWax7iLFAIiodDSr9xDIwPNLDM=
561+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.578/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
561562
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.445 h1:Bh7XD0ypNMHYyBOM8hhKsSu+y0VVKUnJVS+YKKhfpGg=
562563
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.445/go.mod h1:jMDD351efCFpT1+KVFbcpu6SbmP4TYmp4qkoCfr63nQ=
563564
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.553 h1:Pl1kYgFhJp0QSoVFSzRsiGk+HfEAkBTQg7+O60tytNA=
@@ -645,6 +646,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcm v1.0.547 h1:6bukohy
645646
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcm v1.0.547/go.mod h1:C7b++Lr8Xh+2KtTUMBjbb+/BrBhfFhAxDMjXzT2GLhY=
646647
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.503 h1:wDJnXddBwMCqYDy4mPRcMZpRD5EOoXjktXSyQQUvpwo=
647648
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.503/go.mod h1:auioaP0mtgitVHdt+NLRN3f87zPsA3M/m+9niqGxKgs=
649+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.578 h1:503H565386+uwlu/D3hO7kbW9wcYe6BWKXzE3Pi3TF8=
650+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.578/go.mod h1:MJ6nlo9xGgxLlWBlizUyxKRFR5lf1mhjBFAwaW7fBYY=
648651
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdcpg v1.0.533 h1:r6HQhmHzPp1oSGhwkNzUzIRlpnpb8Jhtcn1yKhg9ml4=
649652
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdcpg v1.0.533/go.mod h1:5sIIchyV9sXIVAqsD3UWts+qQJ0qoc55sL2WuiY8Ugs=
650653
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.0.268 h1:ez5lvKQVWGQV90BV3m9SeFODaoDbrtkMzw2S0DRMncA=

tencentcloud/extension_tcr.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,8 @@ var RegionIdMap = map[string]string{
5151
"ap-shenzhen-sycft": "77",
5252
"ap-shanghai-adc": "78",
5353
}
54+
55+
const (
56+
REGISTRY_CHARGE_TYPE_POSTPAID = 0
57+
REGISTRY_CHARGE_TYPE_PREPAID = 1
58+
)

tencentcloud/resource_tc_tcr_instance.go

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,25 @@ func resourceTencentCloudTcrInstance() *schema.Resource {
180180
},
181181
},
182182
},
183+
"registry_charge_type": {
184+
Type: schema.TypeInt,
185+
Optional: true,
186+
Default: 1,
187+
ValidateFunc: validateIntegerInRange(1, 2),
188+
Description: "Charge type of instance. 1: postpaid; 2: prepaid. Default is postpaid.",
189+
},
190+
"instance_charge_type_prepaid_period": {
191+
Type: schema.TypeInt,
192+
Optional: true,
193+
ValidateFunc: validateIntegerMin(1),
194+
Description: "Length of time to purchase an instance (in month). Must set when registry_charge_type is prepaid.",
195+
},
196+
"instance_charge_type_prepaid_renew_flag": {
197+
Type: schema.TypeInt,
198+
Optional: true,
199+
ValidateFunc: validateIntegerInRange(1, 3),
200+
Description: "Auto renewal flag. 1: manual renewal, 2: automatic renewal, 3: no renewal and no notification. Must set when registry_charge_type is prepaid.",
201+
},
183202
//Computed values
184203
"status": {
185204
Type: schema.TypeString,
@@ -207,6 +226,11 @@ func resourceTencentCloudTcrInstance() *schema.Resource {
207226
Default: false,
208227
Description: "Indicate to delete the COS bucket which is auto-created with the instance or not.",
209228
},
229+
"expired_at": {
230+
Type: schema.TypeString,
231+
Computed: true,
232+
Description: "Instance expiration time (prepaid).",
233+
},
210234
},
211235
}
212236
}
@@ -245,9 +269,19 @@ func resourceTencentCloudTcrInstanceCreate(d *schema.ResourceData, meta interfac
245269
}
246270
}
247271
}
272+
params := make(map[string]interface{})
273+
if v, ok := d.GetOk("registry_charge_type"); ok {
274+
params["registry_charge_type"] = v.(int)
275+
}
276+
if v, ok := d.GetOk("instance_charge_type_prepaid_period"); ok {
277+
params["instance_charge_type_prepaid_period"] = v.(int)
278+
}
279+
if v, ok := d.GetOk("instance_charge_type_prepaid_renew_flag"); ok {
280+
params["instance_charge_type_prepaid_renew_flag"] = v.(int)
281+
}
248282

249283
outErr = resource.Retry(writeRetryTimeout, func() *resource.RetryError {
250-
instanceId, inErr = tcrService.CreateTCRInstance(ctx, name, insType, map[string]string{})
284+
instanceId, inErr = tcrService.CreateTCRInstance(ctx, name, insType, params)
251285
if inErr != nil {
252286
return retryError(inErr)
253287
}
@@ -406,6 +440,14 @@ func resourceTencentCloudTcrInstanceRead(d *schema.ResourceData, meta interface{
406440
_ = d.Set("public_domain", instance.PublicDomain)
407441
_ = d.Set("internal_end_point", instance.InternalEndpoint)
408442
_ = d.Set("public_status", publicStatus)
443+
_ = d.Set("registry_charge_type", *instance.PayMod+1)
444+
if *instance.PayMod == REGISTRY_CHARGE_TYPE_PREPAID && instance.RenewFlag != nil {
445+
_ = d.Set("instance_charge_type_prepaid_renew_flag", *instance.RenewFlag+1)
446+
}
447+
if *instance.PayMod == REGISTRY_CHARGE_TYPE_PREPAID && instance.ExpiredAt != nil {
448+
_ = d.Set("expired_at", instance.ExpiredAt)
449+
450+
}
409451

410452
request := tcr.NewDescribeSecurityPoliciesRequest()
411453
request.RegistryId = helper.String(d.Id())

tencentcloud/resource_tc_tcr_instance_test.go

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ func init() {
8383
})
8484
}
8585

86-
func TestAccTencentCloudTCRInstance_basic_and_update(t *testing.T) {
86+
func TestAccTencentCloudTcrInstanceResource_basic_and_update(t *testing.T) {
8787
t.Parallel()
8888
resource.Test(t, resource.TestCase{
89-
PreCheck: func() { testAccPreCheck(t) },
89+
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
9090
Providers: testAccProviders,
9191
CheckDestroy: testAccCheckTCRInstanceDestroy,
9292
Steps: []resource.TestStep{
@@ -140,10 +140,38 @@ func TestAccTencentCloudTCRInstance_basic_and_update(t *testing.T) {
140140
})
141141
}
142142

143-
func TestAccTencentCloudTCRInstance_replication(t *testing.T) {
143+
func TestAccTencentCloudTcrInstanceResource_paypaid(t *testing.T) {
144144
t.Parallel()
145145
resource.Test(t, resource.TestCase{
146-
PreCheck: func() { testAccPreCheck(t) },
146+
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
147+
Providers: testAccProviders,
148+
CheckDestroy: testAccCheckTCRInstanceDestroy,
149+
Steps: []resource.TestStep{
150+
{
151+
Config: testAccTCRInstance_paypaid,
152+
Check: resource.ComposeAggregateTestCheckFunc(
153+
resource.TestCheckResourceAttr("tencentcloud_tcr_instance.mytcr_instance_paypaid", "name", "paypaidtcrinstance"),
154+
resource.TestCheckResourceAttr("tencentcloud_tcr_instance.mytcr_instance_paypaid", "instance_type", "basic"),
155+
resource.TestCheckResourceAttr("tencentcloud_tcr_instance.mytcr_instance_paypaid", "tags.test", "test"),
156+
resource.TestCheckResourceAttr("tencentcloud_tcr_instance.mytcr_instance_paypaid", "registry_charge_type", "2"),
157+
resource.TestCheckResourceAttr("tencentcloud_tcr_instance.mytcr_instance_paypaid", "instance_charge_type_prepaid_renew_flag", "1"),
158+
resource.TestCheckResourceAttrSet("tencentcloud_tcr_instance.mytcr_instance_paypaid", "expired_at"),
159+
),
160+
},
161+
{
162+
ResourceName: "tencentcloud_tcr_instance.mytcr_instance_paypaid",
163+
ImportState: true,
164+
ImportStateVerify: true,
165+
ImportStateVerifyIgnore: []string{"delete_bucket", "instance_charge_type_prepaid_period"},
166+
},
167+
},
168+
})
169+
}
170+
171+
func TestAccTencentCloudTcrInstanceResource_replication(t *testing.T) {
172+
t.Parallel()
173+
resource.Test(t, resource.TestCase{
174+
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
147175
Providers: testAccProviders,
148176
CheckDestroy: testAccCheckTCRInstanceDestroy,
149177
Steps: []resource.TestStep{
@@ -171,7 +199,7 @@ func TestAccTencentCloudTCRInstance_replication(t *testing.T) {
171199
})
172200
}
173201

174-
func TestUnitTencentCloudTCRReplicaSet(t *testing.T) {
202+
func TestAccTencentCloudTcrInstanceResource_replica_set(t *testing.T) {
175203

176204
inputs := []interface{}{
177205
map[string]interface{}{
@@ -324,6 +352,19 @@ resource "tencentcloud_tcr_instance" "mytcr_instance" {
324352
}
325353
}`
326354

355+
const testAccTCRInstance_paypaid = `
356+
resource "tencentcloud_tcr_instance" "mytcr_instance_paypaid" {
357+
name = "paypaidtcrinstance"
358+
instance_type = "basic"
359+
delete_bucket = true
360+
registry_charge_type = 2
361+
instance_charge_type_prepaid_period = 1
362+
instance_charge_type_prepaid_renew_flag = 1
363+
tags ={
364+
test = "test"
365+
}
366+
}`
367+
327368
const testAccTCRInstance_replica = `
328369
resource "tencentcloud_tcr_instance" "mytcr_instance" {
329370
name = "tfreplicas"

tencentcloud/service_tencentcloud_tcr.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"log"
77

88
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
9+
"github.com/pkg/errors"
910
sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
1011
tcr "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr/v20190924"
1112
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/connectivity"
@@ -17,7 +18,7 @@ type TCRService struct {
1718
client *connectivity.TencentCloudClient
1819
}
1920

20-
func (me *TCRService) CreateTCRInstance(ctx context.Context, name string, instanceType string, tags map[string]string) (instanceId string, errRet error) {
21+
func (me *TCRService) CreateTCRInstance(ctx context.Context, name string, instanceType string, params map[string]interface{}) (instanceId string, errRet error) {
2122
logId := getLogId(ctx)
2223
request := tcr.NewCreateInstanceRequest()
2324
defer func() {
@@ -28,6 +29,33 @@ func (me *TCRService) CreateTCRInstance(ctx context.Context, name string, instan
2829
request.RegistryName = &name
2930
request.RegistryType = &instanceType
3031

32+
var chargeType, period, renewFlag int
33+
if v, ok := params["registry_charge_type"]; ok {
34+
chargeType = v.(int)
35+
request.RegistryChargeType = helper.IntInt64(chargeType - 1)
36+
}
37+
38+
if v, ok := params["instance_charge_type_prepaid_period"]; ok {
39+
period = v.(int)
40+
}
41+
if v, ok := params["instance_charge_type_prepaid_renew_flag"]; ok {
42+
renewFlag = v.(int)
43+
}
44+
if chargeType == 2 {
45+
if period == 0 || renewFlag == 0 {
46+
errRet = errors.New("Must set instance_charge_type_prepaid_period and instance_charge_type_prepaid_renew_flag when registry_charge_type is postpaid")
47+
return
48+
}
49+
request.RegistryChargePrepaid = &tcr.RegistryChargePrepaid{
50+
Period: helper.IntInt64(period),
51+
RenewFlag: helper.IntInt64(renewFlag - 1),
52+
}
53+
}
54+
55+
var tags map[string]string
56+
if v, ok := params["tags"]; ok {
57+
tags = v.(map[string]string)
58+
}
3159
if len(tags) > 0 {
3260
tagSpec := tcr.TagSpecification{ResourceType: helper.String("instance"), Tags: make([]*tcr.Tag, 0)}
3361
for k, v := range tags {

vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/request.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)