diff --git a/docs/data-sources/smn_message_templates.md b/docs/data-sources/smn_message_templates.md new file mode 100644 index 00000000..6ee050cf --- /dev/null +++ b/docs/data-sources/smn_message_templates.md @@ -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. + + +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. diff --git a/flexibleengine/acceptance/data_source_flexibleengine_smn_message_templates_test.go b/flexibleengine/acceptance/data_source_flexibleengine_smn_message_templates_test.go new file mode 100644 index 00000000..292718eb --- /dev/null +++ b/flexibleengine/acceptance/data_source_flexibleengine_smn_message_templates_test.go @@ -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) +} diff --git a/flexibleengine/provider.go b/flexibleengine/provider.go index 3b0cad54..c5826be6 100644 --- a/flexibleengine/provider.go +++ b/flexibleengine/provider.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/helper/mutexkv" @@ -328,12 +329,13 @@ func Provider() *schema.Provider { "flexibleengine_rds_instances": rds.DataSourceRdsInstances(), "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_dedicated_instances": waf.DataSourceWafDedicatedInstancesV1(),