Skip to content
Merged
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
75 changes: 75 additions & 0 deletions docs/data-sources/cdn_domain_template_apply_records.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
subcategory: "Content Delivery Network (CDN)"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_cdn_domain_template_apply_records"
description: |-
Use this data source to get a list of domain template apply records within HuaweiCloud.
---

# huaweicloud_cdn_domain_template_apply_records

Use this data source to get a list of domain template apply records within HuaweiCloud.

## Example Usage

```hcl
data "huaweicloud_cdn_domain_template_apply_records" "test" {}
```

## Argument Reference

The following arguments are supported:

* `template_id` - (Optional, String) The ID of the domain template.

* `template_name` - (Optional, String) The name of the domain template.

* `operator_id` - (Optional, String) The operation ID of the domain template.

## Attribute Reference

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

* `id` - The data source ID.

* `records` - The list of domain template apply records that matched the filter parameters.
The [records](#cdn_domain_template_apply_records_attr) structure is documented below.

<a name="cdn_domain_template_apply_records_attr"></a>
The `records` block supports:

* `operator_id` - The operation ID.

* `status` - The result of applying the template.
+ **success** - The template was applied successfully.
+ **fail** - The template application failed.

* `template_id` - The ID of the domain template.

* `template_name` - The name of the domain template.

* `description` - The description of the domain template.

* `apply_time` - The time when the domain template was applied, in RFC3339 format.

* `type` - The type of the domain template.
+ **1** - System preset template.
+ **2** - Tenant custom template.

* `account_id` - The account ID.

* `resources` - The list of resources to which the template was applied.
The [resources](#cdn_domain_template_apply_records_resources_attr) structure is documented below.

* `configs` - The configuration of the domain template, in JSON format.

<a name="cdn_domain_template_apply_records_resources_attr"></a>
The `resources` block supports:

* `status` - The status of applying the template to the domain.
+ **success** - The template was applied successfully to the domain.
+ **fail** - The template application to the domain failed.

* `domain_name` - The domain name.

* `error_msg` - The error message.
37 changes: 19 additions & 18 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,24 +745,25 @@ func Provider() *schema.Provider {
"huaweicloud_ccm_private_certificates": ccm.DataSourcePrivateCertificates(),
"huaweicloud_ccm_private_certificate_export": ccm.DataSourcePrivateCertificateExport(),

"huaweicloud_cdn_analytics": cdn.DataSourceAnalytics(),
"huaweicloud_cdn_billing_option": cdn.DataSourceBillingOption(),
"huaweicloud_cdn_cache_url_tasks": cdn.DataSourceCacheUrlTasks(),
"huaweicloud_cdn_cache_history_tasks": cdn.DataSourceCacheHistoryTasks(),
"huaweicloud_cdn_cache_sharing_groups": cdn.DataSourceCacheSharingGroups(),
"huaweicloud_cdn_domains": cdn.DataSourceDomains(),
"huaweicloud_cdn_domain_templates": cdn.DataSourceDomainTemplates(),
"huaweicloud_cdn_domain_certificates": cdn.DataSourceDomainCertificates(),
"huaweicloud_cdn_domain_owner_verification": cdn.DataSourceDomainOwnerVerification(),
"huaweicloud_cdn_domain_tags": cdn.DataSourceDomainTags(),
"huaweicloud_cdn_ip_information": cdn.DataSourceIpInformation(),
"huaweicloud_cdn_logs": cdn.DataSourceLogs(),
"huaweicloud_cdn_quotas": cdn.DataSourceQuotas(),
"huaweicloud_cdn_domain_statistics": cdn.DataSourceStatistics(),
"huaweicloud_cdn_rule_engine_rules": cdn.DataSourceRuleEngineRules(),
"huaweicloud_cdn_statistic_configuration": cdn.DataSourceStatisticConfiguration(),
"huaweicloud_cdn_top_referrer_statistics": cdn.DataSourceTopReferrerStatistics(),
"huaweicloud_cdn_top_url_statistics": cdn.DataSourceTopUrlStatistics(),
"huaweicloud_cdn_analytics": cdn.DataSourceAnalytics(),
"huaweicloud_cdn_billing_option": cdn.DataSourceBillingOption(),
"huaweicloud_cdn_cache_url_tasks": cdn.DataSourceCacheUrlTasks(),
"huaweicloud_cdn_cache_history_tasks": cdn.DataSourceCacheHistoryTasks(),
"huaweicloud_cdn_cache_sharing_groups": cdn.DataSourceCacheSharingGroups(),
"huaweicloud_cdn_domains": cdn.DataSourceDomains(),
"huaweicloud_cdn_domain_templates": cdn.DataSourceDomainTemplates(),
"huaweicloud_cdn_domain_template_apply_records": cdn.DataSourceDomainTemplateApplyRecords(),
"huaweicloud_cdn_domain_certificates": cdn.DataSourceDomainCertificates(),
"huaweicloud_cdn_domain_owner_verification": cdn.DataSourceDomainOwnerVerification(),
"huaweicloud_cdn_domain_tags": cdn.DataSourceDomainTags(),
"huaweicloud_cdn_ip_information": cdn.DataSourceIpInformation(),
"huaweicloud_cdn_logs": cdn.DataSourceLogs(),
"huaweicloud_cdn_quotas": cdn.DataSourceQuotas(),
"huaweicloud_cdn_domain_statistics": cdn.DataSourceStatistics(),
"huaweicloud_cdn_rule_engine_rules": cdn.DataSourceRuleEngineRules(),
"huaweicloud_cdn_statistic_configuration": cdn.DataSourceStatisticConfiguration(),
"huaweicloud_cdn_top_referrer_statistics": cdn.DataSourceTopReferrerStatistics(),
"huaweicloud_cdn_top_url_statistics": cdn.DataSourceTopUrlStatistics(),

"huaweicloud_ces_agent_dimensions": ces.DataSourceCesAgentDimensions(),
"huaweicloud_ces_agent_maintenance_tasks": ces.DataSourceCesAgentMaintenanceTasks(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package cdn

import (
"fmt"
"regexp"
"testing"

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

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

func TestAccDataDomainTemplateApplyRecords_basic(t *testing.T) {
var (
name = acceptance.RandomAccResourceNameWithDash()

all = "data.huaweicloud_cdn_domain_template_apply_records.all"
dc = acceptance.InitDataSourceCheck(all)

filterByTemplateId = "data.huaweicloud_cdn_domain_template_apply_records.filter_by_template_id"
dcFilterByTemplateId = acceptance.InitDataSourceCheck(filterByTemplateId)

filterByTemplateName = "data.huaweicloud_cdn_domain_template_apply_records.filter_by_template_name"
dcFilterByTemplateName = acceptance.InitDataSourceCheck(filterByTemplateName)

filterByOperatorId = "data.huaweicloud_cdn_domain_template_apply_records.filter_by_operator_id"
dcFilterByOperatorId = acceptance.InitDataSourceCheck(filterByOperatorId)
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckCdnDomainName(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDataDomainTemplateApplyRecords_basic(name),
Check: resource.ComposeTestCheckFunc(
// Without any filter parameter.
dc.CheckResourceExists(),
resource.TestMatchResourceAttr(all, "records.#", regexp.MustCompile("^[1-9]([0-9]+)?$")),
// Filter by 'template_id' parameter.
dcFilterByTemplateId.CheckResourceExists(),
resource.TestCheckOutput("is_template_id_filter_useful", "true"),
resource.TestCheckResourceAttrSet(filterByTemplateId, "records.0.operator_id"),
resource.TestCheckResourceAttrSet(filterByTemplateId, "records.0.status"),
resource.TestCheckResourceAttrSet(filterByTemplateId, "records.0.template_id"),
resource.TestCheckResourceAttrSet(filterByTemplateId, "records.0.template_name"),
resource.TestCheckResourceAttrSet(filterByTemplateId, "records.0.description"),
resource.TestMatchResourceAttr(filterByTemplateId, "records.0.apply_time",
regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}?(Z|([+-]\d{2}:\d{2}))$`)),
resource.TestCheckResourceAttrSet(filterByTemplateId, "records.0.type"),
resource.TestCheckResourceAttrSet(filterByTemplateId, "records.0.account_id"),
resource.TestCheckResourceAttrSet(filterByTemplateId, "records.0.resources.#"),
resource.TestCheckResourceAttrSet(filterByTemplateId, "records.0.resources.0.status"),
resource.TestCheckResourceAttrSet(filterByTemplateId, "records.0.resources.0.domain_name"),
resource.TestCheckResourceAttrSet(filterByTemplateId, "records.0.configs"),
// Filter by 'template_name' parameter.
dcFilterByTemplateName.CheckResourceExists(),
resource.TestCheckOutput("is_template_name_filter_useful", "true"),
// Filter by 'operator_id' parameter.
dcFilterByOperatorId.CheckResourceExists(),
resource.TestCheckOutput("is_operator_id_filter_useful", "true"),
),
},
},
})
}

func testAccDataDomainTemplateApplyRecords_basic(name string) string {
return fmt.Sprintf(`
resource "huaweicloud_cdn_domain_template" "test" {
name = "%[1]s"
description = "Created by terraform for template apply records test"
configs = jsonencode({
"cache_rules": [
{
"force_cache": "on",
"follow_origin": "off",
"match_type": "all",
"priority": 1,
"stale_while_revalidate": "off",
"ttl": 20,
"ttl_unit": "d",
"url_parameter_type": "full_url",
"url_parameter_value": ""
}
],
"origin_follow302_status": "off",
"compress": {
"type": "gzip",
"status": "on",
"file_type": ".js,.html,.css"
}
})
}

resource "huaweicloud_cdn_domain_template_apply" "test" {
template_id = huaweicloud_cdn_domain_template.test.id
resources = "%[2]s"
}

# Without any filter parameter.
data "huaweicloud_cdn_domain_template_apply_records" "all" {
depends_on = [
huaweicloud_cdn_domain_template_apply.test
]
}

# Filter by 'template_id' parameter.
locals {
template_id = huaweicloud_cdn_domain_template.test.id
}

data "huaweicloud_cdn_domain_template_apply_records" "filter_by_template_id" {
depends_on = [
huaweicloud_cdn_domain_template_apply.test
]

template_id = local.template_id
}

locals {
template_id_filter_result = [for v in data.huaweicloud_cdn_domain_template_apply_records.filter_by_template_id.records[*].template_id :
v == local.template_id]
}

output "is_template_id_filter_useful" {
value = length(local.template_id_filter_result) > 0 && alltrue(local.template_id_filter_result)
}

# Filter by 'template_name' parameter.
locals {
template_name = huaweicloud_cdn_domain_template.test.name
}

data "huaweicloud_cdn_domain_template_apply_records" "filter_by_template_name" {
depends_on = [
huaweicloud_cdn_domain_template_apply.test
]

template_name = local.template_name
}

locals {
template_name_filter_result = [for v in data.huaweicloud_cdn_domain_template_apply_records.filter_by_template_name.records[*].template_name :
v == local.template_name]
}

output "is_template_name_filter_useful" {
value = length(local.template_name_filter_result) > 0 && alltrue(local.template_name_filter_result)
}

# Filter by 'operator_id' parameter.
locals {
operator_id = try(data.huaweicloud_cdn_domain_template_apply_records.all.records[0].operator_id, "NOT_FOUND")
}

data "huaweicloud_cdn_domain_template_apply_records" "filter_by_operator_id" {
operator_id = local.operator_id
}

locals {
operator_id_filter_result = [for v in data.huaweicloud_cdn_domain_template_apply_records.filter_by_operator_id.records[*].operator_id :
v == local.operator_id]
}

output "is_operator_id_filter_useful" {
value = length(local.operator_id_filter_result) > 0 && alltrue(local.operator_id_filter_result)
}
`, name, acceptance.HW_CDN_DOMAIN_NAME)
}
Loading
Loading