-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(SMN): add SMN message_templates data source (FlexibleEngineCloud…
- Loading branch information
1 parent
06813ca
commit df21db9
Showing
3 changed files
with
147 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
85 changes: 85 additions & 0 deletions
85
flexibleengine/acceptance/data_source_flexibleengine_smn_message_templates_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters