diff --git a/azurerm/internal/services/loganalytics/client/client.go b/azurerm/internal/services/loganalytics/client/client.go index aaa448b38e5e..690eef79e8e6 100644 --- a/azurerm/internal/services/loganalytics/client/client.go +++ b/azurerm/internal/services/loganalytics/client/client.go @@ -7,12 +7,16 @@ import ( ) type Client struct { + DataSourcesClient *operationalinsights.DataSourcesClient LinkedServicesClient *operationalinsights.LinkedServicesClient SolutionsClient *operationsmanagement.SolutionsClient WorkspacesClient *operationalinsights.WorkspacesClient } func NewClient(o *common.ClientOptions) *Client { + DataSourcesClient := operationalinsights.NewDataSourcesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + o.ConfigureClient(&DataSourcesClient.Client, o.ResourceManagerAuthorizer) + WorkspacesClient := operationalinsights.NewWorkspacesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&WorkspacesClient.Client, o.ResourceManagerAuthorizer) @@ -23,6 +27,7 @@ func NewClient(o *common.ClientOptions) *Client { o.ConfigureClient(&LinkedServicesClient.Client, o.ResourceManagerAuthorizer) return &Client{ + DataSourcesClient: &DataSourcesClient, LinkedServicesClient: &LinkedServicesClient, SolutionsClient: &SolutionsClient, WorkspacesClient: &WorkspacesClient, diff --git a/azurerm/internal/services/loganalytics/parse/log_analytics_datasource.go b/azurerm/internal/services/loganalytics/parse/log_analytics_datasource.go new file mode 100644 index 000000000000..a9065d6c31cc --- /dev/null +++ b/azurerm/internal/services/loganalytics/parse/log_analytics_datasource.go @@ -0,0 +1,38 @@ +package parse + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +type LogAnalyticsDataSourceId struct { + ResourceGroup string + Workspace string + Name string +} + +func LogAnalyticsDataSourceID(input string) (*LogAnalyticsDataSourceId, error) { + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("[ERROR] Unable to parse Log Analytics Data Source ID %q: %+v", input, err) + } + + server := LogAnalyticsDataSourceId{ + ResourceGroup: id.ResourceGroup, + } + + if server.Workspace, err = id.PopSegment("workspaces"); err != nil { + return nil, err + } + + if server.Name, err = id.PopSegment("datasources"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &server, nil +} diff --git a/azurerm/internal/services/loganalytics/parse/log_analytics_datasource_test.go b/azurerm/internal/services/loganalytics/parse/log_analytics_datasource_test.go new file mode 100644 index 000000000000..2d9ad66a7b91 --- /dev/null +++ b/azurerm/internal/services/loganalytics/parse/log_analytics_datasource_test.go @@ -0,0 +1,85 @@ +package parse + +import ( + "testing" +) + +func TestLogAnalyticsDataSourceID(t *testing.T) { + testData := []struct { + Name string + Input string + Error bool + Expect *LogAnalyticsDataSourceId + }{ + { + Name: "Empty", + Input: "", + Error: true, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Error: true, + }, + { + Name: "No Resource Groups Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", + Error: true, + }, + { + Name: "Resource Group ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/", + Error: true, + }, + { + Name: "Missing Workspace Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + Name: "Workspace Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.OperationalInsights/workspaces/workspace1", + Error: true, + }, + { + Name: "Missing DataSource Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.OperationalInsights/workspaces/workspace1/datasources", + Error: true, + }, + { + Name: "DataSource Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.OperationalInsights/workspaces/workspace1/datasources/datasource1", + Error: true, + Expect: &LogAnalyticsDataSourceId{ + ResourceGroup: "resGroup1", + Workspace: "workspace1", + Name: "datasource1", + }, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := LogAnalyticsDataSourceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.ResourceGroup != v.Expect.ResourceGroup { + t.Fatalf("Expected %q but got %q for Resource Group", v.Expect.ResourceGroup, actual.ResourceGroup) + } + + if actual.Workspace != v.Expect.Workspace { + t.Fatalf("Expected %q but got %q for Name", v.Expect.Workspace, actual.Workspace) + } + + if actual.Name != v.Expect.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expect.Name, actual.Name) + } + } +} diff --git a/azurerm/internal/services/loganalytics/registration.go b/azurerm/internal/services/loganalytics/registration.go index d8c5f126a26e..0f8a5880ec77 100644 --- a/azurerm/internal/services/loganalytics/registration.go +++ b/azurerm/internal/services/loganalytics/registration.go @@ -27,7 +27,9 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { return map[string]*schema.Resource{ - "azurerm_log_analytics_linked_service": resourceArmLogAnalyticsLinkedService(), - "azurerm_log_analytics_solution": resourceArmLogAnalyticsSolution(), - "azurerm_log_analytics_workspace": resourceArmLogAnalyticsWorkspace()} + "azurerm_log_analytics_linked_service": resourceArmLogAnalyticsLinkedService(), + "azurerm_log_analytics_solution": resourceArmLogAnalyticsSolution(), + "azurerm_log_analytics_workspace": resourceArmLogAnalyticsWorkspace(), + "azurerm_log_analytics_datasource_windows_performance_counter": resourceArmLogAnalyticsDataSourceWindowsPerformanceCounter(), + } } diff --git a/azurerm/internal/services/loganalytics/resource_arm_log_analytics_datasource_windows_performance_counter.go b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_datasource_windows_performance_counter.go new file mode 100644 index 000000000000..1758e34d29c2 --- /dev/null +++ b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_datasource_windows_performance_counter.go @@ -0,0 +1,206 @@ +package loganalytics + +import ( + "encoding/json" + "fmt" + "log" + "math" + "time" + + "github.com/Azure/azure-sdk-for-go/services/preview/operationalinsights/mgmt/2015-11-01-preview/operationalinsights" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/structure" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/loganalytics/parse" + azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmLogAnalyticsDataSourceWindowsPerformanceCounter() *schema.Resource { + return &schema.Resource{ + Create: resourceArmLogAnalyticsDataSourceWindowsPerformanceCounterCreateUpdate, + Read: resourceArmLogAnalyticsDataSourceWindowsPerformanceCounterRead, + Update: resourceArmLogAnalyticsDataSourceWindowsPerformanceCounterCreateUpdate, + Delete: resourceArmLogAnalyticsDataSourceWindowsPerformanceCounterDelete, + + Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { + _, err := parse.LogAnalyticsDataSourceID(id) + return err + }), + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Read: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "resource_group_name": azure.SchemaResourceGroupName(), + + "workspace_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + DiffSuppressFunc: suppress.CaseDifference, + ValidateFunc: ValidateAzureRmLogAnalyticsWorkspaceName, + }, + + "counter_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "instance_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "interval_seconds": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(10, math.MaxInt32), + }, + + "object_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, + } +} + +type dataSourceWindowsPerformanceCounterProperty struct { + CounterName string `json:"counterName"` + InstanceName string `json:"instanceName"` + IntervalSeconds int `json:"intervalSeconds"` + ObjectName string `json:"objectName"` +} + +func resourceArmLogAnalyticsDataSourceWindowsPerformanceCounterCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).LogAnalytics.DataSourcesClient + ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + workspaceName := d.Get("workspace_name").(string) + + if d.IsNewResource() { + resp, err := client.Get(ctx, resourceGroup, workspaceName, name) + if err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("failed to check for existing Log Analytics DataSource Windows Performance Counter %q (Resource Group %q / Workspace: %q): %+v", name, resourceGroup, workspaceName, err) + } + } + + if !utils.ResponseWasNotFound(resp.Response) { + return tf.ImportAsExistsError("azurerm_log_analytics_datasource_windows_performance_counter", *resp.ID) + } + } + + prop := &dataSourceWindowsPerformanceCounterProperty{ + CounterName: d.Get("counter_name").(string), + InstanceName: d.Get("instance_name").(string), + IntervalSeconds: d.Get("interval_seconds").(int), + ObjectName: d.Get("object_name").(string), + } + + params := operationalinsights.DataSource{ + Kind: operationalinsights.WindowsPerformanceCounter, + Properties: prop, + } + + if _, err := client.CreateOrUpdate(ctx, resourceGroup, workspaceName, name, params); err != nil { + return fmt.Errorf("failed to create Log Analytics DataSource Windows Performance Counter %q (Resource Group %q / Workspace: %q): %+v", name, resourceGroup, workspaceName, err) + } + + resp, err := client.Get(ctx, resourceGroup, workspaceName, name) + if err != nil { + return fmt.Errorf("failed to retrieve Log Analytics DataSource Windows Performance Counter %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + if resp.ID == nil || *resp.ID == "" { + return fmt.Errorf("Cannot read ID for Log Analytics DataSource Windows Performance Counter %q (Resource Group %q)", name, resourceGroup) + } + + d.SetId(*resp.ID) + + return resourceArmLogAnalyticsDataSourceWindowsPerformanceCounterRead(d, meta) +} + +func resourceArmLogAnalyticsDataSourceWindowsPerformanceCounterRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).LogAnalytics.DataSourcesClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.LogAnalyticsDataSourceID(d.Id()) + if err != nil { + return err + } + + resp, err := client.Get(ctx, id.ResourceGroup, id.Workspace, id.Name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[DEBUG] Log Analytics DataSource Windows Performance Counter %q was not found in Resource Group %q in Workspace %q - removing from state!", id.Name, id.ResourceGroup, id.Workspace) + d.SetId("") + return nil + } + + return fmt.Errorf("failed to retrieve Log Analytics DataSource Windows Performance Counter %q (Resource Group %q / Workspace: %q): %+v", id.Name, id.ResourceGroup, id.Workspace, err) + } + + d.Set("name", resp.Name) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("workspace_name", id.Workspace) + if props := resp.Properties; props != nil { + propStr, err := structure.FlattenJsonToString(props.(map[string]interface{})) + if err != nil { + return fmt.Errorf("failed to flatten properties map to json for Log Analytics DataSource Windows Performance Counter %q (Resource Group %q / Workspace: %q): %+v", id.Name, id.ResourceGroup, id.Workspace, err) + } + + prop := &dataSourceWindowsPerformanceCounterProperty{} + if err := json.Unmarshal([]byte(propStr), &prop); err != nil { + return fmt.Errorf("failed to decode properties json for Log Analytics DataSource Windows Performance Counter %q (Resource Group %q / Workspace: %q): %+v", id.Name, id.ResourceGroup, id.Workspace, err) + } + + d.Set("counter_name", prop.CounterName) + d.Set("instance_name", prop.InstanceName) + d.Set("interval_seconds", prop.IntervalSeconds) + d.Set("object_name", prop.ObjectName) + } + + return nil +} + +func resourceArmLogAnalyticsDataSourceWindowsPerformanceCounterDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).LogAnalytics.DataSourcesClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.LogAnalyticsDataSourceID(d.Id()) + if err != nil { + return err + } + + if _, err := client.Delete(ctx, id.ResourceGroup, id.Workspace, id.Name); err != nil { + return fmt.Errorf("failed to delete Log Analytics DataSource Windows Performance Counter %q (Resource Group %q / Workspace: %q): %+v", id.Name, id.ResourceGroup, id.Workspace, err) + } + + return nil +} diff --git a/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_datasource_windows_performance_counter_test.go b/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_datasource_windows_performance_counter_test.go new file mode 100644 index 000000000000..c87bcf91091f --- /dev/null +++ b/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_datasource_windows_performance_counter_test.go @@ -0,0 +1,235 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/loganalytics/parse" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMLogAnalyticsDataSourceWindowsPerformanceCounter_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_log_analytics_datasource_windows_performance_counter", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMLogAnalyticsDataSourceWindowsPerformanceCounterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMLogAnalyticsDataSourceWindowsPerformanceCounter_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogAnalyticsDataSourceWindowsPerformanceCounterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "object_name", "CPU"), + resource.TestCheckResourceAttr(data.ResourceName, "instance_name", "*"), + resource.TestCheckResourceAttr(data.ResourceName, "counter_name", "CPU"), + resource.TestCheckResourceAttr(data.ResourceName, "interval_seconds", "10"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMLogAnalyticsDataSourceWindowsPerformanceCounter_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_log_analytics_datasource_windows_performance_counter", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMLogAnalyticsDataSourceWindowsPerformanceCounterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMLogAnalyticsDataSourceWindowsPerformanceCounter_complete(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogAnalyticsDataSourceWindowsPerformanceCounterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "object_name", "Mem"), + resource.TestCheckResourceAttr(data.ResourceName, "instance_name", "inst1"), + resource.TestCheckResourceAttr(data.ResourceName, "counter_name", "Mem"), + resource.TestCheckResourceAttr(data.ResourceName, "interval_seconds", "20"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMLogAnalyticsDataSourceWindowsPerformanceCounter_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_log_analytics_datasource_windows_performance_counter", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMLogAnalyticsDataSourceWindowsPerformanceCounterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMLogAnalyticsDataSourceWindowsPerformanceCounter_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogAnalyticsDataSourceWindowsPerformanceCounterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "object_name", "CPU"), + resource.TestCheckResourceAttr(data.ResourceName, "instance_name", "*"), + resource.TestCheckResourceAttr(data.ResourceName, "counter_name", "CPU"), + resource.TestCheckResourceAttr(data.ResourceName, "interval_seconds", "10"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMLogAnalyticsDataSourceWindowsPerformanceCounter_complete(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogAnalyticsDataSourceWindowsPerformanceCounterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "object_name", "Mem"), + resource.TestCheckResourceAttr(data.ResourceName, "instance_name", "inst1"), + resource.TestCheckResourceAttr(data.ResourceName, "counter_name", "Mem"), + resource.TestCheckResourceAttr(data.ResourceName, "interval_seconds", "20"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMLogAnalyticsDataSourceWindowsPerformanceCounter_requiresImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_log_analytics_datasource_windows_performance_counter", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMLogAnalyticsDataSourceWindowsPerformanceCounterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMLogAnalyticsDataSourceWindowsPerformanceCounter_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogAnalyticsDataSourceWindowsPerformanceCounterExists(data.ResourceName), + ), + }, + data.RequiresImportErrorStep(testAccAzureRMLogAnalyticsDataSourceWindowsPerformanceCounter_requiresImport), + }, + }) +} + +func testCheckAzureRMLogAnalyticsDataSourceWindowsPerformanceCounterExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).LogAnalytics.DataSourcesClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Log Analytics Data Source Windows Performance Counter not found: %s", resourceName) + } + + id, err := parse.LogAnalyticsDataSourceID(rs.Primary.ID) + if err != nil { + return err + } + + if resp, err := client.Get(ctx, id.ResourceGroup, id.Workspace, id.Name); err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Log Analytics Data Source Windows Performance Counter %q (Resource Group %q) does not exist", id.Name, id.ResourceGroup) + } + return fmt.Errorf("failed to get on LogAnalytics.DataSourcesClient: %+v", err) + } + + return nil + } +} + +func testCheckAzureRMLogAnalyticsDataSourceWindowsPerformanceCounterDestroy(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).LogAnalytics.DataSourcesClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_log_analytics_datasource_windows_performance_counter" { + continue + } + + id, err := parse.LogAnalyticsDataSourceID(rs.Primary.ID) + if err != nil { + return err + } + + if resp, err := client.Get(ctx, id.ResourceGroup, id.Workspace, id.Name); err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("failed to get on LogAnalytics.DataSourcesClient: %+v", err) + } + } + + return nil + } + + return nil +} + +func testAccAzureRMLogAnalyticsDataSourceWindowsPerformanceCounter_basic(data acceptance.TestData) string { + template := testAccAzureRMLogAnalyticsDataSourceWindowsPerformanceCounter_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_log_analytics_datasource_windows_performance_counter" "test" { + name = "acctestLADS-WPC-%d" + resource_group_name = azurerm_resource_group.test.name + workspace_name = azurerm_log_analytics_workspace.test.name + object_name = "CPU" + instance_name = "*" + counter_name = "CPU" + interval_seconds = 10 +} +`, template, data.RandomInteger) +} + +func testAccAzureRMLogAnalyticsDataSourceWindowsPerformanceCounter_complete(data acceptance.TestData) string { + template := testAccAzureRMLogAnalyticsDataSourceWindowsPerformanceCounter_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_log_analytics_datasource_windows_performance_counter" "test" { + name = "acctestLADS-WPC-%d" + resource_group_name = azurerm_resource_group.test.name + workspace_name = azurerm_log_analytics_workspace.test.name + object_name = "Mem" + instance_name = "inst1" + counter_name = "Mem" + interval_seconds = 20 +} +`, template, data.RandomInteger) +} + +func testAccAzureRMLogAnalyticsDataSourceWindowsPerformanceCounter_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMLogAnalyticsDataSourceWindowsPerformanceCounter_basic(data) + return fmt.Sprintf(` +%s + +resource "azurerm_log_analytics_datasource_windows_performance_counter" "import" { + name = azurerm_log_analytics_datasource_windows_performance_counter.test.name + resource_group_name = azurerm_log_analytics_datasource_windows_performance_counter.test.resource_group_name + workspace_name = azurerm_log_analytics_datasource_windows_performance_counter.test.workspace_name + object_name = azurerm_log_analytics_datasource_windows_performance_counter.test.object_name + instance_name = azurerm_log_analytics_datasource_windows_performance_counter.test.instance_name + counter_name = azurerm_log_analytics_datasource_windows_performance_counter.test.counter_name + interval_seconds = azurerm_log_analytics_datasource_windows_performance_counter.test.interval_seconds +} +`, template) +} + +func testAccAzureRMLogAnalyticsDataSourceWindowsPerformanceCounter_template(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-la-%d" + location = "%s" +} + +resource "azurerm_log_analytics_workspace" "test" { + name = "acctestLAW-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "PerGB2018" +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} diff --git a/website/azurerm.erb b/website/azurerm.erb index f27f0b204dd8..948f19adab55 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -1567,6 +1567,10 @@
  • Log Analytics Resources