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

New Resource: azurerm_monitor_diagnostic_setting / New Data Source: azurerm_monitor_diagnostic_categories #1291

Merged
merged 15 commits into from
Nov 15, 2018

Conversation

janboll
Copy link

@janboll janboll commented May 24, 2018

Hi,

I implemented a new resource to be able to configure diagnostic settings on any given resource (fixes #657). I am opening this PR to request feedback as soon as possible.
There are still open points

  • Documentation
  • Testing
    • Update / delete
    • Complete feature
  • Import
  • Datasource

Please have a look at the PR and check if I am steering into the right direction.
Thanks,
Jan

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

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

hey @janboll

Thanks for this PR :)

I've taken a look through and left some comments in-line and have tried to provide code samples for all of the issues I've raised - but this is off to a good start 👍

Thanks!

azurerm/config.go Show resolved Hide resolved
azurerm/resource_arm_monitor_diagnostics.go Outdated Show resolved Hide resolved
azurerm/resource_arm_monitor_diagnostics.go Outdated Show resolved Hide resolved
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
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 remove the DiffSuppressFunc here, since this should force a recreation if the casing changes on the resource we're monitoring?

azurerm/resource_arm_monitor_diagnostics_test.go Outdated Show resolved Hide resolved
azurerm/resource_arm_monitor_diagnostics.go Outdated Show resolved Hide resolved
azurerm/resource_arm_monitor_diagnostics.go Outdated Show resolved Hide resolved
azurerm/resource_arm_monitor_diagnostics.go Outdated Show resolved Hide resolved
azurerm/resource_arm_monitor_diagnostics.go Outdated Show resolved Hide resolved
return err
}
if read.ID == nil {
return fmt.Errorf("Cannot read Diagnostic Settings")
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 make this error message clearer to match the other resources? e.g. fmt.Errorf("Cannot read ID for Monitor Diagnostics %q", name)

@janboll
Copy link
Author

janboll commented Jun 12, 2018

I had to change the schema cause of the way the Azure API behaves. If you omit one of MetricSettings or LogSettings it will just create these loggings with default settings instead of skipping them.
Therefore I built the schema so that it matches this behaviour, it will always enable all diagnostic settings unless you disable them using disabled_settings

@laughtonsm

This comment has been minimized.

@janboll
Copy link
Author

janboll commented Jun 25, 2018

Hi @tombuildsstuff did you have time to check on my changes yet?

@twinkler

This comment has been minimized.

@BeardedBarbarian

This comment has been minimized.

@tombuildsstuff
Copy link
Contributor

tombuildsstuff commented Jul 16, 2018

@janboll apologies for the really delayed re-review here - I'm going to take another look through this tomorrow (sorry I missed that) later this week :)

@tombuildsstuff
Copy link
Contributor

@janboll hey - just to let you know that I'm taking a look at this at the moment. As a part of this I've pulled the code locally to read through properly, and have rebased this on top of master/switched to using the same API as the rest of the resources which use the insights SDK - I hope you don't mind!

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

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

hey @janboll

Thanks for pushing those updates / apologies for the delayed review here!

I've pushed a couple of commits to rebase this and then fix the ID as mentioned in the comments/add some TODO's. Taking a look through this I think the schema needs some tweaking to get it right, in particular I think we need to add a data source to return the available (Metrics/Logs) Categories for a particular Diagnostic Setting, and probably look at the schema for the Metric and Log fields, since I think these want to be nested blocks; what do you think?

Thanks!

azurerm/resource_arm_monitor_diagnostics.go Outdated Show resolved Hide resolved
azurerm/resource_arm_monitor_diagnostics.go Outdated Show resolved Hide resolved
azurerm/resource_arm_monitor_diagnostics.go Outdated Show resolved Hide resolved
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
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 remove the DiffSuppressFunc from this? in addition we can validate this using ValidateFunc: azure.ValidateResourceID (rather than the azure.ValidateResourceIDOrEmpty which is intended for optional fields)

func retrieveDiagnosticName(diagnosticSettingId string) string {
substring := "/providers/microsoft.insights/diagnosticSettings/"
return diagnosticSettingId[len(substring)+strings.Index(diagnosticSettingId, substring):]
}
Copy link
Contributor

Choose a reason for hiding this comment

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

on reflection I feel like a less brittle way of doing this would be to compose our own resource ID of {targetResourceID}|{name} since some of the Azure API's are case sensitive - I'm going to push a commit to fix this.

azurerm/monitor_diagnostics.go Outdated Show resolved Hide resolved
azurerm/resource_arm_monitor_diagnostics.go Outdated Show resolved Hide resolved
azurerm/resource_arm_monitor_diagnostics.go Outdated Show resolved Hide resolved
azurerm/resource_arm_monitor_diagnostics.go Outdated Show resolved Hide resolved
azurerm/resource_arm_monitor_diagnostics.go Outdated Show resolved Hide resolved
@tombuildsstuff
Copy link
Contributor

@janboll apologies this has sat for a little while - I hope you don't mind but I've pushed a commit to rebase this on top of master so we can proceed with this :)

Jan-Hendrik Boll and others added 5 commits November 13, 2018 12:17
Add testCheckAzureRMMonitorDiagnosticsDestroy function
… etc

Adding some TODO's around the Schema
Ensuring fields are always set
Tests pass:

```
$ acctests azurerm TestAccDataSourceArmMonitorDiagnosticCategories_
=== RUN   TestAccDataSourceArmMonitorDiagnosticCategories_appService
--- PASS: TestAccDataSourceArmMonitorDiagnosticCategories_appService (150.71s)
=== RUN   TestAccDataSourceArmMonitorDiagnosticCategories_storageAccount
--- PASS: TestAccDataSourceArmMonitorDiagnosticCategories_storageAccount (108.97s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	261.573s
```
@ghost ghost added size/XXL and removed size/XL labels Nov 13, 2018
@tombuildsstuff tombuildsstuff changed the title [WIP] New resource: monitor diagnostics New Resource: azurerm_monitor_diagnostic_setting / New Data Source: azurerm_monitor_diagnostic_categories Nov 13, 2018
@tombuildsstuff tombuildsstuff dismissed their stale review November 13, 2018 16:38

dismissing since changes have been pushed

```
$ acctests azurerm TestAccAzureRMMonitorDiagnosticSetting_
=== RUN   TestAccAzureRMMonitorDiagnosticSetting_eventhub
=== PAUSE TestAccAzureRMMonitorDiagnosticSetting_eventhub
=== RUN   TestAccAzureRMMonitorDiagnosticSetting_logAnalyticsWorkspace
=== PAUSE TestAccAzureRMMonitorDiagnosticSetting_logAnalyticsWorkspace
=== RUN   TestAccAzureRMMonitorDiagnosticSetting_storageAccount
=== PAUSE TestAccAzureRMMonitorDiagnosticSetting_storageAccount
=== CONT  TestAccAzureRMMonitorDiagnosticSetting_eventhub
--- PASS: TestAccAzureRMMonitorDiagnosticSetting_eventhub (282.77s)
=== CONT  TestAccAzureRMMonitorDiagnosticSetting_storageAccount
--- PASS: TestAccAzureRMMonitorDiagnosticSetting_storageAccount (219.99s)
=== CONT  TestAccAzureRMMonitorDiagnosticSetting_logAnalyticsWorkspace
--- PASS: TestAccAzureRMMonitorDiagnosticSetting_logAnalyticsWorkspace (215.82s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	719.066s
```
Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

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

@janboll, @tombuildsstuff,

I have left some comments inline, most pretty innocuous. The one thing that stands out to me is what will happen if one or more of eventhub_authorization_rule_id, log_analytics_workspace_id or storage_account_id is set?

azurerm/data_source_monitor_diagnostic_categories.go Outdated Show resolved Hide resolved
azurerm/data_source_monitor_diagnostic_categories.go Outdated Show resolved Hide resolved
azurerm/resource_arm_monitor_diagnostic_setting.go Outdated Show resolved Hide resolved
azurerm/resource_arm_monitor_diagnostic_setting.go Outdated Show resolved Hide resolved
azurerm/utils/utils.go Outdated Show resolved Hide resolved
azurerm/utils/utils.go Outdated Show resolved Hide resolved
@tombuildsstuff
Copy link
Contributor

tombuildsstuff commented Nov 14, 2018

@janboll thanks for pushing those changes 👍

Apologies (as I'd meant to post this yesterday) / for the delayed re-review here - I hope you don't mind, but I pushed some commits to update this resource (and added a Data Source) to better match the representation in Azure so that we can get this merged :)

Thanks!

@janboll
Copy link
Author

janboll commented Nov 14, 2018

@tombuildsstuff Thanks, really appreciate help on this PR! 👍

Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

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

LGTM @tombuildsstuff 👍

@katbyte katbyte merged commit 2154108 into hashicorp:master Nov 15, 2018
katbyte added a commit that referenced this pull request Nov 15, 2018
@twem
Copy link

twem commented Dec 4, 2018

The examples appear to be missing from the documentation. Has this been logged as an issue?

@tombuildsstuff
Copy link
Contributor

@twem thanks for the heads up - that's been reported/fixed in #2391 and will be updated as a part of the next release :)

@ghost
Copy link

ghost commented Mar 5, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New Resource: azurerm_monitor_diagnostic_setting
8 participants