Skip to content

Commit

Permalink
feat(tem): add reputation field (#2220)
Browse files Browse the repository at this point in the history
* feat(tem): add reputation field

* fix test
  • Loading branch information
yfodil authored Nov 10, 2023
1 parent 9245633 commit 0d6c26b
Show file tree
Hide file tree
Showing 6 changed files with 466 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/resources/tem_domain.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ In addition to all above arguments, the following attributes are exported:

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

- `reputation` - The domain's reputation.
- `status` - The status of the domain's reputation.
- `score` - A range from 0 to 100 that determines your domain's reputation score.
- `scored_at` - The time and date the score was calculated.
- `previous_score` - The previously-calculated domain's reputation score.
- `previous_scored_at` - The time and date the previous reputation score was calculated.

## Import

Domains can be imported using the `{region}/{id}`, e.g.
Expand Down
28 changes: 28 additions & 0 deletions scaleway/data_source_tem_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,31 @@ func TestAccScalewayDataSourceTemDomain_Basic(t *testing.T) {
},
})
}

func TestAccScalewayDataSourceTemDomain_Reputation(t *testing.T) {
tt := NewTestTools(t)
defer tt.Cleanup()

domainName := "test.scaleway-terraform.com"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: tt.ProviderFactories,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(`
data "scaleway_tem_domain" "test" {
name = "%s"
}
`, domainName),
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewayTemDomainExists(tt, "data.scaleway_tem_domain.test"),
resource.TestCheckResourceAttr("data.scaleway_tem_domain.test", "name", domainName),
resource.TestCheckResourceAttrSet("data.scaleway_tem_domain.test", "reputation.0.status"),
resource.TestCheckResourceAttrSet("data.scaleway_tem_domain.test", "reputation.0.score"),
resource.TestCheckResourceAttrSet("data.scaleway_tem_domain.test", "reputation.0.scored_at"),
),
},
},
})
}
15 changes: 15 additions & 0 deletions scaleway/helpers_tem.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,18 @@ func waitForTemDomain(ctx context.Context, api *tem.API, region scw.Region, id s

return domain, err
}

func flattenDomainReputation(reputation *tem.DomainReputation) interface{} {
if reputation == nil {
return nil
}
return []map[string]interface{}{
{
"status": reputation.Status.String(),
"score": reputation.Score,
"scored_at": flattenTime(reputation.ScoredAt),
"previous_score": flattenUint32Ptr(reputation.PreviousScore),
"previous_scored_at": flattenTime(reputation.PreviousScoredAt),
},
}
}
35 changes: 35 additions & 0 deletions scaleway/resource_tem_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,40 @@ func resourceScalewayTemDomain() *schema.Resource {
Computed: true,
Description: "The Scaleway's blackhole MX server to use",
},
"reputation": {
Type: schema.TypeList,
Computed: true,
Description: "The domain's reputation",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"status": {
Type: schema.TypeString,
Computed: true,
Description: "Status of the domain's reputation",
},
"score": {
Type: schema.TypeInt,
Computed: true,
Description: "A range from 0 to 100 that determines your domain's reputation score",
},
"scored_at": {
Type: schema.TypeString,
Computed: true,
Description: "Time and date the score was calculated",
},
"previous_score": {
Type: schema.TypeInt,
Computed: true,
Description: "The previously-calculated domain's reputation score",
},
"previous_scored_at": {
Type: schema.TypeString,
Computed: true,
Description: "Time and date the previous reputation score was calculated",
},
},
},
},
"region": regionSchema(),
"project_id": projectIDSchema(),
},
Expand Down Expand Up @@ -182,6 +216,7 @@ func resourceScalewayTemDomainRead(ctx context.Context, d *schema.ResourceData,
_ = d.Set("smtps_port", tem.SMTPSPort)
_ = d.Set("smtps_port_alternative", tem.SMTPSPortAlternative)
_ = d.Set("mx_blackhole", tem.MXBlackhole)
_ = d.Set("reputation", flattenDomainReputation(domain.Reputation))
_ = d.Set("region", string(region))
_ = d.Set("project_id", domain.ProjectID)

Expand Down
4 changes: 4 additions & 0 deletions scaleway/resource_tem_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func testSweepTemDomain(_ string) error {
}

for _, ns := range listDomains.Domains {
if ns.Name == "test.scaleway-terraform.com" {
l.Debugf("sweeper: skipping deletion of domain %s", ns.Name)
continue
}
_, err := temAPI.RevokeDomain(&tem.RevokeDomainRequest{
DomainID: ns.ID,
Region: region,
Expand Down
Loading

0 comments on commit 0d6c26b

Please sign in to comment.