Skip to content

Commit 7f6cad7

Browse files
committed
feat: supprot ses
1 parent 1c5a3ed commit 7f6cad7

File tree

57 files changed

+8567
-298
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+8567
-298
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ require (
4242
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.693
4343
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544
4444
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.711
45-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.737
45+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.743
4646
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624
4747
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.589
4848
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.692
@@ -72,7 +72,7 @@ require (
7272
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis v1.0.657
7373
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/rum v1.0.542
7474
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.729
75-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ses v1.0.529
75+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ses v1.0.743
7676
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms v1.0.486
7777
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sqlserver v1.0.689
7878
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl v1.0.737

go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,12 +879,15 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.731 h1:CEVw
879879
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.731/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
880880
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.732 h1:19TNf4ATZQLFDSKNsJ+FE86rc2HlqkFeIO6wNw2Hj6g=
881881
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.732/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
882+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.734/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
882883
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.735 h1:LJF4eHQdBd5fvjoIGrgB19knAZ98besEzskr0uyypLQ=
883884
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.735/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
884885
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.736 h1:kDxUSuxipDOYAgssgXVf33WT2g6UyY+67yVMsVHPGiU=
885886
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.736/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
886887
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.737 h1:Y/mD9PJbMkjzJiuZsJnzUk31OPCXvch7WSFbs9kKRyw=
887888
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.737/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
889+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.743 h1:P6Pql3W1aEtHK4l2W8L1ExcZ0pA/mlgr1c6K6ROkSCs=
890+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.743/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
888891
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624 h1:nEZqsoqt1pEoaP9JjkHQy3/H00suCfzlHW1qOm2nYD8=
889892
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624/go.mod h1:+TXSVyeKwt1IhZRqKPbTREteBcP+K07Q846/ilNzLWA=
890893
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.589 h1:LZihgirMH0vsaGScYexxwY0fTss9vHaSZs/YOQUVESg=
@@ -953,6 +956,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.729 h1:UWTpLpN
953956
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.729/go.mod h1:P5cLcaPdmOiRhv79OAvAKf+9JTg/64N7ZxwZHBW2mZA=
954957
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ses v1.0.529 h1:NezuBQEG7ihXbwueREo4qavBAo6ZcHuWGZt1dR+VdKc=
955958
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ses v1.0.529/go.mod h1:Xfmf4Rq4J2ukz6NoEwpADQS5ws3By3KDPemCQeeMF+M=
959+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ses v1.0.743 h1:loQWl2qSlclwPrgAyvkIODDXbwy3ZPynAxiMf+TJdjY=
960+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ses v1.0.743/go.mod h1:oqFIxpm3Pu3cT9qAALFw2VqcC4g/tVyWGOkjVkpJakA=
956961
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms v1.0.486 h1:eHLaL+hl5X5f8Apuf2SGVclO3MRev/E3AfA/0aZQGUA=
957962
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms v1.0.486/go.mod h1:MSsho0YlAsoPCOMqdBfwqGd/SMQ0FTGh0a6emBy2X+g=
958963
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sqlserver v1.0.689 h1:SWmtQo+FO+QneHfwcl7u/4YnSwgxVjXNyJMn9+WlzmI=
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/*
2+
Use this data source to query detailed information of ses black_email_address
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_ses_black_email_address" "black_email_address" {
8+
start_date = "2020-09-22"
9+
end_date = "2020-09-23"
10+
email_address = "xxx@mail.qcloud.com"
11+
task_id = "7000"
12+
}
13+
```
14+
*/
15+
package tencentcloud
16+
17+
import (
18+
"context"
19+
20+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
21+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
22+
ses "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ses/v20201002"
23+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
24+
)
25+
26+
func dataSourceTencentCloudSesBlackEmailAddress() *schema.Resource {
27+
return &schema.Resource{
28+
Read: dataSourceTencentCloudSesBlackEmailAddressRead,
29+
Schema: map[string]*schema.Schema{
30+
"start_date": {
31+
Required: true,
32+
Type: schema.TypeString,
33+
Description: "Start date in the format of `YYYY-MM-DD`.",
34+
},
35+
36+
"end_date": {
37+
Required: true,
38+
Type: schema.TypeString,
39+
Description: "End date in the format of `YYYY-MM-DD`.",
40+
},
41+
42+
"email_address": {
43+
Optional: true,
44+
Type: schema.TypeString,
45+
Description: "You can specify an email address to query.",
46+
},
47+
48+
"task_id": {
49+
Optional: true,
50+
Type: schema.TypeString,
51+
Description: "You can specify a task ID to query.",
52+
},
53+
54+
"black_list": {
55+
Computed: true,
56+
Type: schema.TypeList,
57+
Description: "List of blocklisted addresses.",
58+
Elem: &schema.Resource{
59+
Schema: map[string]*schema.Schema{
60+
"bounce_time": {
61+
Type: schema.TypeString,
62+
Computed: true,
63+
Description: "Time when the email address is blocklisted.",
64+
},
65+
"email_address": {
66+
Type: schema.TypeString,
67+
Computed: true,
68+
Description: "Blocklisted email address.",
69+
},
70+
},
71+
},
72+
},
73+
74+
"result_output_file": {
75+
Type: schema.TypeString,
76+
Optional: true,
77+
Description: "Used to save results.",
78+
},
79+
},
80+
}
81+
}
82+
83+
func dataSourceTencentCloudSesBlackEmailAddressRead(d *schema.ResourceData, meta interface{}) error {
84+
defer logElapsed("data_source.tencentcloud_ses_black_email_address.read")()
85+
defer inconsistentCheck(d, meta)()
86+
87+
logId := getLogId(contextNil)
88+
89+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
90+
91+
paramMap := make(map[string]interface{})
92+
if v, ok := d.GetOk("start_date"); ok {
93+
paramMap["StartDate"] = helper.String(v.(string))
94+
}
95+
96+
if v, ok := d.GetOk("end_date"); ok {
97+
paramMap["EndDate"] = helper.String(v.(string))
98+
}
99+
100+
if v, ok := d.GetOk("email_address"); ok {
101+
paramMap["EmailAddress"] = helper.String(v.(string))
102+
}
103+
104+
if v, ok := d.GetOk("task_id"); ok {
105+
paramMap["TaskID"] = helper.String(v.(string))
106+
}
107+
108+
service := SesService{client: meta.(*TencentCloudClient).apiV3Conn}
109+
110+
var blackList []*ses.BlackEmailAddress
111+
112+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
113+
result, e := service.DescribeSesBlackEmailAddressByFilter(ctx, paramMap)
114+
if e != nil {
115+
return retryError(e)
116+
}
117+
blackList = result
118+
return nil
119+
})
120+
if err != nil {
121+
return err
122+
}
123+
124+
ids := make([]string, 0, len(blackList))
125+
tmpList := make([]map[string]interface{}, 0, len(blackList))
126+
127+
if blackList != nil {
128+
for _, blackEmailAddress := range blackList {
129+
blackEmailAddressMap := map[string]interface{}{}
130+
131+
if blackEmailAddress.BounceTime != nil {
132+
blackEmailAddressMap["bounce_time"] = blackEmailAddress.BounceTime
133+
}
134+
135+
if blackEmailAddress.EmailAddress != nil {
136+
blackEmailAddressMap["email_address"] = blackEmailAddress.EmailAddress
137+
}
138+
139+
ids = append(ids, *blackEmailAddress.EmailAddress)
140+
tmpList = append(tmpList, blackEmailAddressMap)
141+
}
142+
143+
_ = d.Set("black_list", tmpList)
144+
}
145+
146+
d.SetId(helper.DataResourceIdsHash(ids))
147+
output, ok := d.GetOk("result_output_file")
148+
if ok && output.(string) != "" {
149+
if e := writeToFile(output.(string), tmpList); e != nil {
150+
return e
151+
}
152+
}
153+
return nil
154+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
// go test -test.run TestAccTencentCloudSesBlackEmailAddressDataSource_basic -v
10+
func TestAccTencentCloudSesBlackEmailAddressDataSource_basic(t *testing.T) {
11+
t.Parallel()
12+
resource.Test(t, resource.TestCase{
13+
PreCheck: func() {
14+
testAccStepSetRegion(t, "ap-hongkong")
15+
testAccPreCheckBusiness(t, ACCOUNT_TYPE_SES)
16+
},
17+
Providers: testAccProviders,
18+
Steps: []resource.TestStep{
19+
{
20+
Config: testAccSesBlackEmailAddressDataSource,
21+
Check: resource.ComposeTestCheckFunc(
22+
testAccCheckTencentCloudDataSourceID("data.tencentcloud_ses_black_email_address.black_email_address"),
23+
resource.TestCheckResourceAttrSet("data.tencentcloud_ses_black_email_address.black_email_address", "black_list.#"),
24+
resource.TestCheckResourceAttrSet("data.tencentcloud_ses_black_email_address.black_email_address", "black_list.0.bounce_time"),
25+
resource.TestCheckResourceAttrSet("data.tencentcloud_ses_black_email_address.black_email_address", "black_list.0.email_address"),
26+
),
27+
},
28+
},
29+
})
30+
}
31+
32+
const testAccSesBlackEmailAddressDataSource = `
33+
34+
data "tencentcloud_ses_black_email_address" "black_email_address" {
35+
start_date = "2020-09-22"
36+
end_date = "2023-09-23"
37+
email_address = "terraform-tf@gmail.com"
38+
}
39+
40+
`
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/*
2+
Use this data source to query detailed information of ses email_identities
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_ses_email_identities" "email_identities" {
8+
}
9+
```
10+
*/
11+
package tencentcloud
12+
13+
import (
14+
"context"
15+
16+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
17+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
18+
ses "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ses/v20201002"
19+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
20+
)
21+
22+
func dataSourceTencentCloudSesEmailIdentities() *schema.Resource {
23+
return &schema.Resource{
24+
Read: dataSourceTencentCloudSesEmailIdentitiesRead,
25+
Schema: map[string]*schema.Schema{
26+
"email_identities": {
27+
Computed: true,
28+
Type: schema.TypeList,
29+
Description: "Sending domain name list.",
30+
Elem: &schema.Resource{
31+
Schema: map[string]*schema.Schema{
32+
"identity_name": {
33+
Type: schema.TypeString,
34+
Computed: true,
35+
Description: "Sending domain name.",
36+
},
37+
"identity_type": {
38+
Type: schema.TypeString,
39+
Computed: true,
40+
Description: "Authentication type, fixed as DOMAIN.",
41+
},
42+
"sending_enabled": {
43+
Type: schema.TypeBool,
44+
Computed: true,
45+
Description: "Is it verified.",
46+
},
47+
"current_reputation_level": {
48+
Type: schema.TypeInt,
49+
Computed: true,
50+
Description: "Current credit rating.",
51+
},
52+
"daily_quota": {
53+
Type: schema.TypeInt,
54+
Computed: true,
55+
Description: "Highest number of letters of the day.",
56+
},
57+
},
58+
},
59+
},
60+
61+
"max_reputation_level": {
62+
Computed: true,
63+
Type: schema.TypeInt,
64+
Description: "Maximum credit rating.",
65+
},
66+
67+
"max_daily_quota": {
68+
Computed: true,
69+
Type: schema.TypeInt,
70+
Description: "Maximum daily sending volume for a single domain name.",
71+
},
72+
73+
"result_output_file": {
74+
Type: schema.TypeString,
75+
Optional: true,
76+
Description: "Used to save results.",
77+
},
78+
},
79+
}
80+
}
81+
82+
func dataSourceTencentCloudSesEmailIdentitiesRead(d *schema.ResourceData, meta interface{}) error {
83+
defer logElapsed("data_source.tencentcloud_ses_email_identities.read")()
84+
defer inconsistentCheck(d, meta)()
85+
86+
logId := getLogId(contextNil)
87+
88+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
89+
90+
service := SesService{client: meta.(*TencentCloudClient).apiV3Conn}
91+
var emailIdentities *ses.ListEmailIdentitiesResponseParams
92+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
93+
result, e := service.DescribeSesEmailIdentitiesByFilter(ctx)
94+
if e != nil {
95+
return retryError(e)
96+
}
97+
emailIdentities = result
98+
return nil
99+
})
100+
if err != nil {
101+
return err
102+
}
103+
104+
ids := make([]string, 0, len(emailIdentities.EmailIdentities))
105+
tmpList := make([]map[string]interface{}, 0, len(emailIdentities.EmailIdentities))
106+
107+
if emailIdentities.EmailIdentities != nil {
108+
for _, emailIdentity := range emailIdentities.EmailIdentities {
109+
emailIdentityMap := map[string]interface{}{}
110+
111+
if emailIdentity.IdentityName != nil {
112+
emailIdentityMap["identity_name"] = emailIdentity.IdentityName
113+
}
114+
115+
if emailIdentity.IdentityType != nil {
116+
emailIdentityMap["identity_type"] = emailIdentity.IdentityType
117+
}
118+
119+
if emailIdentity.SendingEnabled != nil {
120+
emailIdentityMap["sending_enabled"] = emailIdentity.SendingEnabled
121+
}
122+
123+
if emailIdentity.CurrentReputationLevel != nil {
124+
emailIdentityMap["current_reputation_level"] = emailIdentity.CurrentReputationLevel
125+
}
126+
127+
if emailIdentity.DailyQuota != nil {
128+
emailIdentityMap["daily_quota"] = emailIdentity.DailyQuota
129+
}
130+
131+
ids = append(ids, *emailIdentity.IdentityName)
132+
tmpList = append(tmpList, emailIdentityMap)
133+
}
134+
135+
_ = d.Set("email_identities", tmpList)
136+
}
137+
138+
if emailIdentities.MaxReputationLevel != nil {
139+
_ = d.Set("max_reputation_level", emailIdentities.MaxReputationLevel)
140+
}
141+
142+
if emailIdentities.MaxDailyQuota != nil {
143+
_ = d.Set("max_daily_quota", emailIdentities.MaxDailyQuota)
144+
}
145+
146+
d.SetId(helper.DataResourceIdsHash(ids))
147+
output, ok := d.GetOk("result_output_file")
148+
if ok && output.(string) != "" {
149+
if e := writeToFile(output.(string), d); e != nil {
150+
return e
151+
}
152+
}
153+
return nil
154+
}

0 commit comments

Comments
 (0)