88
99 "github.com/hashicorp/terraform-plugin-sdk/helper/resource"
1010 "github.com/hashicorp/terraform-plugin-sdk/terraform"
11+ sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
1112)
1213
1314func TestAccTencentCloudTCRTagRetentionRuleResource_basic (t * testing.T ) {
@@ -76,6 +77,11 @@ func testAccCheckTCRTagRetentionRuleDestroy(s *terraform.State) error {
7677
7778 rule , err := service .DescribeTcrTagRetentionRuleById (ctx , registryId , namespaceName , & retentionId )
7879 if err != nil {
80+ if ee , ok := err .(* sdkErrors.TencentCloudSDKError ); ok {
81+ if ee .Code == "ResourceNotFound" {
82+ return nil
83+ }
84+ }
7985 return err
8086 }
8187
@@ -110,6 +116,11 @@ func testAccCheckTCRTagRetentionRuleExists(re string) resource.TestCheckFunc {
110116
111117 rule , err := service .DescribeTcrTagRetentionRuleById (ctx , registryId , namespaceName , & retentionId )
112118 if err != nil {
119+ if ee , ok := err .(* sdkErrors.TencentCloudSDKError ); ok {
120+ if ee .Code == "ResourceNotFound" {
121+ return fmt .Errorf ("Tcr Tag Retention Rule not found[ResourceNotFound], Id: %v" , rs .Primary .ID )
122+ }
123+ }
113124 return err
114125 }
115126
@@ -120,10 +131,21 @@ func testAccCheckTCRTagRetentionRuleExists(re string) resource.TestCheckFunc {
120131 }
121132}
122133
123- const testAccTcrTagRetentionRule = defaultTCRInstanceData + `
134+ const testAccTCRInstance_retention = `
135+ resource "tencentcloud_tcr_instance" "mytcr_retention" {
136+ name = "tf-test-tcr-retention"
137+ instance_type = "basic"
138+ delete_bucket = true
139+
140+ tags ={
141+ test = "test"
142+ }
143+ }`
144+
145+ const testAccTcrTagRetentionRule = testAccTCRInstance_retention + `
124146
125147resource "tencentcloud_tcr_namespace" "my_ns" {
126- instance_id = local.tcr_id
148+ instance_id = tencentcloud_tcr_instance.mytcr_retention.id
127149 name = "tf_test_ns_retention"
128150 is_public = true
129151 is_auto_scan = true
@@ -135,7 +157,7 @@ resource "tencentcloud_tcr_namespace" "my_ns" {
135157}
136158
137159resource "tencentcloud_tcr_tag_retention_rule" "my_rule" {
138- registry_id = local.tcr_id
160+ registry_id = tencentcloud_tcr_instance.mytcr_retention.id
139161 namespace_name = tencentcloud_tcr_namespace.my_ns.name
140162 retention_rule {
141163 key = "nDaysSinceLastPush"
@@ -147,10 +169,10 @@ resource "tencentcloud_tcr_tag_retention_rule" "my_rule" {
147169
148170`
149171
150- const testAccTcrTagRetentionRule_update = defaultTCRInstanceData + `
172+ const testAccTcrTagRetentionRule_update = testAccTCRInstance_retention + `
151173
152174resource "tencentcloud_tcr_namespace" "my_ns" {
153- instance_id = local.tcr_id
175+ instance_id = tencentcloud_tcr_instance.mytcr_retention.id
154176 name = "tf_test_ns_retention"
155177 is_public = true
156178 is_auto_scan = true
@@ -162,7 +184,7 @@ resource "tencentcloud_tcr_namespace" "my_ns" {
162184}
163185
164186resource "tencentcloud_tcr_tag_retention_rule" "my_rule" {
165- registry_id = local.tcr_id
187+ registry_id = tencentcloud_tcr_instance.mytcr_retention.id
166188 namespace_name = tencentcloud_tcr_namespace.my_ns.name
167189 retention_rule {
168190 key = "nDaysSinceLastPush"
0 commit comments