Skip to content

Commit

Permalink
feat(SMN): add SMN message_templates data source (FlexibleEngineCloud…
Browse files Browse the repository at this point in the history
  • Loading branch information
liwanting0517 authored and Zippo-Wang committed Dec 25, 2023
1 parent 06813ca commit df21db9
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 6 deletions.
55 changes: 55 additions & 0 deletions docs/data-sources/smn_message_templates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
subcategory: "Simple Message Notification (SMN)"
---

# flexibleengine_smn_message_templates

Use this data source to get the list of SMN message templates.

## Example Usage

```hcl
variable "name" {}
data "flexibleengine_smn_message_templates" "test" {
name = var.name
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String) Specifies the region in which to query the data source.
If omitted, the provider-level region will be used.

* `name` - (Optional, String) Specifies the name of the message template.

* `protocol` - (Optional, String) Specifies the protocol of the message template.

* `template_id` - (Optional, String) Specifies the message template ID.

## Attribute Reference

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

* `id` - The data source ID.

* `templates` - The list of message templates.
The [templates](#SmnMessageTemplate_MessageTemplate) structure is documented below.

<a name="SmnMessageTemplate_MessageTemplate"></a>
The `templates` block supports:

* `id` - Indicates the message template ID.

* `name` - Indicates the message template name.

* `protocol` - Indicates the protocol supported by the template.

* `tag_names` - Indicates the variable list. The variable name will be quoted in braces ({}) in the template.
When you use a template to send messages, you can replace the variable with any content.

* `created_at` - Indicates the create time.

* `updated_at` - Indicates the update time.
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package acceptance

import (
"fmt"
"testing"

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

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

func TestAccDatasourceSmnMessageTemplates_basic(t *testing.T) {
rName := "data.flexibleengine_smn_message_templates.test"
name := acceptance.RandomAccResourceName()
dc := acceptance.InitDataSourceCheck(rName)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDatasourceSmnMessageTemplates_basic(name),
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckResourceAttrSet(rName, "templates.0.id"),
resource.TestCheckResourceAttrSet(rName, "templates.0.name"),
resource.TestCheckResourceAttrSet(rName, "templates.0.protocol"),
resource.TestCheckResourceAttrSet(rName, "templates.0.tag_names.#"),
resource.TestCheckResourceAttrSet(rName, "templates.0.created_at"),
resource.TestCheckResourceAttrSet(rName, "templates.0.updated_at"),
resource.TestCheckOutput("name_filter_is_useful", "true"),
resource.TestCheckOutput("protocol_filter_is_useful", "true"),
resource.TestCheckOutput("template_id_filter_is_useful", "true"),
),
},
},
})
}

func testAccDatasourceSmnMessageTemplates_basic(name string) string {
return fmt.Sprintf(`
%[1]s
data "flexibleengine_smn_message_templates" "test" {
depends_on = [flexibleengine_smn_message_template.test]
}
data "flexibleengine_smn_message_templates" "name_filter" {
name = "%[2]s"
depends_on = [flexibleengine_smn_message_template.test]
}
output "name_filter_is_useful" {
value = length(data.flexibleengine_smn_message_templates.name_filter.templates) > 0 && alltrue(
[for v in data.flexibleengine_smn_message_templates.name_filter.templates[*].name : v == "%[2]s"]
)
}
data "flexibleengine_smn_message_templates" "protocol_filter" {
protocol = "default"
depends_on = [flexibleengine_smn_message_template.test]
}
output "protocol_filter_is_useful" {
value = length(data.flexibleengine_smn_message_templates.protocol_filter.templates) > 0 && alltrue(
[for v in data.flexibleengine_smn_message_templates.protocol_filter.templates[*].protocol : v == "default"]
)
}
locals {
template_id = flexibleengine_smn_message_template.test.id
}
data "flexibleengine_smn_message_templates" "template_id_filter" {
template_id = local.template_id
}
output "template_id_filter_is_useful" {
value = length(data.flexibleengine_smn_message_templates.template_id_filter.templates) > 0 && alltrue(
[for v in data.flexibleengine_smn_message_templates.template_id_filter.templates[*].id : v == local.template_id]
)
}
`, testSmnMessageTemplate_basic(name), name)
}
13 changes: 7 additions & 6 deletions flexibleengine/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,13 @@ func Provider() *schema.Provider {
"flexibleengine_rds_sqlserver_collations": rds.DataSourceSQLServerCollations(),
"flexibleengine_rds_storage_types": rds.DataSourceStoragetype(),

"flexibleengine_sfs_turbos": sfs.DataSourceTurbos(),
"flexibleengine_smn_topics": smn.DataSourceTopics(),
"flexibleengine_sms_source_servers": sms.DataSourceServers(),
"flexibleengine_vpc_route_table": vpc.DataSourceVPCRouteTable(),
"flexibleengine_vpc_subnets": vpc.DataSourceVpcSubnets(),
"flexibleengine_vpcs": vpc.DataSourceVpcs(),
"flexibleengine_sfs_turbos": sfs.DataSourceTurbos(),
"flexibleengine_smn_topics": smn.DataSourceTopics(),
"flexibleengine_smn_message_templates": smn.DataSourceSmnMessageTemplates(),
"flexibleengine_sms_source_servers": sms.DataSourceServers(),
"flexibleengine_vpc_route_table": vpc.DataSourceVPCRouteTable(),
"flexibleengine_vpc_subnets": vpc.DataSourceVpcSubnets(),
"flexibleengine_vpcs": vpc.DataSourceVpcs(),

"flexibleengine_waf_certificate": waf.DataSourceWafCertificateV1(),
"flexibleengine_waf_dedicated_instances": waf.DataSourceWafDedicatedInstancesV1(),
Expand Down

0 comments on commit df21db9

Please sign in to comment.