Skip to content

Commit 6e10d86

Browse files
gitmknanonymous
andauthored
Fix/tem unit (#1476)
* feat: add tem_application unit * feat: add environment unit * feat: add app config unit * feat: add log config unit * feat: add workload unit * fix: modify doc * feat: gateway unit * feat: add scale rule unit Co-authored-by: anonymous <anonymous@mail.org>
1 parent 6f82a67 commit 6e10d86

12 files changed

+729
-170
lines changed

tencentcloud/basic_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,8 +864,12 @@ const (
864864

865865
// TEM
866866
const (
867-
defaultEnvironmentId = "en-758oo2ej"
867+
defaultEnvironmentId = "en-85377m6j"
868868
defaultApplicationId = "app-joqr9bd5"
869+
defaultTemVpcId = "vpc-4owdpnwr"
870+
defaultTemSubnetId = "subnet-c1l35990"
871+
defaultLogsetId = "33aaf0ae-6163-411b-a415-9f27450f68db"
872+
defaultTopicId = "88735a07-bea4-4985-8763-e9deb6da4fad"
869873
)
870874

871875
// End of TEM
Lines changed: 89 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
11
package tencentcloud
22

33
import (
4+
"context"
5+
"fmt"
6+
"strings"
47
"testing"
58

69
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
10+
"github.com/hashicorp/terraform-plugin-sdk/terraform"
11+
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
712
)
813

9-
func TestAccTencentCloudNeedFixTemAppConfig_basic(t *testing.T) {
14+
// go test -i; go test -test.run TestAccTencentCloudNeedFixTemAppConfigResource_basic -v
15+
func TestAccTencentCloudNeedFixTemAppConfigResource_basic(t *testing.T) {
1016
t.Parallel()
11-
1217
resource.Test(t, resource.TestCase{
13-
PreCheck: func() { testAccPreCheck(t) },
14-
Providers: testAccProviders,
18+
PreCheck: func() {
19+
testAccPreCheck(t)
20+
},
21+
Providers: testAccProviders,
22+
CheckDestroy: testAccCheckTemAppConfigDestroy,
1523
Steps: []resource.TestStep{
1624
{
1725
Config: testAccTemAppConfig,
1826
Check: resource.ComposeTestCheckFunc(
27+
testAccCheckTemAppConfigExists("tencentcloud_tem_app_config.appConfig"),
1928
resource.TestCheckResourceAttrSet("tencentcloud_tem_app_config.appConfig", "id"),
29+
resource.TestCheckResourceAttr("tencentcloud_tem_app_config.appConfig", "environment_id", defaultEnvironmentId),
30+
resource.TestCheckResourceAttr("tencentcloud_tem_app_config.appConfig", "name", "demo"),
31+
resource.TestCheckResourceAttr("tencentcloud_tem_app_config.appConfig", "config_data.#", "1"),
32+
resource.TestCheckResourceAttr("tencentcloud_tem_app_config.appConfig", "config_data.0.key", "key"),
33+
resource.TestCheckResourceAttr("tencentcloud_tem_app_config.appConfig", "config_data.0.value", "value"),
2034
),
2135
},
2236
{
@@ -28,19 +42,84 @@ func TestAccTencentCloudNeedFixTemAppConfig_basic(t *testing.T) {
2842
})
2943
}
3044

31-
const testAccTemAppConfig = `
45+
func testAccCheckTemAppConfigDestroy(s *terraform.State) error {
46+
logId := getLogId(contextNil)
47+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
48+
service := TemService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn}
49+
for _, rs := range s.RootModule().Resources {
50+
if rs.Type != "tencentcloud_tem_app_config" {
51+
continue
52+
}
53+
idSplit := strings.Split(rs.Primary.ID, FILED_SP)
54+
if len(idSplit) != 2 {
55+
return fmt.Errorf("id is broken,%s", rs.Primary.ID)
56+
}
57+
environmentId := idSplit[0]
58+
name := idSplit[1]
59+
60+
res, err := service.DescribeTemAppConfig(ctx, environmentId, name)
61+
if err != nil {
62+
if sdkErr, ok := err.(*errors.TencentCloudSDKError); ok {
63+
if sdkErr.Code == "InternalError.DescribeConfigDataError" {
64+
return nil
65+
}
66+
}
67+
return err
68+
}
69+
70+
if res != nil {
71+
return fmt.Errorf("tem app config %s still exists", rs.Primary.ID)
72+
}
73+
}
74+
return nil
75+
}
76+
77+
func testAccCheckTemAppConfigExists(r string) resource.TestCheckFunc {
78+
return func(s *terraform.State) error {
79+
logId := getLogId(contextNil)
80+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
81+
82+
rs, ok := s.RootModule().Resources[r]
83+
if !ok {
84+
return fmt.Errorf("resource %s is not found", r)
85+
}
86+
87+
idSplit := strings.Split(rs.Primary.ID, FILED_SP)
88+
if len(idSplit) != 2 {
89+
return fmt.Errorf("id is broken,%s", rs.Primary.ID)
90+
}
91+
environmentId := idSplit[0]
92+
name := idSplit[1]
93+
94+
service := TemService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn}
95+
res, err := service.DescribeTemAppConfig(ctx, environmentId, name)
96+
if err != nil {
97+
return err
98+
}
99+
100+
if res == nil {
101+
return fmt.Errorf("tem app config %s is not found", rs.Primary.ID)
102+
}
103+
104+
return nil
105+
}
106+
}
107+
108+
const testAccTemAppConfigVar = `
109+
variable "environment_id" {
110+
default = "` + defaultEnvironmentId + `"
111+
}
112+
`
113+
114+
const testAccTemAppConfig = testAccTemAppConfigVar + `
32115
33116
resource "tencentcloud_tem_app_config" "appConfig" {
34-
environment_id = "en-o5edaepv"
117+
environment_id = var.environment_id
35118
name = "demo"
36119
config_data {
37120
key = "key"
38121
value = "value"
39122
}
40-
config_data {
41-
key = "key1"
42-
value = "value1"
43-
}
44123
}
45124
46125
`

tencentcloud/resource_tc_tem_application.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ resource "tencentcloud_tem_application" "application" {
1414
repo_server = "ccr.ccs.tencentyun.com"
1515
}
1616
```
17-
Import
18-
19-
tem application can be imported using the id, e.g.
20-
```
21-
$ terraform import tencentcloud_tem_application.application application_id
22-
```
2317
*/
2418
package tencentcloud
2519

@@ -40,9 +34,9 @@ func resourceTencentCloudTemApplication() *schema.Resource {
4034
Create: resourceTencentCloudTemApplicationCreate,
4135
Update: resourceTencentCloudTemApplicationUpdate,
4236
Delete: resourceTencentCloudTemApplicationDelete,
43-
Importer: &schema.ResourceImporter{
44-
State: schema.ImportStatePassthrough,
45-
},
37+
// Importer: &schema.ResourceImporter{
38+
// State: schema.ImportStatePassthrough,
39+
// },
4640
Schema: map[string]*schema.Schema{
4741
"application_name": {
4842
Type: schema.TypeString,

tencentcloud/resource_tc_tem_application_test.go

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,93 @@
11
package tencentcloud
22

33
import (
4+
"context"
5+
"fmt"
46
"testing"
57

68
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
9+
"github.com/hashicorp/terraform-plugin-sdk/terraform"
710
)
811

9-
func TestAccTencentCloudNeedFixTemApplication_basic(t *testing.T) {
12+
// go test -i; go test -test.run TestAccTencentCloudNeedFixTemApplicationResource_basic -v
13+
func TestAccTencentCloudNeedFixTemApplicationResource_basic(t *testing.T) {
1014
t.Parallel()
1115

1216
resource.Test(t, resource.TestCase{
13-
PreCheck: func() { testAccPreCheck(t) },
14-
Providers: testAccProviders,
17+
PreCheck: func() {
18+
testAccPreCheck(t)
19+
},
20+
Providers: testAccProviders,
21+
CheckDestroy: testAccCheckTemApplicationDestroy,
1522
Steps: []resource.TestStep{
1623
{
1724
Config: testAccTemApplication,
1825
Check: resource.ComposeTestCheckFunc(
26+
testAccCheckTemApplicationExists("tencentcloud_tem_application.application"),
1927
resource.TestCheckResourceAttrSet("tencentcloud_tem_application.application", "id"),
28+
resource.TestCheckResourceAttr("tencentcloud_tem_application.application", "application_name", "demo"),
29+
resource.TestCheckResourceAttr("tencentcloud_tem_application.application", "description", "demo for test"),
30+
resource.TestCheckResourceAttr("tencentcloud_tem_application.application", "coding_language", "JAVA"),
31+
resource.TestCheckResourceAttr("tencentcloud_tem_application.application", "use_default_image_service", "0"),
32+
resource.TestCheckResourceAttr("tencentcloud_tem_application.application", "repo_type", "2"),
33+
resource.TestCheckResourceAttr("tencentcloud_tem_application.application", "repo_name", "qcloud/nginx"),
34+
resource.TestCheckResourceAttr("tencentcloud_tem_application.application", "repo_server", "ccr.ccs.tencentyun.com"),
2035
),
2136
},
22-
{
23-
ResourceName: "tencentcloud_tem_application.application",
24-
ImportState: true,
25-
ImportStateVerify: true,
26-
},
37+
// {
38+
// ResourceName: "tencentcloud_tem_application.application",
39+
// ImportState: true,
40+
// ImportStateVerify: true,
41+
// },
2742
},
2843
})
2944
}
3045

46+
func testAccCheckTemApplicationDestroy(s *terraform.State) error {
47+
logId := getLogId(contextNil)
48+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
49+
service := TemService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn}
50+
for _, rs := range s.RootModule().Resources {
51+
if rs.Type != "tencentcloud_tem_application" {
52+
continue
53+
}
54+
55+
res, err := service.DescribeTemApplication(ctx, rs.Primary.ID)
56+
if err != nil {
57+
return err
58+
}
59+
60+
if len(res.Result.Records) > 0 {
61+
return fmt.Errorf("tem application %s still exists", rs.Primary.ID)
62+
}
63+
}
64+
return nil
65+
}
66+
67+
func testAccCheckTemApplicationExists(r string) resource.TestCheckFunc {
68+
return func(s *terraform.State) error {
69+
logId := getLogId(contextNil)
70+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
71+
72+
rs, ok := s.RootModule().Resources[r]
73+
if !ok {
74+
return fmt.Errorf("resource %s is not found", r)
75+
}
76+
77+
service := TemService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn}
78+
res, err := service.DescribeTemApplication(ctx, rs.Primary.ID)
79+
if err != nil {
80+
return err
81+
}
82+
83+
if len(res.Result.Records) < 1 {
84+
return fmt.Errorf("tem application %s is not found", rs.Primary.ID)
85+
}
86+
87+
return nil
88+
}
89+
}
90+
3191
const testAccTemApplication = `
3292
3393
resource "tencentcloud_tem_application" "application" {
Lines changed: 80 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
package tencentcloud
22

33
import (
4+
"context"
5+
"fmt"
46
"testing"
57

68
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
9+
"github.com/hashicorp/terraform-plugin-sdk/terraform"
10+
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
711
)
812

9-
func TestAccTencentCloudNeedFixTemEnvironment_basic(t *testing.T) {
13+
// go test -i; go test -test.run TestAccTencentCloudNeedFixTemEnvironmentResource_basic -v
14+
func TestAccTencentCloudNeedFixTemEnvironmentResource_basic(t *testing.T) {
1015
t.Parallel()
1116

1217
resource.Test(t, resource.TestCase{
13-
PreCheck: func() { testAccPreCheck(t) },
14-
Providers: testAccProviders,
18+
PreCheck: func() {
19+
testAccPreCheck(t)
20+
},
21+
Providers: testAccProviders,
22+
CheckDestroy: testAccCheckTemEnvironmentDestroy,
1523
Steps: []resource.TestStep{
1624
{
1725
Config: testAccTemEnvironment,
1826
Check: resource.ComposeTestCheckFunc(
27+
testAccCheckTemEnvironmentExists("tencentcloud_tem_environment.environment"),
1928
resource.TestCheckResourceAttrSet("tencentcloud_tem_environment.environment", "id"),
29+
resource.TestCheckResourceAttr("tencentcloud_tem_environment.environment", "environment_name", "demo"),
30+
resource.TestCheckResourceAttr("tencentcloud_tem_environment.environment", "description", "demo for test"),
2031
),
2132
},
2233
{
@@ -28,13 +39,73 @@ func TestAccTencentCloudNeedFixTemEnvironment_basic(t *testing.T) {
2839
})
2940
}
3041

31-
const testAccTemEnvironment = `
42+
func testAccCheckTemEnvironmentDestroy(s *terraform.State) error {
43+
logId := getLogId(contextNil)
44+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
45+
service := TemService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn}
46+
for _, rs := range s.RootModule().Resources {
47+
if rs.Type != "tencentcloud_tem_environment" {
48+
continue
49+
}
3250

33-
resource "tencentcloud_tem_environment" "environment" {
34-
environment_name = "demo"
35-
description = "demo for test"
36-
vpc = "vpc-2hfyray3"
37-
subnet_ids = ["subnet-rdkj0agk", "subnet-r1c4pn5m", "subnet-02hcj95c"]
51+
res, err := service.DescribeTemEnvironment(ctx, rs.Primary.ID)
52+
if err != nil {
53+
if sdkErr, ok := err.(*errors.TencentCloudSDKError); ok {
54+
if sdkErr.Code == "ResourceNotFound.VersionNamespaceNotFound" {
55+
return nil
56+
}
57+
}
58+
return err
59+
}
60+
61+
if res.Result != nil {
62+
return fmt.Errorf("tem environment %s still exists", rs.Primary.ID)
63+
}
64+
}
65+
return nil
66+
}
67+
68+
func testAccCheckTemEnvironmentExists(r string) resource.TestCheckFunc {
69+
return func(s *terraform.State) error {
70+
logId := getLogId(contextNil)
71+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
72+
73+
rs, ok := s.RootModule().Resources[r]
74+
if !ok {
75+
return fmt.Errorf("resource %s is not found", r)
76+
}
77+
78+
service := TemService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn}
79+
res, err := service.DescribeTemEnvironment(ctx, rs.Primary.ID)
80+
if err != nil {
81+
return err
82+
}
83+
84+
if res.Result == nil {
85+
return fmt.Errorf("tem environment %s is not found", rs.Primary.ID)
86+
}
87+
88+
return nil
89+
}
3890
}
3991

92+
const testAccTemEnvironmentVar = `
93+
variable "vpc_id" {
94+
default = "` + defaultTemVpcId + `"
95+
}
96+
97+
variable "subnet_id" {
98+
default = "` + defaultTemSubnetId + `"
99+
}
100+
`
101+
102+
const testAccTemEnvironment = testAccTemEnvironmentVar + `
103+
104+
resource "tencentcloud_tem_environment" "environment" {
105+
environment_name = "demo"
106+
description = "demo for test"
107+
vpc = var.vpc_id
108+
subnet_ids = [var.subnet_id]
109+
}
110+
40111
`

0 commit comments

Comments
 (0)