Skip to content

Commit fcc7763

Browse files
committed
feat(workspace): add new data source to query template apply records
1 parent be63f13 commit fcc7763

File tree

5 files changed

+518
-19
lines changed

5 files changed

+518
-19
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
subcategory: "Content Delivery Network (CDN)"
3+
layout: "huaweicloud"
4+
page_title: "HuaweiCloud: huaweicloud_cdn_domain_template_apply_records"
5+
description: |-
6+
Use this data source to get a list of domain template apply records within HuaweiCloud.
7+
---
8+
9+
# huaweicloud_cdn_domain_template_apply_records
10+
11+
Use this data source to get a list of domain template apply records within HuaweiCloud.
12+
13+
## Example Usage
14+
15+
```hcl
16+
data "huaweicloud_cdn_domain_template_apply_records" "test" {}
17+
```
18+
19+
## Argument Reference
20+
21+
The following arguments are supported:
22+
23+
* `region` - (Optional, String) The region where the domain template apply records are located.
24+
25+
* `template_id` - (Optional, String) The ID of the domain template.
26+
27+
* `template_name` - (Optional, String) The name of the domain template.
28+
29+
* `operator_id` - (Optional, String) The operation ID of the domain template.
30+
31+
## Attribute Reference
32+
33+
In addition to all arguments above, the following attributes are exported:
34+
35+
* `id` - The data source ID.
36+
37+
* `records` - The list of domain template apply records that matched the filter parameters.
38+
The [records](#cdn_domain_template_apply_records_attr) structure is documented below.
39+
40+
<a name="cdn_domain_template_apply_records_attr"></a>
41+
The `records` block supports:
42+
43+
* `operator_id` - The operation ID.
44+
45+
* `status` - The result of applying the template.
46+
+ **success** - The template was applied successfully.
47+
+ **fail** - The template application failed.
48+
49+
* `template_id` - The ID of the domain template.
50+
51+
* `template_name` - The name of the domain template.
52+
53+
* `description` - The description of the domain template.
54+
55+
* `apply_time` - The time when the domain template was applied, in RFC3339 format.
56+
57+
* `type` - The type of the domain template.
58+
+ **1** - System preset template.
59+
+ **2** - Tenant custom template.
60+
61+
* `account_id` - The account ID.
62+
63+
* `resources` - The list of resources to which the template was applied.
64+
The [resources](#cdn_domain_template_apply_records_resources_attr) structure is documented below.
65+
66+
* `configs` - The configuration of the domain template, in JSON format.
67+
68+
<a name="cdn_domain_template_apply_records_resources_attr"></a>
69+
The `resources` block supports:
70+
71+
* `status` - The status of applying the template to the domain.
72+
+ **success** - The template was applied successfully to the domain.
73+
+ **fail** - The template application to the domain failed.
74+
75+
* `domain_name` - The domain name.
76+
77+
* `error_msg` - The error message.

huaweicloud/provider.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -745,24 +745,25 @@ func Provider() *schema.Provider {
745745
"huaweicloud_ccm_private_certificates": ccm.DataSourcePrivateCertificates(),
746746
"huaweicloud_ccm_private_certificate_export": ccm.DataSourcePrivateCertificateExport(),
747747

748-
"huaweicloud_cdn_analytics": cdn.DataSourceAnalytics(),
749-
"huaweicloud_cdn_billing_option": cdn.DataSourceBillingOption(),
750-
"huaweicloud_cdn_cache_url_tasks": cdn.DataSourceCacheUrlTasks(),
751-
"huaweicloud_cdn_cache_history_tasks": cdn.DataSourceCacheHistoryTasks(),
752-
"huaweicloud_cdn_cache_sharing_groups": cdn.DataSourceCacheSharingGroups(),
753-
"huaweicloud_cdn_domains": cdn.DataSourceDomains(),
754-
"huaweicloud_cdn_domain_templates": cdn.DataSourceDomainTemplates(),
755-
"huaweicloud_cdn_domain_certificates": cdn.DataSourceDomainCertificates(),
756-
"huaweicloud_cdn_domain_owner_verification": cdn.DataSourceDomainOwnerVerification(),
757-
"huaweicloud_cdn_domain_tags": cdn.DataSourceDomainTags(),
758-
"huaweicloud_cdn_ip_information": cdn.DataSourceIpInformation(),
759-
"huaweicloud_cdn_logs": cdn.DataSourceLogs(),
760-
"huaweicloud_cdn_quotas": cdn.DataSourceQuotas(),
761-
"huaweicloud_cdn_domain_statistics": cdn.DataSourceStatistics(),
762-
"huaweicloud_cdn_rule_engine_rules": cdn.DataSourceRuleEngineRules(),
763-
"huaweicloud_cdn_statistic_configuration": cdn.DataSourceStatisticConfiguration(),
764-
"huaweicloud_cdn_top_referrer_statistics": cdn.DataSourceTopReferrerStatistics(),
765-
"huaweicloud_cdn_top_url_statistics": cdn.DataSourceTopUrlStatistics(),
748+
"huaweicloud_cdn_analytics": cdn.DataSourceAnalytics(),
749+
"huaweicloud_cdn_billing_option": cdn.DataSourceBillingOption(),
750+
"huaweicloud_cdn_cache_url_tasks": cdn.DataSourceCacheUrlTasks(),
751+
"huaweicloud_cdn_cache_history_tasks": cdn.DataSourceCacheHistoryTasks(),
752+
"huaweicloud_cdn_cache_sharing_groups": cdn.DataSourceCacheSharingGroups(),
753+
"huaweicloud_cdn_domains": cdn.DataSourceDomains(),
754+
"huaweicloud_cdn_domain_templates": cdn.DataSourceDomainTemplates(),
755+
"huaweicloud_cdn_domain_template_apply_records": cdn.DataSourceDomainTemplateApplyRecords(),
756+
"huaweicloud_cdn_domain_certificates": cdn.DataSourceDomainCertificates(),
757+
"huaweicloud_cdn_domain_owner_verification": cdn.DataSourceDomainOwnerVerification(),
758+
"huaweicloud_cdn_domain_tags": cdn.DataSourceDomainTags(),
759+
"huaweicloud_cdn_ip_information": cdn.DataSourceIpInformation(),
760+
"huaweicloud_cdn_logs": cdn.DataSourceLogs(),
761+
"huaweicloud_cdn_quotas": cdn.DataSourceQuotas(),
762+
"huaweicloud_cdn_domain_statistics": cdn.DataSourceStatistics(),
763+
"huaweicloud_cdn_rule_engine_rules": cdn.DataSourceRuleEngineRules(),
764+
"huaweicloud_cdn_statistic_configuration": cdn.DataSourceStatisticConfiguration(),
765+
"huaweicloud_cdn_top_referrer_statistics": cdn.DataSourceTopReferrerStatistics(),
766+
"huaweicloud_cdn_top_url_statistics": cdn.DataSourceTopUrlStatistics(),
766767

767768
"huaweicloud_ces_agent_dimensions": ces.DataSourceCesAgentDimensions(),
768769
"huaweicloud_ces_agent_maintenance_tasks": ces.DataSourceCesAgentMaintenanceTasks(),
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
package cdn
2+
3+
import (
4+
"fmt"
5+
"regexp"
6+
"testing"
7+
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
9+
10+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
11+
)
12+
13+
func TestAccDataDomainTemplateApplyRecords_basic(t *testing.T) {
14+
var (
15+
name = acceptance.RandomAccResourceNameWithDash()
16+
17+
allRecords = "data.huaweicloud_cdn_domain_template_apply_records.all"
18+
dc = acceptance.InitDataSourceCheck(allRecords)
19+
20+
byTemplateId = "data.huaweicloud_cdn_domain_template_apply_records.filter_by_template_id"
21+
dcByTemplateId = acceptance.InitDataSourceCheck(byTemplateId)
22+
23+
byTemplateName = "data.huaweicloud_cdn_domain_template_apply_records.filter_by_template_name"
24+
dcByTemplateName = acceptance.InitDataSourceCheck(byTemplateName)
25+
26+
byOperatorId = "data.huaweicloud_cdn_domain_template_apply_records.filter_by_operator_id"
27+
dcByOperatorId = acceptance.InitDataSourceCheck(byOperatorId)
28+
)
29+
30+
resource.ParallelTest(t, resource.TestCase{
31+
PreCheck: func() {
32+
acceptance.TestAccPreCheck(t)
33+
acceptance.TestAccPreCheckCdnDomainName(t)
34+
},
35+
ProviderFactories: acceptance.TestAccProviderFactories,
36+
Steps: []resource.TestStep{
37+
{
38+
Config: testAccDataDomainTemplateApplyRecords_basic(name),
39+
Check: resource.ComposeTestCheckFunc(
40+
dc.CheckResourceExists(),
41+
resource.TestMatchResourceAttr(allRecords, "records.#", regexp.MustCompile("^[1-9]([0-9]+)?$")),
42+
dcByTemplateId.CheckResourceExists(),
43+
resource.TestCheckOutput("is_template_id_filter_useful", "true"),
44+
resource.TestCheckResourceAttrSet(byTemplateId, "records.0.operator_id"),
45+
resource.TestCheckResourceAttrSet(byTemplateId, "records.0.status"),
46+
resource.TestCheckResourceAttrSet(byTemplateId, "records.0.template_id"),
47+
resource.TestCheckResourceAttrSet(byTemplateId, "records.0.template_name"),
48+
resource.TestCheckResourceAttrSet(byTemplateId, "records.0.description"),
49+
resource.TestMatchResourceAttr(byTemplateId, "records.0.apply_time",
50+
regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}?(Z|([+-]\d{2}:\d{2}))$`)),
51+
resource.TestCheckResourceAttrSet(byTemplateId, "records.0.type"),
52+
resource.TestCheckResourceAttrSet(byTemplateId, "records.0.account_id"),
53+
resource.TestCheckResourceAttrSet(byTemplateId, "records.0.resources.#"),
54+
resource.TestCheckResourceAttrSet(byTemplateId, "records.0.resources.0.status"),
55+
resource.TestCheckResourceAttrSet(byTemplateId, "records.0.resources.0.domain_name"),
56+
resource.TestCheckResourceAttrSet(byTemplateId, "records.0.configs"),
57+
dcByTemplateName.CheckResourceExists(),
58+
resource.TestCheckOutput("is_template_name_filter_useful", "true"),
59+
dcByOperatorId.CheckResourceExists(),
60+
resource.TestCheckOutput("is_operator_id_filter_useful", "true"),
61+
),
62+
},
63+
},
64+
})
65+
}
66+
67+
func testAccDataDomainTemplateApplyRecords_basic(name string) string {
68+
return fmt.Sprintf(`
69+
resource "huaweicloud_cdn_domain_template" "test" {
70+
name = "%[1]s"
71+
description = "Created by terraform for template apply records test"
72+
configs = jsonencode({
73+
"cache_rules": [
74+
{
75+
"force_cache": "on",
76+
"follow_origin": "off",
77+
"match_type": "all",
78+
"priority": 1,
79+
"stale_while_revalidate": "off",
80+
"ttl": 20,
81+
"ttl_unit": "d",
82+
"url_parameter_type": "full_url",
83+
"url_parameter_value": ""
84+
}
85+
],
86+
"origin_follow302_status": "off",
87+
"compress": {
88+
"type": "gzip",
89+
"status": "on",
90+
"file_type": ".js,.html,.css"
91+
}
92+
})
93+
}
94+
95+
resource "huaweicloud_cdn_domain_template_apply" "test" {
96+
template_id = huaweicloud_cdn_domain_template.test.id
97+
resources = "%[2]s"
98+
}
99+
100+
data "huaweicloud_cdn_domain_template_apply_records" "all" {
101+
depends_on = [
102+
huaweicloud_cdn_domain_template_apply.test
103+
]
104+
}
105+
106+
locals {
107+
template_id = huaweicloud_cdn_domain_template.test.id
108+
}
109+
110+
data "huaweicloud_cdn_domain_template_apply_records" "filter_by_template_id" {
111+
depends_on = [
112+
huaweicloud_cdn_domain_template_apply.test
113+
]
114+
115+
template_id = local.template_id
116+
}
117+
118+
locals {
119+
template_id_filter_result = [for v in data.huaweicloud_cdn_domain_template_apply_records.filter_by_template_id.records[*].template_id :
120+
v == local.template_id]
121+
}
122+
123+
output "is_template_id_filter_useful" {
124+
value = length(local.template_id_filter_result) > 0 && alltrue(local.template_id_filter_result)
125+
}
126+
127+
locals {
128+
template_name = huaweicloud_cdn_domain_template.test.name
129+
}
130+
131+
data "huaweicloud_cdn_domain_template_apply_records" "filter_by_template_name" {
132+
depends_on = [
133+
huaweicloud_cdn_domain_template_apply.test
134+
]
135+
136+
template_name = local.template_name
137+
}
138+
139+
locals {
140+
template_name_filter_result = [for v in data.huaweicloud_cdn_domain_template_apply_records.filter_by_template_name.records[*].template_name :
141+
v == local.template_name]
142+
}
143+
144+
output "is_template_name_filter_useful" {
145+
value = length(local.template_name_filter_result) > 0 && alltrue(local.template_name_filter_result)
146+
}
147+
148+
locals {
149+
operator_id = try(data.huaweicloud_cdn_domain_template_apply_records.all.records[0].operator_id, "NOT_FOUND")
150+
}
151+
152+
data "huaweicloud_cdn_domain_template_apply_records" "filter_by_operator_id" {
153+
operator_id = local.operator_id
154+
}
155+
156+
locals {
157+
operator_id_filter_result = [for v in data.huaweicloud_cdn_domain_template_apply_records.filter_by_operator_id.records[*].operator_id :
158+
v == local.operator_id]
159+
}
160+
161+
output "is_operator_id_filter_useful" {
162+
value = length(local.operator_id_filter_result) > 0 && alltrue(local.operator_id_filter_result)
163+
}
164+
`, name, acceptance.HW_CDN_DOMAIN_NAME)
165+
}

0 commit comments

Comments
 (0)