Skip to content

fix(tcr): [123875920]support reset_password #3346

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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/3346.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_tcr_service_account: support reset_password
```
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1107
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.1033
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1148
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1156
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1159
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.1153
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.1111
Expand Down Expand Up @@ -86,7 +86,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tat v1.0.634
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcaplusdb v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcm v1.0.547
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.696
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.1142
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdcpg v1.0.533
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.0.955
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.578
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1154 h1:tc2
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1154/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1156 h1:Uz9TqzwTAtRYuV7gB0Fh2E013qPrUJpS6CeNJ7vlfAI=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1156/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1159 h1:Jl1XE3cY6Bz0lBexvX8z+u2KmDO3tnFxtwHIalM5YS4=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1159/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993 h1:WlPgXldQCxt7qi5Xrc6j6zTrsXWzN5BcOGs7Irq7fwQ=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993/go.mod h1:Z9U8zNtyuyKhjS0698wqsrG/kLx1TQ5CEixXBwVe7xY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip v1.0.860 h1:F3esKBIT3HW9+7Gt8cVgf8X06VdGIczpgLBUECzSEzU=
Expand Down Expand Up @@ -1071,6 +1073,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcm v1.0.547 h1:6bukohy
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcm v1.0.547/go.mod h1:C7b++Lr8Xh+2KtTUMBjbb+/BrBhfFhAxDMjXzT2GLhY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.696 h1:hTfJtxk5WDj84SfOFKg5Mk+DVtSmjVtkyj3gvVKAYkk=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.696/go.mod h1:DgY9Kgh9093fBl2M/vEFGJZwytDIrPQlYoxoT4rE7O0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.1142 h1:X5eKYvyDNA69jXB2AtsLIoa8lwZ3haUZymSHHk4JUiI=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.1142/go.mod h1:GLR0nyoKy8qfcWpfDeA8wgRDY+pqq5UE/SLbB2l9NzU=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcss v1.0.1031 h1:3OgSLiQAfgjQ3kH+lu5WBXRtE6JaZ+FY1Yr+LUv1JEw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcss v1.0.1031/go.mod h1:e5FteF6ukTKsD6wergqmPn/jww3oPwi/QJYtTfYbFuY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdcpg v1.0.533 h1:r6HQhmHzPp1oSGhwkNzUzIRlpnpb8Jhtcn1yKhg9ml4=
Expand Down
17 changes: 17 additions & 0 deletions tencentcloud/services/tcr/resource_tc_tcr_service_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ func ResourceTencentCloudTcrServiceAccount() *schema.Resource {
Description: "Password of the service account.",
},

"reset_password": {
Optional: true,
Type: schema.TypeBool,
Description: "Reset password.",
},

"tags": {
Type: schema.TypeMap,
Optional: true,
Expand Down Expand Up @@ -277,6 +283,8 @@ func resourceTencentCloudTcrServiceAccountUpdate(d *schema.ResourceData, meta in
defer tccommon.InconsistentCheck(d, meta)()

logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
service := TCRService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}

request := tcr.NewModifyServiceAccountRequest()

Expand Down Expand Up @@ -370,6 +378,15 @@ func resourceTencentCloudTcrServiceAccountUpdate(d *schema.ResourceData, meta in
}
}

if d.HasChange("reset_password") {
if v, ok := d.GetOkExists("reset_password"); ok && v.(bool) {
password, err := service.ModifyServiceAccountPassword(ctx, registryId, name)
if err != nil {
return err
}
_ = d.Set("password", password)
}
}
return resourceTencentCloudTcrServiceAccountRead(d, meta)
}

Expand Down
55 changes: 49 additions & 6 deletions tencentcloud/services/tcr/resource_tc_tcr_service_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,22 @@ func TestAccTencentCloudTcrServiceAccountResource_basic(t *testing.T) {
// resource.TestCheckResourceAttr("tencentcloud_tcr_service_account.example", "disable", "true"),
),
},
{
Config: fmt.Sprintf(testAccTcrServiceAccount_resetPassword, expireTime),
PreConfig: func() {
tcacctest.AccStepSetRegion(t, "ap-shanghai")
tcacctest.AccPreCheckCommon(t, tcacctest.ACCOUNT_TYPE_COMMON)
},
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("tencentcloud_tcr_service_account.example", "id"),
resource.TestCheckResourceAttrSet("tencentcloud_tcr_service_account.example", "password"),
),
},
{
ResourceName: "tencentcloud_tcr_service_account.example",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"duration", "password"},
ImportStateVerifyIgnore: []string{"duration", "password", "reset_password"},
},
},
})
Expand All @@ -83,9 +94,6 @@ resource "tencentcloud_tcr_instance" "example" {
is_auto_scan = true
is_prevent_vul = true
severity = "medium"
cve_whitelist_items {
cve_id = "tf_example_cve_id"
}
}

resource "tencentcloud_tcr_service_account" "example" {
Expand Down Expand Up @@ -123,9 +131,43 @@ resource "tencentcloud_tcr_instance" "example" {
is_auto_scan = true
is_prevent_vul = true
severity = "medium"
cve_whitelist_items {
cve_id = "tf_example_cve_id"
}

resource "tencentcloud_tcr_service_account" "example" {
registry_id = tencentcloud_tcr_instance.example.id
name = "tf_example_account"
permissions {
resource = tencentcloud_tcr_namespace.example.name
actions = ["tcr:PushRepository"]
}
description = "CHANGED tf example for tcr service account"
expires_at = %d
disable = false
tags = {
"createdBy" = "terraform"
}
}

`

const testAccTcrServiceAccount_resetPassword = `

resource "tencentcloud_tcr_instance" "example" {
name = "tf-example-tcr-instance"
instance_type = "premium"
delete_bucket = true
tags = {
"createdBy" = "terraform"
}
}

resource "tencentcloud_tcr_namespace" "example" {
instance_id = tencentcloud_tcr_instance.example.id
name = "tf_test_tcr_namespace"
is_public = true
is_auto_scan = true
is_prevent_vul = true
severity = "medium"
}

resource "tencentcloud_tcr_service_account" "example" {
Expand All @@ -141,6 +183,7 @@ resource "tencentcloud_tcr_instance" "example" {
tags = {
"createdBy" = "terraform"
}
reset_password = true
}

`
29 changes: 29 additions & 0 deletions tencentcloud/services/tcr/service_tencentcloud_tcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -1801,3 +1801,32 @@ func (me *TCRService) DeleteTcrServiceAccountById(ctx context.Context, registryI

return
}

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

request := tcr.NewModifyServiceAccountPasswordRequest()
request.RegistryId = &registryId
request.Name = &name
request.Random = helper.Bool(true)

defer func() {
if errRet != nil {
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error())
}
}()

ratelimit.Check(request.GetAction())

response, err := me.client.UseTCRClient().ModifyServiceAccountPassword(request)
if err != nil {
errRet = err
return
}
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())

if response.Response.Password != nil {
password = *response.Response.Password
}
return
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading