Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_datadog_monitor_tag_rule - correctly handle default rule #22806

Merged
merged 10 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions internal/services/datadog/datadog_monitor_tag_rule_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2021-03-01/monitorsresource"
"github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2021-03-01/rules"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand Down Expand Up @@ -145,15 +144,6 @@ func resourceDatadogTagRulesCreate(d *pluginsdk.ResourceData, meta interface{})
}

id := rules.NewTagRuleID(monitorId.SubscriptionId, monitorId.ResourceGroupName, monitorId.MonitorName, d.Get("name").(string))
existing, err := client.TagRulesGet(ctx, id)
if err != nil {
if !response.WasNotFound(existing.HttpResponse) {
return fmt.Errorf("checking for an existing %s: %+v", id, err)
}
}
if !response.WasNotFound(existing.HttpResponse) {
return tf.ImportAsExistsError("azurerm_datadog_monitor_tag_rule", id.ID())
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a core behavioural feature of the provider, so we shouldn't be requiring the requiredImports check, instead we can update it to confirm if this is configured with the default settings, and raise the requiredImports error if so - can we update this?

Copy link
Contributor Author

@neil-yechenwei neil-yechenwei Aug 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the code to check if the "Tag Rule" exists or the "Tag Rule" is with default settings.

Service team confirmed that below behaviors are expected.

  1. Datadog Monitor Tag Rule only allows name "default".
  2. For the completely new Datadog Monitor, there is no existing Datadog Monitor Tag Rule under it.
  3. For the recreated Datadog Monitor with same name, there always is an existing default Datadog Monitor Tag Rule under it.
  4. Service API doesn't support to delete existing Datadog Monitor Tag Rule.


payload := rules.MonitoringTagRules{
Properties: &rules.MonitoringTagRulesProperties{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,6 @@ func TestAccDatadogMonitorTagRules_basic(t *testing.T) {
})
}

func TestAccDatadogMonitorTagRules_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_datadog_monitor_tag_rule", "test")
r := TagRulesDatadogMonitorResource{}
r.populateFromEnvironment(t)
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.RequiresImportErrorStep(r.requiresImport),
})
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we revert this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted it.


func TestAccDatadogMonitorTagRules_update(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_datadog_monitor_tag_rule", "test")
r := TagRulesDatadogMonitorResource{}
Expand Down Expand Up @@ -139,10 +124,6 @@ resource "azurerm_datadog_monitor" "test" {

func (r TagRulesDatadogMonitorResource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

%s

resource "azurerm_datadog_monitor_tag_rule" "test" {
Expand All @@ -161,33 +142,8 @@ resource "azurerm_datadog_monitor_tag_rule" "test" {
`, r.template(data))
}

func (r TagRulesDatadogMonitorResource) requiresImport(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

resource "azurerm_datadog_monitor_tag_rule" "import" {
datadog_monitor_id = azurerm_datadog_monitor_tag_rule.test.datadog_monitor_id
name = azurerm_datadog_monitor_tag_rule.test.name
log {
subscription_log_enabled = true
}
metric {
filter {
name = "Test"
value = "Testing-Logs"
action = "Include"
}
}
}
`, r.basic(data))
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we revert this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted it.

func (r TagRulesDatadogMonitorResource) update(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should be specified in each test, can we revert this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been defined in template func.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

provider blocks should not be defined in the template function and should be specified in each test - can we revert this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, in main branch, provider block is defined in both template function and each test. So I assume this is a bug. So I removed provider block from template function otherwise test case would fail.

%s

resource "azurerm_datadog_monitor_tag_rule" "test" {
Expand Down
Loading