Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions docs/resources/cdn_statistic_subscription_task.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
subcategory: "Content Delivery Network (CDN)"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_cdn_statistic_subscription_task"
description: |-
Manages a CDN statistic subscription task resource within HuaweiCloud.
---

# huaweicloud_cdn_statistic_subscription_task

Manages a CDN statistic subscription task resource within HuaweiCloud.

## Example Usage

```hcl
variable "task_name" {}

resource "huaweicloud_cdn_statistic_subscription_task" "test" {
name = var.task_name
period_type = 0
emails = "[email protected],[email protected]"
domain_name = "www.example.com,www.example2.com"
report_type = "0,1,2,3,4,5"
}
```

## Argument Reference

The following arguments are supported:

* `name` - (Required, String) Specifies the name of the subscription task.
The name can contain word characters, hyphens, and Chinese characters, with a maximum length of 32 characters.

* `period_type` - (Required, Int) Specifies the type of the subscription task.
The valid values are as follows:
+ **0**: Daily report
+ **1**: Weekly report
+ **2**: Monthly report

* `emails` - (Required, String) Specifies the email addresses to receive the operation reports.
Multiple email addresses are separated by commas (,).

* `domain_name` - (Required, String) Specifies the list of domain names to subscribe.
Multiple domain names are separated by commas (,).
If set to **all**, all domain names under the account will be subscribed.

* `report_type` - (Required, String) Specifies the type of the operation report.
Multiple report types are separated by commas (,).
The valid values are as follows:
+ **0**: Access area distribution
+ **1**: Country distribution
+ **2**: Carrier distribution
+ **3**: Domain ranking (by traffic)
+ **4**: Popular URLs (by traffic)
+ **5**: Popular URLs (by request count)
+ **6**: Popular Referer (by traffic)
+ **7**: Popular Referer (by request count)
+ **10**: Origin popular URLs (by traffic)
+ **11**: Origin popular URLs (by request count)
+ **13**: Popular UA (by traffic)
+ **14**: Popular UA (by request count)

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The resource ID.

* `create_time` - The creation time of the subscription task, in RFC3339 format.

* `update_time` - The last update time of the subscription task, in RFC3339 format.

## Import

The subscription task can be imported using the `id` or `name`, e.g.

```bash
$ terraform import huaweicloud_cdn_statistic_subscription_task.test <id>
```

or

```bash
$ terraform import huaweicloud_cdn_statistic_subscription_task.test <name>
```
1 change: 1 addition & 0 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2624,6 +2624,7 @@ func Provider() *schema.Provider {
"huaweicloud_cdn_domain_template": cdn.ResourceDomainTemplate(),
"huaweicloud_cdn_rule_engine_rule": cdn.ResourceRuleEngineRule(),
"huaweicloud_cdn_statistic_configuration": cdn.ResourceStatisticConfiguration(),
"huaweicloud_cdn_statistic_subscription_task": cdn.ResourceStatisticSubscriptionTask(),

"huaweicloud_ces_alarmrule": ces.ResourceAlarmRule(),
"huaweicloud_ces_alarm_template": ces.ResourceCesAlarmTemplate(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package cdn

import (
"errors"
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/cdn"
)

func getStatisticSubscriptionTaskResourceFunc(cfg *config.Config, state *terraform.ResourceState) (interface{}, error) {
client, err := cfg.NewServiceClient("cdn", "")
if err != nil {
return nil, fmt.Errorf("error creating CDN client: %s", err)
}

return cdn.GetStatisticSubscriptionTaskById(client, state.Primary.ID)
}

func TestAccStatisticSubscriptionTask_basic(t *testing.T) {
var (
obj interface{}

rName = "huaweicloud_cdn_statistic_subscription_task.test"
rc = acceptance.InitResourceCheck(rName, &obj, getStatisticSubscriptionTaskResourceFunc)

name = acceptance.RandomAccResourceNameWithDash()
updateName = acceptance.RandomAccResourceNameWithDash()
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckCdnDomainName(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccStatisticSubscriptionTask_basic_step1(name),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(rName, "name", name),
resource.TestCheckResourceAttr(rName, "period_type", "0"),
resource.TestCheckResourceAttrSet(rName, "emails"),
resource.TestCheckResourceAttrSet(rName, "domain_name"),
resource.TestCheckResourceAttrSet(rName, "report_type"),
resource.TestMatchResourceAttr(rName, "create_time",
regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}?(Z|([+-]\d{2}:\d{2}))$`)),
),
},
{
Config: testAccStatisticSubscriptionTask_basic_step2(updateName),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(rName, "name", updateName),
resource.TestCheckResourceAttr(rName, "period_type", "1"),
resource.TestCheckResourceAttrSet(rName, "emails"),
resource.TestCheckResourceAttrSet(rName, "domain_name"),
resource.TestCheckResourceAttrSet(rName, "report_type"),
resource.TestMatchResourceAttr(rName, "create_time",
regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}?(Z|([+-]\d{2}:\d{2}))$`)),
resource.TestMatchResourceAttr(rName, "update_time",
regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}?(Z|([+-]\d{2}:\d{2}))$`)),
),
},
{
ResourceName: rName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"emails",
},
},
{
ResourceName: rName,
ImportState: true,
ImportStateVerify: true,
ImportStateIdFunc: testStatisticSubscriptionTaskImportStateWithName(rName),
ImportStateVerifyIgnore: []string{
"emails",
},
},
},
})
}

func testStatisticSubscriptionTaskImportStateWithName(name string) resource.ImportStateIdFunc {
return func(s *terraform.State) (string, error) {
rs, ok := s.RootModule().Resources[name]
if !ok {
return "", fmt.Errorf("resource (%s) not found", name)
}

taskName := rs.Primary.Attributes["name"]
if taskName == "" {
return "", errors.New("the subscription task name is missing, want '<name>'")
}
return taskName, nil
}
}

func testAccStatisticSubscriptionTask_basic_step1(name string) string {
return fmt.Sprintf(`
resource "huaweicloud_cdn_statistic_subscription_task" "test" {
name = "%[1]s"
period_type = 0
emails = "[email protected]"
domain_name = "%[2]s"
report_type = "0,1,2"
}
`, name, acceptance.HW_CDN_DOMAIN_NAME)
}

func testAccStatisticSubscriptionTask_basic_step2(name string) string {
return fmt.Sprintf(`
resource "huaweicloud_cdn_statistic_subscription_task" "test" {
name = "%[1]s"
period_type = 1
emails = "[email protected],[email protected]"
domain_name = "%[2]s"
report_type = "0,1,2,3,4,5"
}
`, name, acceptance.HW_CDN_DOMAIN_NAME)
}
Loading
Loading