Skip to content

Commit 0d6c26b

Browse files
authored
feat(tem): add reputation field (#2220)
* feat(tem): add reputation field * fix test
1 parent 9245633 commit 0d6c26b

File tree

6 files changed

+466
-0
lines changed

6 files changed

+466
-0
lines changed

docs/resources/tem_domain.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ In addition to all above arguments, the following attributes are exported:
103103

104104
- `mx_blackhole` - The Scaleway's blackhole MX server to use if you do not have one.
105105

106+
- `reputation` - The domain's reputation.
107+
- `status` - The status of the domain's reputation.
108+
- `score` - A range from 0 to 100 that determines your domain's reputation score.
109+
- `scored_at` - The time and date the score was calculated.
110+
- `previous_score` - The previously-calculated domain's reputation score.
111+
- `previous_scored_at` - The time and date the previous reputation score was calculated.
112+
106113
## Import
107114

108115
Domains can be imported using the `{region}/{id}`, e.g.

scaleway/data_source_tem_domain_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,31 @@ func TestAccScalewayDataSourceTemDomain_Basic(t *testing.T) {
4444
},
4545
})
4646
}
47+
48+
func TestAccScalewayDataSourceTemDomain_Reputation(t *testing.T) {
49+
tt := NewTestTools(t)
50+
defer tt.Cleanup()
51+
52+
domainName := "test.scaleway-terraform.com"
53+
54+
resource.ParallelTest(t, resource.TestCase{
55+
PreCheck: func() { testAccPreCheck(t) },
56+
ProviderFactories: tt.ProviderFactories,
57+
Steps: []resource.TestStep{
58+
{
59+
Config: fmt.Sprintf(`
60+
data "scaleway_tem_domain" "test" {
61+
name = "%s"
62+
}
63+
`, domainName),
64+
Check: resource.ComposeTestCheckFunc(
65+
testAccCheckScalewayTemDomainExists(tt, "data.scaleway_tem_domain.test"),
66+
resource.TestCheckResourceAttr("data.scaleway_tem_domain.test", "name", domainName),
67+
resource.TestCheckResourceAttrSet("data.scaleway_tem_domain.test", "reputation.0.status"),
68+
resource.TestCheckResourceAttrSet("data.scaleway_tem_domain.test", "reputation.0.score"),
69+
resource.TestCheckResourceAttrSet("data.scaleway_tem_domain.test", "reputation.0.scored_at"),
70+
),
71+
},
72+
},
73+
})
74+
}

scaleway/helpers_tem.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,18 @@ func waitForTemDomain(ctx context.Context, api *tem.API, region scw.Region, id s
5353

5454
return domain, err
5555
}
56+
57+
func flattenDomainReputation(reputation *tem.DomainReputation) interface{} {
58+
if reputation == nil {
59+
return nil
60+
}
61+
return []map[string]interface{}{
62+
{
63+
"status": reputation.Status.String(),
64+
"score": reputation.Score,
65+
"scored_at": flattenTime(reputation.ScoredAt),
66+
"previous_score": flattenUint32Ptr(reputation.PreviousScore),
67+
"previous_scored_at": flattenTime(reputation.PreviousScoredAt),
68+
},
69+
}
70+
}

scaleway/resource_tem_domain.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,40 @@ func resourceScalewayTemDomain() *schema.Resource {
120120
Computed: true,
121121
Description: "The Scaleway's blackhole MX server to use",
122122
},
123+
"reputation": {
124+
Type: schema.TypeList,
125+
Computed: true,
126+
Description: "The domain's reputation",
127+
Elem: &schema.Resource{
128+
Schema: map[string]*schema.Schema{
129+
"status": {
130+
Type: schema.TypeString,
131+
Computed: true,
132+
Description: "Status of the domain's reputation",
133+
},
134+
"score": {
135+
Type: schema.TypeInt,
136+
Computed: true,
137+
Description: "A range from 0 to 100 that determines your domain's reputation score",
138+
},
139+
"scored_at": {
140+
Type: schema.TypeString,
141+
Computed: true,
142+
Description: "Time and date the score was calculated",
143+
},
144+
"previous_score": {
145+
Type: schema.TypeInt,
146+
Computed: true,
147+
Description: "The previously-calculated domain's reputation score",
148+
},
149+
"previous_scored_at": {
150+
Type: schema.TypeString,
151+
Computed: true,
152+
Description: "Time and date the previous reputation score was calculated",
153+
},
154+
},
155+
},
156+
},
123157
"region": regionSchema(),
124158
"project_id": projectIDSchema(),
125159
},
@@ -182,6 +216,7 @@ func resourceScalewayTemDomainRead(ctx context.Context, d *schema.ResourceData,
182216
_ = d.Set("smtps_port", tem.SMTPSPort)
183217
_ = d.Set("smtps_port_alternative", tem.SMTPSPortAlternative)
184218
_ = d.Set("mx_blackhole", tem.MXBlackhole)
219+
_ = d.Set("reputation", flattenDomainReputation(domain.Reputation))
185220
_ = d.Set("region", string(region))
186221
_ = d.Set("project_id", domain.ProjectID)
187222

scaleway/resource_tem_domain_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ func testSweepTemDomain(_ string) error {
3030
}
3131

3232
for _, ns := range listDomains.Domains {
33+
if ns.Name == "test.scaleway-terraform.com" {
34+
l.Debugf("sweeper: skipping deletion of domain %s", ns.Name)
35+
continue
36+
}
3337
_, err := temAPI.RevokeDomain(&tem.RevokeDomainRequest{
3438
DomainID: ns.ID,
3539
Region: region,

0 commit comments

Comments
 (0)