From 449647abb5c3f4ad3fb74c87f2dc965966e00a2e Mon Sep 17 00:00:00 2001 From: Jiawei Tao Date: Fri, 20 Dec 2024 13:53:14 +0800 Subject: [PATCH] Update attributes, add more acc tests --- .../dynatrace/dynatrace_tag_rules_resource.go | 13 +++-- .../dynatrace_tag_rules_resource_test.go | 48 ++++++++++++++++++- .../docs/r/dynatrace_tag_rules.html.markdown | 8 ++-- 3 files changed, 59 insertions(+), 10 deletions(-) diff --git a/internal/services/dynatrace/dynatrace_tag_rules_resource.go b/internal/services/dynatrace/dynatrace_tag_rules_resource.go index 746a2119e5b9..d978bc422d86 100644 --- a/internal/services/dynatrace/dynatrace_tag_rules_resource.go +++ b/internal/services/dynatrace/dynatrace_tag_rules_resource.go @@ -43,10 +43,12 @@ type FilteringTag struct { func (r TagRulesResource) Arguments() map[string]*schema.Schema { return map[string]*schema.Schema{ "name": { - Type: pluginsdk.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + "default", + }, false), }, "monitor_id": { @@ -66,16 +68,19 @@ func (r TagRulesResource) Arguments() map[string]*schema.Schema { "send_azure_active_directory_logs_enabled": { Type: pluginsdk.TypeBool, Optional: true, + Default: false, }, "send_activity_logs_enabled": { Type: pluginsdk.TypeBool, Optional: true, + Default: false, }, "send_subscription_logs_enabled": { Type: pluginsdk.TypeBool, Optional: true, + Default: false, }, "filtering_tag": { diff --git a/internal/services/dynatrace/dynatrace_tag_rules_resource_test.go b/internal/services/dynatrace/dynatrace_tag_rules_resource_test.go index e071a2516f3e..50a129c8b06e 100644 --- a/internal/services/dynatrace/dynatrace_tag_rules_resource_test.go +++ b/internal/services/dynatrace/dynatrace_tag_rules_resource_test.go @@ -47,6 +47,22 @@ func TestAccDynatraceTagRules_basic(t *testing.T) { }) } +func TestAccDynatraceTagRules_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_dynatrace_tag_rules", "test") + r := NewTagRulesResource() + r.preCheck(t) + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func TestAccDynatraceTagRules_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_dynatrace_tag_rules", "test") r := NewTagRulesResource() @@ -102,7 +118,34 @@ func (r TagRulesResource) basic(data acceptance.TestData) string { %[1]s resource "azurerm_dynatrace_tag_rules" "test" { - name = "acctestdyantracetagrules%d" + name = "default" + monitor_id = azurerm_dynatrace_monitor.test.id + + log_rule { + filtering_tag { + name = "Environment" + value = "Prod" + action = "Include" + } + } + + metric_rule { + filtering_tag { + name = "Environment" + value = "Prod" + action = "Include" + } + } +} +`, MonitorsResource{}.basic(data)) +} + +func (r TagRulesResource) complete(data acceptance.TestData) string { + return fmt.Sprintf(` +%[1]s + +resource "azurerm_dynatrace_tag_rules" "test" { + name = "default" monitor_id = azurerm_dynatrace_monitor.test.id log_rule { @@ -113,6 +156,7 @@ resource "azurerm_dynatrace_tag_rules" "test" { } send_azure_active_directory_logs_enabled = true send_activity_logs_enabled = true + send_subscription_logs_enabled = true } metric_rule { @@ -123,7 +167,7 @@ resource "azurerm_dynatrace_tag_rules" "test" { } } } -`, MonitorsResource{}.basic(data), data.RandomInteger) +`, MonitorsResource{}.basic(data)) } func (r TagRulesResource) requiresImport(data acceptance.TestData) string { diff --git a/website/docs/r/dynatrace_tag_rules.html.markdown b/website/docs/r/dynatrace_tag_rules.html.markdown index 1b6d42624031..98555b234b04 100644 --- a/website/docs/r/dynatrace_tag_rules.html.markdown +++ b/website/docs/r/dynatrace_tag_rules.html.markdown @@ -75,7 +75,7 @@ resource "azurerm_dynatrace_tag_rules" "example" { The following arguments are supported: -* `name` - (Required) Name of the Dynatrace tag rules. Changing this forces a new resource to be created. +* `name` - (Required) Name of the Dynatrace tag rules. Currently, the only supported value is `default`. Changing this forces a new resource to be created. * `monitor_id` - (Required) Name of the Dynatrace monitor. Changing this forces a new resource to be created. @@ -87,11 +87,11 @@ The following arguments are supported: The `log_rule` block supports the following: -* `send_azure_active_directory_logs_enabled` - (Optional) Send Azure Active Directory logs. +* `send_azure_active_directory_logs_enabled` - (Optional) Send Azure Active Directory logs. The default value is `false`. -* `send_activity_logs_enabled` - (Optional) Send Activity logs. +* `send_activity_logs_enabled` - (Optional) Send Activity logs. The default value is `false`. -* `send_subscription_logs_enabled` - (Optional) Send Subscription logs. +* `send_subscription_logs_enabled` - (Optional) Send Subscription logs. The default value is `false`. * `filtering_tag` - (Optional) Filtering tag for the log rule. A `filtering_tag` block as defined below.