Skip to content

Commit 5acf490

Browse files
author
mikatong
committed
support update password
1 parent 3c482ab commit 5acf490

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

tencentcloud/services/tcr/resource_tc_tcr_service_account.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func ResourceTencentCloudTcrServiceAccount() *schema.Resource {
8787
},
8888

8989
"password": {
90+
Optional: true,
9091
Computed: true,
9192
Type: schema.TypeString,
9293
Description: "Password of the service account.",
@@ -201,6 +202,15 @@ func resourceTencentCloudTcrServiceAccountCreate(d *schema.ResourceData, meta in
201202
}
202203
}
203204

205+
service := TCRService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
206+
if v, ok := d.GetOk("password"); ok {
207+
password, err := service.ModifyServiceAccountPassword(ctx, registryId, name, v.(string))
208+
if err != nil {
209+
return err
210+
}
211+
_ = d.Set("password", password)
212+
}
213+
204214
return resourceTencentCloudTcrServiceAccountRead(d, meta)
205215
}
206216

@@ -378,9 +388,9 @@ func resourceTencentCloudTcrServiceAccountUpdate(d *schema.ResourceData, meta in
378388
}
379389
}
380390

381-
if d.HasChange("reset_password") {
382-
if v, ok := d.GetOkExists("reset_password"); ok && v.(bool) {
383-
password, err := service.ModifyServiceAccountPassword(ctx, registryId, name)
391+
if d.HasChange("password") {
392+
if v, ok := d.GetOk("password"); ok {
393+
password, err := service.ModifyServiceAccountPassword(ctx, registryId, name, v.(string))
384394
if err != nil {
385395
return err
386396
}

tencentcloud/services/tcr/resource_tc_tcr_service_account_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,21 @@ func TestAccTencentCloudTcrServiceAccountResource_basic(t *testing.T) {
5656
),
5757
},
5858
{
59-
Config: fmt.Sprintf(testAccTcrServiceAccount_resetPassword, expireTime),
59+
Config: fmt.Sprintf(testAccTcrServiceAccount_updatePassword, expireTime),
6060
PreConfig: func() {
6161
tcacctest.AccStepSetRegion(t, "ap-shanghai")
6262
tcacctest.AccPreCheckCommon(t, tcacctest.ACCOUNT_TYPE_COMMON)
6363
},
6464
Check: resource.ComposeTestCheckFunc(
6565
resource.TestCheckResourceAttrSet("tencentcloud_tcr_service_account.example", "id"),
66-
resource.TestCheckResourceAttrSet("tencentcloud_tcr_service_account.example", "password"),
66+
resource.TestCheckResourceAttr("tencentcloud_tcr_service_account.example", "password", "passwordTest1"),
6767
),
6868
},
6969
{
7070
ResourceName: "tencentcloud_tcr_service_account.example",
7171
ImportState: true,
7272
ImportStateVerify: true,
73-
ImportStateVerifyIgnore: []string{"duration", "password", "reset_password"},
73+
ImportStateVerifyIgnore: []string{"duration", "password"},
7474
},
7575
},
7676
})
@@ -79,7 +79,7 @@ func TestAccTencentCloudTcrServiceAccountResource_basic(t *testing.T) {
7979
const testAccTcrServiceAccount = `
8080
8181
resource "tencentcloud_tcr_instance" "example" {
82-
name = "tf-example-tcr-instance"
82+
name = "tf-example-tcr-instance1"
8383
instance_type = "premium"
8484
delete_bucket = true
8585
tags = {
@@ -116,7 +116,7 @@ resource "tencentcloud_tcr_instance" "example" {
116116
const testAccTcrServiceAccount_Update = `
117117
118118
resource "tencentcloud_tcr_instance" "example" {
119-
name = "tf-example-tcr-instance"
119+
name = "tf-example-tcr-instance1"
120120
instance_type = "premium"
121121
delete_bucket = true
122122
tags = {
@@ -150,10 +150,10 @@ resource "tencentcloud_tcr_instance" "example" {
150150
151151
`
152152

153-
const testAccTcrServiceAccount_resetPassword = `
153+
const testAccTcrServiceAccount_updatePassword = `
154154
155155
resource "tencentcloud_tcr_instance" "example" {
156-
name = "tf-example-tcr-instance"
156+
name = "tf-example-tcr-instance1"
157157
instance_type = "premium"
158158
delete_bucket = true
159159
tags = {
@@ -183,7 +183,7 @@ resource "tencentcloud_tcr_instance" "example" {
183183
tags = {
184184
"createdBy" = "terraform"
185185
}
186-
reset_password = true
186+
password = "passwordTest1"
187187
}
188188
189189
`

tencentcloud/services/tcr/service_tencentcloud_tcr.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,13 +1802,14 @@ func (me *TCRService) DeleteTcrServiceAccountById(ctx context.Context, registryI
18021802
return
18031803
}
18041804

1805-
func (me *TCRService) ModifyServiceAccountPassword(ctx context.Context, registryId string, name string) (password string, errRet error) {
1805+
func (me *TCRService) ModifyServiceAccountPassword(ctx context.Context, registryId string, name string, password string) (passwordResp string, errRet error) {
18061806
logId := tccommon.GetLogId(ctx)
18071807

18081808
request := tcr.NewModifyServiceAccountPasswordRequest()
18091809
request.RegistryId = &registryId
18101810
request.Name = &name
1811-
request.Random = helper.Bool(true)
1811+
request.Random = helper.Bool(false)
1812+
request.Password = helper.String(password)
18121813

18131814
defer func() {
18141815
if errRet != nil {
@@ -1826,7 +1827,7 @@ func (me *TCRService) ModifyServiceAccountPassword(ctx context.Context, registry
18261827
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
18271828

18281829
if response.Response.Password != nil {
1829-
password = *response.Response.Password
1830+
passwordResp = *response.Response.Password
18301831
}
18311832
return
18321833
}

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

Lines changed: 0 additions & 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)