Skip to content

Commit

Permalink
Update attributes, add more acc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jiaweitao001 committed Dec 20, 2024
1 parent 55584b9 commit 449647a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 10 deletions.
13 changes: 9 additions & 4 deletions internal/services/dynatrace/dynatrace_tag_rules_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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": {
Expand Down
48 changes: 46 additions & 2 deletions internal/services/dynatrace/dynatrace_tag_rules_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions website/docs/r/dynatrace_tag_rules.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.

Expand Down

0 comments on commit 449647a

Please sign in to comment.