From 9004404a2eccbac676f7d201d8732e981f7f503f Mon Sep 17 00:00:00 2001 From: Lawrence Gripper Date: Wed, 7 Mar 2018 17:36:26 +0000 Subject: [PATCH 01/10] Initial work on Log Analytics solutions provider --- azurerm/config.go | 38 +- azurerm/provider.go | 1 + .../resource_arm_log_analytics_solution.go | 196 ++++++++ ...esource_arm_log_analytics_solution_test.go | 133 ++++++ .../operationsmanagement/client.go | 57 +++ .../managementassociations.go | 341 ++++++++++++++ .../managementconfigurations.go | 336 ++++++++++++++ .../operationsmanagement/models.go | 183 ++++++++ .../operationsmanagement/operations.go | 98 ++++ .../operationsmanagement/solutions.go | 419 ++++++++++++++++++ .../operationsmanagement/version.go | 28 ++ vendor/vendor.json | 6 + 12 files changed, 1835 insertions(+), 1 deletion(-) create mode 100644 azurerm/resource_arm_log_analytics_solution.go create mode 100644 azurerm/resource_arm_log_analytics_solution_test.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/client.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/managementassociations.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/managementconfigurations.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/models.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/operations.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/solutions.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/version.go diff --git a/azurerm/config.go b/azurerm/config.go index 82fa2a54fb62..16ead67892e0 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -29,6 +29,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/mysql/mgmt/2017-04-30-preview/mysql" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2017-09-01/network" "github.com/Azure/azure-sdk-for-go/services/operationalinsights/mgmt/2015-11-01-preview/operationalinsights" + "github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement" "github.com/Azure/azure-sdk-for-go/services/postgresql/mgmt/2017-04-30-preview/postgresql" "github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2016-04-01/redis" "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2016-06-01/subscriptions" @@ -82,6 +83,7 @@ type ArmClient struct { eventHubNamespacesClient eventhub.NamespacesClient workspacesClient operationalinsights.WorkspacesClient + solutionsClient operationsmanagement.SolutionsClient redisClient redis.Client redisFirewallClient redis.FirewallRuleClient @@ -736,7 +738,41 @@ func (c *ArmClient) registerOperationalInsightsClients(endpoint, subscriptionId opwc := operationalinsights.NewWorkspacesClient(subscriptionId) c.configureClient(&opwc.Client, auth) c.workspacesClient = opwc -} + + solutionsClient := operationsmanagement.NewSolutionsClient(subscriptionId, "Microsoft.OperationsManagement", "solutions", "testing") + c.configureClient(&solutionsClient.Client, auth) + c.solutionsClient = solutionsClient + // c.solutionsClient.RequestInspector = LogRequestPreparer() + // c.solutionsClient.ResponseInspector = LogResponseDecorator() +} + +// func LogRequestPreparer() autorest.PrepareDecorator { +// return func(p autorest.Preparer) autorest.Preparer { +// return autorest.PreparerFunc(func(r *http.Request) (*http.Request, error) { +// // resDump, _ := httputil.DumpRequestOut(r, true) +// // log.Println(string(resDump)) +// // return r, nil + +// r, err := p.Prepare(r) +// if err == nil { +// resDump, _ := httputil.DumpRequestOut(r, true) +// log.Println(string(resDump)) +// } +// return r, err +// }) +// } +// } + +// func LogResponseDecorator() autorest.RespondDecorator { +// return func(p autorest.Responder) autorest.Responder { +// return autorest.ResponderFunc(func(r *http.Response) error { +// _ = p.Respond(r) +// dump, _ := httputil.DumpResponse(r, true) +// log.Println(string(dump)) +// return nil +// }) +// } +// } func (c *ArmClient) registerRedisClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) { redisClient := redis.NewClientWithBaseURI(endpoint, subscriptionId) diff --git a/azurerm/provider.go b/azurerm/provider.go index b7ac20ac2fee..580175cbda9b 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -151,6 +151,7 @@ func Provider() terraform.ResourceProvider { "azurerm_lb_rule": resourceArmLoadBalancerRule(), "azurerm_local_network_gateway": resourceArmLocalNetworkGateway(), "azurerm_log_analytics_workspace": resourceArmLogAnalyticsWorkspace(), + "azurerm_log_analytics_solution": resourceArmLogAnalyticsSolution(), "azurerm_managed_disk": resourceArmManagedDisk(), "azurerm_management_lock": resourceArmManagementLock(), "azurerm_metric_alertrule": resourceArmMetricAlertRule(), diff --git a/azurerm/resource_arm_log_analytics_solution.go b/azurerm/resource_arm_log_analytics_solution.go new file mode 100644 index 000000000000..9cd572323669 --- /dev/null +++ b/azurerm/resource_arm_log_analytics_solution.go @@ -0,0 +1,196 @@ +package azurerm + +import ( + "fmt" + "log" + + "github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement" + + "github.com/hashicorp/terraform/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmLogAnalyticsSolution() *schema.Resource { + return &schema.Resource{ + Create: resourceArmLogAnalyticsSolutionCreateUpdate, + Read: resourceArmLogAnalyticsSolutionRead, + Update: resourceArmLogAnalyticsSolutionCreateUpdate, + Delete: resourceArmLogAnalyticsSolutionDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "location": locationSchema(), + + "resource_group_name": resourceGroupNameDiffSuppressSchema(), + + "plan": { + Type: schema.TypeList, + Required: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + "publisher": { + Type: schema.TypeString, + Required: true, + }, + "promotion_code": { + Type: schema.TypeString, + Optional: true, + }, + "product": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + }, + + "workspace_resource_id": { + Type: schema.TypeString, + Required: true, + }, + }, + } +} + +func resourceArmLogAnalyticsSolutionCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).solutionsClient + ctx := meta.(*ArmClient).StopContext + log.Printf("[INFO] preparing arguments for AzureRM Log Analytics solution creation.") + + name := d.Get("name").(string) + location := d.Get("location").(string) + resGroup := d.Get("resource_group_name").(string) + workspaceID := d.Get("workspace_resource_id").(string) + + solutionPlan := expandAzureRmLogAnalyticsSolutionPlan(d) + + parameters := operationsmanagement.Solution{ + Name: &name, + Location: &location, + Plan: &solutionPlan, + Properties: &operationsmanagement.SolutionProperties{ + WorkspaceResourceID: &workspaceID, + }, + } + + solution, err := client.CreateOrUpdate(ctx, resGroup, name, parameters) + if err != nil { + return err + } + + if solution.ID == nil { + return fmt.Errorf("Cannot read Log Analytics Solution '%s' (resource group %s) ID", name, resGroup) + } + + d.SetId(*solution.ID) + + return resourceArmLogAnalyticsSolutionRead(d, meta) + +} + +func resourceArmLogAnalyticsSolutionRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).solutionsClient + ctx := meta.(*ArmClient).StopContext + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resGroup := id.ResourceGroup + name := id.Path["solutions"] + + resp, err := client.Get(ctx, resGroup, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + d.SetId("") + return nil + } + return fmt.Errorf("Error making Read request on AzureRM Log Analytics solutions '%s': %+v", name, err) + } + + if resp.Plan == nil { + return fmt.Errorf("Error making Read request on AzureRM Log Analytics solutions '%s': %+v Plan was nil", name, err) + } + + d.Set("name", resp.Name) + d.Set("location", resp.Location) + d.Set("resource_group_name", resGroup) + d.Set("workspace_resource_id", resp.ID) + d.Set("plan", flattenAzureRmLogAnalyticsSolutionPlan(*resp.Plan)) + return nil +} + +func resourceArmLogAnalyticsSolutionDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).solutionsClient + ctx := meta.(*ArmClient).StopContext + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resGroup := id.ResourceGroup + name := id.Path["solutions"] + + resp, err := client.Delete(ctx, resGroup, name) + + if err != nil { + if utils.ResponseWasNotFound(resp) { + return nil + } + + return fmt.Errorf("Error issuing AzureRM delete request for Log Analytics Solution '%s': %+v", name, err) + } + + return nil +} + +func expandAzureRmLogAnalyticsSolutionPlan(d *schema.ResourceData) operationsmanagement.SolutionPlan { + plans := d.Get("plan").([]interface{}) + plan := plans[0].(map[string]interface{}) + + expandedPlan := operationsmanagement.SolutionPlan{} + + if name := plan["name"].(string); len(name) > 0 { + expandedPlan.Name = &name + } + + if publisher := plan["publisher"].(string); len(publisher) > 0 { + expandedPlan.Publisher = &publisher + } + + if promotionCode := plan["promotion_code"].(string); len(promotionCode) > 0 { + expandedPlan.PromotionCode = &promotionCode + } else { + blankString := "" + expandedPlan.PromotionCode = &blankString + } + + if product := plan["product"].(string); len(product) > 0 { + expandedPlan.Product = &product + } + + return expandedPlan +} + +func flattenAzureRmLogAnalyticsSolutionPlan(plan operationsmanagement.SolutionPlan) []interface{} { + plans := make([]interface{}, 0) + values := make(map[string]interface{}) + + values["name"] = *plan.Name + values["product"] = *plan.Product + values["promotion_code"] = *plan.PromotionCode + values["publisher"] = *plan.Publisher + + return append(plans, values) +} diff --git a/azurerm/resource_arm_log_analytics_solution_test.go b/azurerm/resource_arm_log_analytics_solution_test.go new file mode 100644 index 000000000000..f8e027fc5a02 --- /dev/null +++ b/azurerm/resource_arm_log_analytics_solution_test.go @@ -0,0 +1,133 @@ +package azurerm + +import ( + "fmt" + "net/http" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccAzureRMLogAnalyticsSolution(t *testing.T) { + ri := acctest.RandInt() + // config := testAccAzureRMLogAnalyticsSolution(ri, testLocation()) + config := testAccAzureRMLogAnalyticsSolution(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMLogAnalyticsWorkspaceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogAnalyticsWorkspaceExists("azurerm_log_analytics_workspace.test"), + ), + }, + }, + }) +} + +func testCheckAzureRMLogAnalyticsSolutionDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*ArmClient).solutionsClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_log_analytics_solution" { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := conn.Get(ctx, resourceGroup, name) + + if err != nil { + return nil + } + + if resp.StatusCode != http.StatusNotFound { + return fmt.Errorf("Log Analytics solution still exists:\n%#v", resp) + } + } + + return nil +} + +func testCheckAzureRMLogAnalyticsSolutionExists(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + name := rs.Primary.Attributes["name"] + resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] + if !hasResourceGroup { + return fmt.Errorf("Bad: no resource group found in state for Log Analytics Workspace: '%s'", name) + } + + conn := testAccProvider.Meta().(*ArmClient).solutionsClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + resp, err := conn.Get(ctx, resourceGroup, name) + if err != nil { + return fmt.Errorf("Bad: Get on Log Analytics Solutions Client: %+v", err) + } + + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Bad: Log Analytics Solutions '%s' (resource group: '%s') does not exist", name, resourceGroup) + } + + return nil + } +} + +func testAccAzureRMLogAnalyticsSolution(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "oms-acctestRG-%d" + location = "%s" +} + +resource "azurerm_log_analytics_workspace" "workspace" { + name = "acctest-dep-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + sku = "Free" +} + +resource "azurerm_log_analytics_solution" "solution" { + name = "acctest-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + workspace_resource_id = "${azurerm_log_analytics_workspace.workspace.id}" + + plan { + name = "Containers" + publisher = "Microsoft" + product = "OMSGallery/Containers" + } +} +`, rInt, location, rInt, rInt) +} + +func testAccAzureRMLogAnalyticsSolution_Temp(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_log_analytics_solution" "solution" { + name = "acctest" + location = "westeurope" + resource_group_name = "lg-terraformtest" + workspace_resource_id = "/subscriptions/5774ad8f-d51e-4456-a72e-0447910568d3/resourcegroups/acctestrg-8930075193794579467/providers/microsoft.operationalinsights/workspaces/acctest-dep-8930075193794579467" + + plan { + name = "Containers" + publisher = "Microsoft" + promotion_code = "" + product = "OMSGallery/Containers" + } +} +`) +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/client.go b/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/client.go new file mode 100644 index 000000000000..819be16528c8 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/client.go @@ -0,0 +1,57 @@ +// Package operationsmanagement implements the Azure ARM Operationsmanagement service API version 2015-11-01-preview. +// +// Operations Management Client +package operationsmanagement + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" +) + +const ( + // DefaultBaseURI is the default URI used for the service Operationsmanagement + DefaultBaseURI = "https://management.azure.com" +) + +// BaseClient is the base client for Operationsmanagement. +type BaseClient struct { + autorest.Client + BaseURI string + SubscriptionID string + ProviderName string + ResourceType string + ResourceName string +} + +// New creates an instance of the BaseClient client. +func New(subscriptionID string, providerName string, resourceType string, resourceName string) BaseClient { + return NewWithBaseURI(DefaultBaseURI, subscriptionID, providerName, resourceType, resourceName) +} + +// NewWithBaseURI creates an instance of the BaseClient client. +func NewWithBaseURI(baseURI string, subscriptionID string, providerName string, resourceType string, resourceName string) BaseClient { + return BaseClient{ + Client: autorest.NewClientWithUserAgent(UserAgent()), + BaseURI: baseURI, + SubscriptionID: subscriptionID, + ProviderName: providerName, + ResourceType: resourceType, + ResourceName: resourceName, + } +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/managementassociations.go b/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/managementassociations.go new file mode 100644 index 000000000000..4d8c8d9072ef --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/managementassociations.go @@ -0,0 +1,341 @@ +package operationsmanagement + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "net/http" +) + +// ManagementAssociationsClient is the operations Management Client +type ManagementAssociationsClient struct { + BaseClient +} + +// NewManagementAssociationsClient creates an instance of the ManagementAssociationsClient client. +func NewManagementAssociationsClient(subscriptionID string, providerName string, resourceType string, resourceName string) ManagementAssociationsClient { + return NewManagementAssociationsClientWithBaseURI(DefaultBaseURI, subscriptionID, providerName, resourceType, resourceName) +} + +// NewManagementAssociationsClientWithBaseURI creates an instance of the ManagementAssociationsClient client. +func NewManagementAssociationsClientWithBaseURI(baseURI string, subscriptionID string, providerName string, resourceType string, resourceName string) ManagementAssociationsClient { + return ManagementAssociationsClient{NewWithBaseURI(baseURI, subscriptionID, providerName, resourceType, resourceName)} +} + +// CreateOrUpdate creates or updates the ManagementAssociation. +// +// resourceGroupName is the name of the resource group to get. The name is case insensitive. managementAssociationName +// is user ManagementAssociation Name. parameters is the parameters required to create ManagementAssociation extension. +func (client ManagementAssociationsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, managementAssociationName string, parameters ManagementAssociation) (result ManagementAssociation, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, + {TargetValue: parameters, + Constraints: []validation.Constraint{{Target: "parameters.Properties", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "parameters.Properties.ApplicationID", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil { + return result, validation.NewErrorWithValidationError(err, "operationsmanagement.ManagementAssociationsClient", "CreateOrUpdate") + } + + req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, managementAssociationName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.ManagementAssociationsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "operationsmanagement.ManagementAssociationsClient", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.ManagementAssociationsClient", "CreateOrUpdate", resp, "Failure responding to request") + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client ManagementAssociationsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, managementAssociationName string, parameters ManagementAssociation) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "managementAssociationName": autorest.Encode("path", managementAssociationName), + "providerName": autorest.Encode("path", client.ProviderName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "resourceName": autorest.Encode("path", client.ResourceName), + "resourceType": autorest.Encode("path", client.ResourceType), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsJSON(), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{providerName}/{resourceType}/{resourceName}/providers/Microsoft.OperationsManagement/ManagementAssociations/{managementAssociationName}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client ManagementAssociationsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client ManagementAssociationsClient) CreateOrUpdateResponder(resp *http.Response) (result ManagementAssociation, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete deletes the ManagementAssociation in the subscription. +// +// resourceGroupName is the name of the resource group to get. The name is case insensitive. managementAssociationName +// is user ManagementAssociation Name. +func (client ManagementAssociationsClient) Delete(ctx context.Context, resourceGroupName string, managementAssociationName string) (result autorest.Response, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { + return result, validation.NewErrorWithValidationError(err, "operationsmanagement.ManagementAssociationsClient", "Delete") + } + + req, err := client.DeletePreparer(ctx, resourceGroupName, managementAssociationName) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.ManagementAssociationsClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "operationsmanagement.ManagementAssociationsClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.ManagementAssociationsClient", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client ManagementAssociationsClient) DeletePreparer(ctx context.Context, resourceGroupName string, managementAssociationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "managementAssociationName": autorest.Encode("path", managementAssociationName), + "providerName": autorest.Encode("path", client.ProviderName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "resourceName": autorest.Encode("path", client.ResourceName), + "resourceType": autorest.Encode("path", client.ResourceType), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{providerName}/{resourceType}/{resourceName}/providers/Microsoft.OperationsManagement/ManagementAssociations/{managementAssociationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client ManagementAssociationsClient) DeleteSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client ManagementAssociationsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get retrieves the user ManagementAssociation. +// +// resourceGroupName is the name of the resource group to get. The name is case insensitive. managementAssociationName +// is user ManagementAssociation Name. +func (client ManagementAssociationsClient) Get(ctx context.Context, resourceGroupName string, managementAssociationName string) (result ManagementAssociation, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { + return result, validation.NewErrorWithValidationError(err, "operationsmanagement.ManagementAssociationsClient", "Get") + } + + req, err := client.GetPreparer(ctx, resourceGroupName, managementAssociationName) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.ManagementAssociationsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "operationsmanagement.ManagementAssociationsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.ManagementAssociationsClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client ManagementAssociationsClient) GetPreparer(ctx context.Context, resourceGroupName string, managementAssociationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "managementAssociationName": autorest.Encode("path", managementAssociationName), + "providerName": autorest.Encode("path", client.ProviderName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "resourceName": autorest.Encode("path", client.ResourceName), + "resourceType": autorest.Encode("path", client.ResourceType), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{providerName}/{resourceType}/{resourceName}/providers/Microsoft.OperationsManagement/ManagementAssociations/{managementAssociationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client ManagementAssociationsClient) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client ManagementAssociationsClient) GetResponder(resp *http.Response) (result ManagementAssociation, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListBySubscription retrieves the ManagementAssociatons list. +func (client ManagementAssociationsClient) ListBySubscription(ctx context.Context) (result ManagementAssociationPropertiesList, err error) { + req, err := client.ListBySubscriptionPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.ManagementAssociationsClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + resp, err := client.ListBySubscriptionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "operationsmanagement.ManagementAssociationsClient", "ListBySubscription", resp, "Failure sending request") + return + } + + result, err = client.ListBySubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.ManagementAssociationsClient", "ListBySubscription", resp, "Failure responding to request") + } + + return +} + +// ListBySubscriptionPreparer prepares the ListBySubscription request. +func (client ManagementAssociationsClient) ListBySubscriptionPreparer(ctx context.Context) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.OperationsManagement/ManagementAssociations", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListBySubscriptionSender sends the ListBySubscription request. The method will close the +// http.Response Body if it receives an error. +func (client ManagementAssociationsClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always +// closes the http.Response Body. +func (client ManagementAssociationsClient) ListBySubscriptionResponder(resp *http.Response) (result ManagementAssociationPropertiesList, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/managementconfigurations.go b/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/managementconfigurations.go new file mode 100644 index 000000000000..a53e64067617 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/managementconfigurations.go @@ -0,0 +1,336 @@ +package operationsmanagement + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "net/http" +) + +// ManagementConfigurationsClient is the operations Management Client +type ManagementConfigurationsClient struct { + BaseClient +} + +// NewManagementConfigurationsClient creates an instance of the ManagementConfigurationsClient client. +func NewManagementConfigurationsClient(subscriptionID string, providerName string, resourceType string, resourceName string) ManagementConfigurationsClient { + return NewManagementConfigurationsClientWithBaseURI(DefaultBaseURI, subscriptionID, providerName, resourceType, resourceName) +} + +// NewManagementConfigurationsClientWithBaseURI creates an instance of the ManagementConfigurationsClient client. +func NewManagementConfigurationsClientWithBaseURI(baseURI string, subscriptionID string, providerName string, resourceType string, resourceName string) ManagementConfigurationsClient { + return ManagementConfigurationsClient{NewWithBaseURI(baseURI, subscriptionID, providerName, resourceType, resourceName)} +} + +// CreateOrUpdate creates or updates the ManagementConfiguration. +// +// resourceGroupName is the name of the resource group to get. The name is case insensitive. +// managementConfigurationName is user Management Configuration Name. parameters is the parameters required to create +// OMS Solution. +func (client ManagementConfigurationsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, managementConfigurationName string, parameters ManagementConfiguration) (result ManagementConfiguration, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, + {TargetValue: parameters, + Constraints: []validation.Constraint{{Target: "parameters.Properties", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "parameters.Properties.ParentResourceType", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "parameters.Properties.Parameters", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "parameters.Properties.Template", Name: validation.Null, Rule: true, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewErrorWithValidationError(err, "operationsmanagement.ManagementConfigurationsClient", "CreateOrUpdate") + } + + req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, managementConfigurationName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.ManagementConfigurationsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "operationsmanagement.ManagementConfigurationsClient", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.ManagementConfigurationsClient", "CreateOrUpdate", resp, "Failure responding to request") + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client ManagementConfigurationsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, managementConfigurationName string, parameters ManagementConfiguration) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "managementConfigurationName": autorest.Encode("path", managementConfigurationName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsJSON(), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.OperationsManagement/ManagementConfigurations/{managementConfigurationName}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client ManagementConfigurationsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client ManagementConfigurationsClient) CreateOrUpdateResponder(resp *http.Response) (result ManagementConfiguration, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete deletes the ManagementConfiguration in the subscription. +// +// resourceGroupName is the name of the resource group to get. The name is case insensitive. +// managementConfigurationName is user Management Configuration Name. +func (client ManagementConfigurationsClient) Delete(ctx context.Context, resourceGroupName string, managementConfigurationName string) (result autorest.Response, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { + return result, validation.NewErrorWithValidationError(err, "operationsmanagement.ManagementConfigurationsClient", "Delete") + } + + req, err := client.DeletePreparer(ctx, resourceGroupName, managementConfigurationName) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.ManagementConfigurationsClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "operationsmanagement.ManagementConfigurationsClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.ManagementConfigurationsClient", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client ManagementConfigurationsClient) DeletePreparer(ctx context.Context, resourceGroupName string, managementConfigurationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "managementConfigurationName": autorest.Encode("path", managementConfigurationName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.OperationsManagement/ManagementConfigurations/{managementConfigurationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client ManagementConfigurationsClient) DeleteSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client ManagementConfigurationsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get retrieves the user ManagementConfiguration. +// +// resourceGroupName is the name of the resource group to get. The name is case insensitive. +// managementConfigurationName is user Management Configuration Name. +func (client ManagementConfigurationsClient) Get(ctx context.Context, resourceGroupName string, managementConfigurationName string) (result ManagementConfiguration, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { + return result, validation.NewErrorWithValidationError(err, "operationsmanagement.ManagementConfigurationsClient", "Get") + } + + req, err := client.GetPreparer(ctx, resourceGroupName, managementConfigurationName) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.ManagementConfigurationsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "operationsmanagement.ManagementConfigurationsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.ManagementConfigurationsClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client ManagementConfigurationsClient) GetPreparer(ctx context.Context, resourceGroupName string, managementConfigurationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "managementConfigurationName": autorest.Encode("path", managementConfigurationName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.OperationsManagement/ManagementConfigurations/{managementConfigurationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client ManagementConfigurationsClient) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client ManagementConfigurationsClient) GetResponder(resp *http.Response) (result ManagementConfiguration, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListBySubscription retrieves the ManagementConfigurations list. +func (client ManagementConfigurationsClient) ListBySubscription(ctx context.Context) (result ManagementConfigurationPropertiesList, err error) { + req, err := client.ListBySubscriptionPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.ManagementConfigurationsClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + resp, err := client.ListBySubscriptionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "operationsmanagement.ManagementConfigurationsClient", "ListBySubscription", resp, "Failure sending request") + return + } + + result, err = client.ListBySubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.ManagementConfigurationsClient", "ListBySubscription", resp, "Failure responding to request") + } + + return +} + +// ListBySubscriptionPreparer prepares the ListBySubscription request. +func (client ManagementConfigurationsClient) ListBySubscriptionPreparer(ctx context.Context) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.OperationsManagement/ManagementConfigurations", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListBySubscriptionSender sends the ListBySubscription request. The method will close the +// http.Response Body if it receives an error. +func (client ManagementConfigurationsClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always +// closes the http.Response Body. +func (client ManagementConfigurationsClient) ListBySubscriptionResponder(resp *http.Response) (result ManagementConfigurationPropertiesList, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/models.go b/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/models.go new file mode 100644 index 000000000000..aa5e5a2114af --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/models.go @@ -0,0 +1,183 @@ +package operationsmanagement + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" +) + +// ArmTemplateParameter parameter to pass to ARM template +type ArmTemplateParameter struct { + // Name - name of the parameter. + Name *string `json:"name,omitempty"` + // Value - value for the parameter. In Jtoken + Value *string `json:"value,omitempty"` +} + +// CodeMessageError the error body contract. +type CodeMessageError struct { + // Error - The error details for a failed request. + Error *CodeMessageErrorError `json:"error,omitempty"` +} + +// CodeMessageErrorError the error details for a failed request. +type CodeMessageErrorError struct { + // Code - The error type. + Code *string `json:"code,omitempty"` + // Message - The error message. + Message *string `json:"message,omitempty"` +} + +// ManagementAssociation the container for solution. +type ManagementAssociation struct { + autorest.Response `json:"-"` + // ID - Resource ID. + ID *string `json:"id,omitempty"` + // Name - Resource name. + Name *string `json:"name,omitempty"` + // Type - Resource type. + Type *string `json:"type,omitempty"` + // Location - Resource location + Location *string `json:"location,omitempty"` + // Properties - Properties for ManagementAssociation object supported by the OperationsManagement resource provider. + Properties *ManagementAssociationProperties `json:"properties,omitempty"` +} + +// ManagementAssociationProperties managementAssociation properties supported by the OperationsManagement resource +// provider. +type ManagementAssociationProperties struct { + // ApplicationID - The applicationId of the appliance for this association. + ApplicationID *string `json:"applicationId,omitempty"` +} + +// ManagementAssociationPropertiesList the list of ManagementAssociation response +type ManagementAssociationPropertiesList struct { + autorest.Response `json:"-"` + // Value - List of Management Association properites within the subscription. + Value *[]ManagementAssociation `json:"value,omitempty"` +} + +// ManagementConfiguration the container for solution. +type ManagementConfiguration struct { + autorest.Response `json:"-"` + // ID - Resource ID. + ID *string `json:"id,omitempty"` + // Name - Resource name. + Name *string `json:"name,omitempty"` + // Type - Resource type. + Type *string `json:"type,omitempty"` + // Location - Resource location + Location *string `json:"location,omitempty"` + // Properties - Properties for ManagementConfiguration object supported by the OperationsManagement resource provider. + Properties *ManagementConfigurationProperties `json:"properties,omitempty"` +} + +// ManagementConfigurationProperties managementConfiguration properties supported by the OperationsManagement resource +// provider. +type ManagementConfigurationProperties struct { + // ApplicationID - The applicationId of the appliance for this Management. + ApplicationID *string `json:"applicationId,omitempty"` + // ParentResourceType - The type of the parent resource. + ParentResourceType *string `json:"parentResourceType,omitempty"` + // Parameters - Parameters to run the ARM template + Parameters *[]ArmTemplateParameter `json:"parameters,omitempty"` + // ProvisioningState - The provisioning state for the ManagementConfiguration. + ProvisioningState *string `json:"provisioningState,omitempty"` + // Template - The Json object containing the ARM template to deploy + Template *map[string]interface{} `json:"template,omitempty"` +} + +// ManagementConfigurationPropertiesList the list of ManagementConfiguration response +type ManagementConfigurationPropertiesList struct { + autorest.Response `json:"-"` + // Value - List of Management Configuration properites within the subscription. + Value *[]ManagementConfiguration `json:"value,omitempty"` +} + +// Operation supported operation of OperationsManagement resource provider. +type Operation struct { + // Name - Operation name: {provider}/{resource}/{operation} + Name *string `json:"name,omitempty"` + // Display - Display metadata associated with the operation. + Display *OperationDisplay `json:"display,omitempty"` +} + +// OperationDisplay display metadata associated with the operation. +type OperationDisplay struct { + // Provider - Service provider: Microsoft OperationsManagement. + Provider *string `json:"provider,omitempty"` + // Resource - Resource on which the operation is performed etc. + Resource *string `json:"resource,omitempty"` + // Operation - Type of operation: get, read, delete, etc. + Operation *string `json:"operation,omitempty"` +} + +// OperationListResult result of the request to list solution operations. +type OperationListResult struct { + autorest.Response `json:"-"` + // Value - List of solution operations supported by the OperationsManagement resource provider. + Value *[]Operation `json:"value,omitempty"` +} + +// Solution the container for solution. +type Solution struct { + autorest.Response `json:"-"` + // ID - Resource ID. + ID *string `json:"id,omitempty"` + // Name - Resource name. + Name *string `json:"name,omitempty"` + // Type - Resource type. + Type *string `json:"type,omitempty"` + // Location - Resource location + Location *string `json:"location,omitempty"` + // Plan - Plan for solution object supported by the OperationsManagement resource provider. + Plan *SolutionPlan `json:"plan,omitempty"` + // Properties - Properties for solution object supported by the OperationsManagement resource provider. + Properties *SolutionProperties `json:"properties,omitempty"` +} + +// SolutionPlan plan for solution object supported by the OperationsManagement resource provider. +type SolutionPlan struct { + // Name - name of the solution to be created. For Microsoft published solution it should be in the format of solutionType(workspaceName). SolutionType part is case sensitive. For third party solution, it can be anything. + Name *string `json:"name,omitempty"` + // Publisher - Publisher name. For gallery solution, it is Microsoft. + Publisher *string `json:"publisher,omitempty"` + // PromotionCode - promotionCode, Not really used now, can you left as empty + PromotionCode *string `json:"promotionCode,omitempty"` + // Product - name of the solution to enabled/add. For Microsoft published gallery solution it should be in the format of OMSGallery/. This is case sensitive + Product *string `json:"product,omitempty"` +} + +// SolutionProperties solution properties supported by the OperationsManagement resource provider. +type SolutionProperties struct { + // WorkspaceResourceID - The azure resourceId for the workspace where the solution will be deployed/enabled. + WorkspaceResourceID *string `json:"workspaceResourceId,omitempty"` + // ProvisioningState - The provisioning state for the solution. + ProvisioningState *string `json:"provisioningState,omitempty"` + // ContainedResources - The azure resources that will be contained within the solutions. They will be locked and gets deleted automatically when the solution is deleted. + ContainedResources *[]string `json:"containedResources,omitempty"` + // ReferencedResources - The resources that will be referenced from this solution. Deleting any of those solution out of band will break the solution. + ReferencedResources *[]string `json:"referencedResources,omitempty"` +} + +// SolutionPropertiesList the list of solution response +type SolutionPropertiesList struct { + autorest.Response `json:"-"` + // Value - List of solution properites within the subscription. + Value *[]Solution `json:"value,omitempty"` +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/operations.go b/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/operations.go new file mode 100644 index 000000000000..f64d685b2d26 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/operations.go @@ -0,0 +1,98 @@ +package operationsmanagement + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "net/http" +) + +// OperationsClient is the operations Management Client +type OperationsClient struct { + BaseClient +} + +// NewOperationsClient creates an instance of the OperationsClient client. +func NewOperationsClient(subscriptionID string, providerName string, resourceType string, resourceName string) OperationsClient { + return NewOperationsClientWithBaseURI(DefaultBaseURI, subscriptionID, providerName, resourceType, resourceName) +} + +// NewOperationsClientWithBaseURI creates an instance of the OperationsClient client. +func NewOperationsClientWithBaseURI(baseURI string, subscriptionID string, providerName string, resourceType string, resourceName string) OperationsClient { + return OperationsClient{NewWithBaseURI(baseURI, subscriptionID, providerName, resourceType, resourceName)} +} + +// List lists all of the available OperationsManagement Rest API operations. +func (client OperationsClient) List(ctx context.Context) (result OperationListResult, err error) { + req, err := client.ListPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.OperationsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "operationsmanagement.OperationsClient", "List", resp, "Failure sending request") + return + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.OperationsClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client OperationsClient) ListPreparer(ctx context.Context) (*http.Request, error) { + const APIVersion = "2015-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPath("/providers/Microsoft.OperationsManagement/operations"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client OperationsClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client OperationsClient) ListResponder(resp *http.Response) (result OperationListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/solutions.go b/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/solutions.go new file mode 100644 index 000000000000..570837913bcb --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/solutions.go @@ -0,0 +1,419 @@ +package operationsmanagement + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" +) + +// SolutionsClient is the operations Management Client +type SolutionsClient struct { + BaseClient +} + +// NewSolutionsClient creates an instance of the SolutionsClient client. +func NewSolutionsClient(subscriptionID string, providerName string, resourceType string, resourceName string) SolutionsClient { + return NewSolutionsClientWithBaseURI(DefaultBaseURI, subscriptionID, providerName, resourceType, resourceName) +} + +// NewSolutionsClientWithBaseURI creates an instance of the SolutionsClient client. +func NewSolutionsClientWithBaseURI(baseURI string, subscriptionID string, providerName string, resourceType string, resourceName string) SolutionsClient { + return SolutionsClient{NewWithBaseURI(baseURI, subscriptionID, providerName, resourceType, resourceName)} +} + +// CreateOrUpdate creates or updates the Solution. +// +// resourceGroupName is the name of the resource group to get. The name is case insensitive. solutionName is user +// Solution Name. parameters is the parameters required to create OMS Solution. +func (client SolutionsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, solutionName string, parameters Solution) (result Solution, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, + {TargetValue: parameters, + Constraints: []validation.Constraint{{Target: "parameters.Properties", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "parameters.Properties.WorkspaceResourceID", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil { + return result, validation.NewErrorWithValidationError(err, "operationsmanagement.SolutionsClient", "CreateOrUpdate") + } + + req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, solutionName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.SolutionsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + // dump, err := httputil.DumpRequest(req, true) + // log.Println(string(dump)) + + // if err != nil { + // panic(err) + // } + // bytes, _ := ioutil.ReadAll(req.Body) + + // stringLength := len(string(bytes)) + // log.Println(stringLength) + // log.Println(string(bytes)) + // log.Println(err) + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "operationsmanagement.SolutionsClient", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.SolutionsClient", "CreateOrUpdate", resp, "Failure responding to request") + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client SolutionsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, solutionName string, parameters Solution) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "solutionName": autorest.Encode("path", solutionName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsJSON(), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.OperationsManagement/solutions/{solutionName}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client SolutionsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client SolutionsClient) CreateOrUpdateResponder(resp *http.Response) (result Solution, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete deletes the solution in the subscription. +// +// resourceGroupName is the name of the resource group to get. The name is case insensitive. solutionName is user +// Solution Name. +func (client SolutionsClient) Delete(ctx context.Context, resourceGroupName string, solutionName string) (result autorest.Response, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { + return result, validation.NewErrorWithValidationError(err, "operationsmanagement.SolutionsClient", "Delete") + } + + req, err := client.DeletePreparer(ctx, resourceGroupName, solutionName) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.SolutionsClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "operationsmanagement.SolutionsClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.SolutionsClient", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client SolutionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, solutionName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "solutionName": autorest.Encode("path", solutionName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.OperationsManagement/solutions/{solutionName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client SolutionsClient) DeleteSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client SolutionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get retrieves the user solution. +// +// resourceGroupName is the name of the resource group to get. The name is case insensitive. solutionName is user +// Solution Name. +func (client SolutionsClient) Get(ctx context.Context, resourceGroupName string, solutionName string) (result Solution, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { + return result, validation.NewErrorWithValidationError(err, "operationsmanagement.SolutionsClient", "Get") + } + + req, err := client.GetPreparer(ctx, resourceGroupName, solutionName) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.SolutionsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "operationsmanagement.SolutionsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.SolutionsClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client SolutionsClient) GetPreparer(ctx context.Context, resourceGroupName string, solutionName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "solutionName": autorest.Encode("path", solutionName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.OperationsManagement/solutions/{solutionName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client SolutionsClient) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client SolutionsClient) GetResponder(resp *http.Response) (result Solution, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListByResourceGroup retrieves the solution list. It will retrieve both first party and third party solutions +// +// resourceGroupName is the name of the resource group to get. The name is case insensitive. +func (client SolutionsClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result SolutionPropertiesList, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { + return result, validation.NewErrorWithValidationError(err, "operationsmanagement.SolutionsClient", "ListByResourceGroup") + } + + req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.SolutionsClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + resp, err := client.ListByResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "operationsmanagement.SolutionsClient", "ListByResourceGroup", resp, "Failure sending request") + return + } + + result, err = client.ListByResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.SolutionsClient", "ListByResourceGroup", resp, "Failure responding to request") + } + + return +} + +// ListByResourceGroupPreparer prepares the ListByResourceGroup request. +func (client SolutionsClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.OperationsManagement/solutions", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client SolutionsClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (client SolutionsClient) ListByResourceGroupResponder(resp *http.Response) (result SolutionPropertiesList, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListBySubscription retrieves the solution list. It will retrieve both first party and third party solutions +func (client SolutionsClient) ListBySubscription(ctx context.Context) (result SolutionPropertiesList, err error) { + req, err := client.ListBySubscriptionPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.SolutionsClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + resp, err := client.ListBySubscriptionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "operationsmanagement.SolutionsClient", "ListBySubscription", resp, "Failure sending request") + return + } + + result, err = client.ListBySubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "operationsmanagement.SolutionsClient", "ListBySubscription", resp, "Failure responding to request") + } + + return +} + +// ListBySubscriptionPreparer prepares the ListBySubscription request. +func (client SolutionsClient) ListBySubscriptionPreparer(ctx context.Context) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.OperationsManagement/solutions", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListBySubscriptionSender sends the ListBySubscription request. The method will close the +// http.Response Body if it receives an error. +func (client SolutionsClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always +// closes the http.Response Body. +func (client SolutionsClient) ListBySubscriptionResponder(resp *http.Response) (result SolutionPropertiesList, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/version.go b/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/version.go new file mode 100644 index 000000000000..d8d97ca5153e --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/version.go @@ -0,0 +1,28 @@ +package operationsmanagement + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +// UserAgent returns the UserAgent string to use when sending http.Requests. +func UserAgent() string { + return "Azure-SDK-For-Go/v12.5.0-beta services" +} + +// Version returns the semantic version (see http://semver.org) of the client. +func Version() string { + return "v12.5.0-beta" +} diff --git a/vendor/vendor.json b/vendor/vendor.json index f12b71c3c54f..4c8526326ce4 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -154,6 +154,12 @@ "version": "v12.5.0-beta", "versionExact": "v12.5.0-beta" }, + { + "checksumSHA1": "WMfs+FCE3stapwrAvAS3fjFZlHk=", + "path": "github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement", + "revision": "21b68149ccf7c16b3f028bb4c7fd0ab458fe308f", + "revisionTime": "2018-02-12T16:31:56Z" + }, { "checksumSHA1": "qOcKrxfayIRgAKlAZu9XYTSfeA0=", "path": "github.com/Azure/azure-sdk-for-go/services/postgresql/mgmt/2017-04-30-preview/postgresql", From c7974e4bea5ae234ff98deea40174db4afbc5140 Mon Sep 17 00:00:00 2001 From: Lawrence Gripper Date: Wed, 7 Mar 2018 19:39:55 +0000 Subject: [PATCH 02/10] Removed debug code from sdk. Worked around error in SDK return type --- .../resource_arm_log_analytics_solution.go | 12 +++++- ...esource_arm_log_analytics_solution_test.go | 38 +++++++++---------- .../operationsmanagement/solutions.go | 13 ------- 3 files changed, 28 insertions(+), 35 deletions(-) diff --git a/azurerm/resource_arm_log_analytics_solution.go b/azurerm/resource_arm_log_analytics_solution.go index 9cd572323669..ceced40bdcdd 100644 --- a/azurerm/resource_arm_log_analytics_solution.go +++ b/azurerm/resource_arm_log_analytics_solution.go @@ -40,18 +40,22 @@ func resourceArmLogAnalyticsSolution() *schema.Resource { "name": { Type: schema.TypeString, Required: true, + ForceNew: true, }, "publisher": { Type: schema.TypeString, Required: true, + ForceNew: true, }, "promotion_code": { Type: schema.TypeString, Optional: true, + ForceNew: true, }, "product": { Type: schema.TypeString, Required: true, + ForceNew: true, }, }, }, @@ -86,11 +90,15 @@ func resourceArmLogAnalyticsSolutionCreateUpdate(d *schema.ResourceData, meta in }, } - solution, err := client.CreateOrUpdate(ctx, resGroup, name, parameters) - if err != nil { + res, err := client.CreateOrUpdate(ctx, resGroup, name, parameters) + //Currently this is required to work around successful creation resulting in an error + // being returned + if err != nil && res.StatusCode != 201 { return err } + solution, _ := client.Get(ctx, resGroup, name) + if solution.ID == nil { return fmt.Errorf("Cannot read Log Analytics Solution '%s' (resource group %s) ID", name, resGroup) } diff --git a/azurerm/resource_arm_log_analytics_solution_test.go b/azurerm/resource_arm_log_analytics_solution_test.go index f8e027fc5a02..92ac0373ae07 100644 --- a/azurerm/resource_arm_log_analytics_solution_test.go +++ b/azurerm/resource_arm_log_analytics_solution_test.go @@ -12,17 +12,16 @@ import ( func TestAccAzureRMLogAnalyticsSolution(t *testing.T) { ri := acctest.RandInt() - // config := testAccAzureRMLogAnalyticsSolution(ri, testLocation()) config := testAccAzureRMLogAnalyticsSolution(ri, testLocation()) resource.Test(t, resource.TestCase{ Providers: testAccProviders, - CheckDestroy: testCheckAzureRMLogAnalyticsWorkspaceDestroy, + CheckDestroy: testCheckAzureRMLogAnalyticsSolutionDestroy, Steps: []resource.TestStep{ { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogAnalyticsWorkspaceExists("azurerm_log_analytics_workspace.test"), + testCheckAzureRMLogAnalyticsSolutionExists("azurerm_log_analytics_solution.solution"), ), }, }, @@ -114,20 +113,19 @@ resource "azurerm_log_analytics_solution" "solution" { `, rInt, location, rInt, rInt) } -func testAccAzureRMLogAnalyticsSolution_Temp(rInt int, location string) string { - return fmt.Sprintf(` -resource "azurerm_log_analytics_solution" "solution" { - name = "acctest" - location = "westeurope" - resource_group_name = "lg-terraformtest" - workspace_resource_id = "/subscriptions/5774ad8f-d51e-4456-a72e-0447910568d3/resourcegroups/acctestrg-8930075193794579467/providers/microsoft.operationalinsights/workspaces/acctest-dep-8930075193794579467" - - plan { - name = "Containers" - publisher = "Microsoft" - promotion_code = "" - product = "OMSGallery/Containers" - } -} -`) -} +// func testAccAzureRMLogAnalyticsSolution_Temp(rInt int, location string) string { +// return fmt.Sprintf(` +// resource "azurerm_log_analytics_solution" "solution" { +// name = "acctest" +// location = "westeurope" +// resource_group_name = "lg-terraformtest" +// workspace_resource_id = "/subscriptions/5774ad8f-d51e-4456-a72e-0447910568d3/resourcegroups/lg-terraformtest/providers/microsoft.operationalinsights/workspaces/lg-testoms" + +// plan { +// name = "Containers" +// publisher = "Microsoft" +// product = "OMSGallery/Containers" +// } +// } +// `) +// } diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/solutions.go b/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/solutions.go index 570837913bcb..3a392d2e4e9b 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/solutions.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/solutions.go @@ -63,19 +63,6 @@ func (client SolutionsClient) CreateOrUpdate(ctx context.Context, resourceGroupN return } - // dump, err := httputil.DumpRequest(req, true) - // log.Println(string(dump)) - - // if err != nil { - // panic(err) - // } - // bytes, _ := ioutil.ReadAll(req.Body) - - // stringLength := len(string(bytes)) - // log.Println(stringLength) - // log.Println(string(bytes)) - // log.Println(err) - resp, err := client.CreateOrUpdateSender(req) if err != nil { result.Response = autorest.Response{Response: resp} From 068bf395c96c31f5c844df96195f916489ce3e32 Mon Sep 17 00:00:00 2001 From: Lawrence Gripper Date: Thu, 8 Mar 2018 12:03:43 +0000 Subject: [PATCH 03/10] Created example and fixed issue with naming on create. --- .../resource_arm_log_analytics_solution.go | 25 +++++++++----- ...esource_arm_log_analytics_solution_test.go | 16 ++++----- .../main.tf | 33 +++++++++++++++++++ .../outputs.tf | 10 ++++++ 4 files changed, 68 insertions(+), 16 deletions(-) create mode 100644 examples/log-analytics-container-monitoring/main.tf create mode 100644 examples/log-analytics-container-monitoring/outputs.tf diff --git a/azurerm/resource_arm_log_analytics_solution.go b/azurerm/resource_arm_log_analytics_solution.go index ceced40bdcdd..3dd388f195be 100644 --- a/azurerm/resource_arm_log_analytics_solution.go +++ b/azurerm/resource_arm_log_analytics_solution.go @@ -22,9 +22,13 @@ func resourceArmLogAnalyticsSolution() *schema.Resource { Schema: map[string]*schema.Schema{ "name": { + Type: schema.TypeString, + Computed: true, + }, + + "solution_name": { Type: schema.TypeString, Required: true, - ForceNew: true, }, "location": locationSchema(), @@ -39,8 +43,7 @@ func resourceArmLogAnalyticsSolution() *schema.Resource { Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, - Required: true, - ForceNew: true, + Computed: true, }, "publisher": { Type: schema.TypeString, @@ -61,6 +64,11 @@ func resourceArmLogAnalyticsSolution() *schema.Resource { }, }, + "workspace_name": { + Type: schema.TypeString, + Required: true, + }, + "workspace_resource_id": { Type: schema.TypeString, Required: true, @@ -74,13 +82,16 @@ func resourceArmLogAnalyticsSolutionCreateUpdate(d *schema.ResourceData, meta in ctx := meta.(*ArmClient).StopContext log.Printf("[INFO] preparing arguments for AzureRM Log Analytics solution creation.") - name := d.Get("name").(string) + // The resource requires both .name and .plan.name are set in the format + // "SolutionName(WorkspaceName)". Feedback will be submitted to the OMS team as IMO this isn't ideal. + name := fmt.Sprintf("%s(%s)", d.Get("solution_name").(string), d.Get("workspace_name").(string)) + solutionPlan := expandAzureRmLogAnalyticsSolutionPlan(d) + solutionPlan.Name = &name + location := d.Get("location").(string) resGroup := d.Get("resource_group_name").(string) workspaceID := d.Get("workspace_resource_id").(string) - solutionPlan := expandAzureRmLogAnalyticsSolutionPlan(d) - parameters := operationsmanagement.Solution{ Name: &name, Location: &location, @@ -135,7 +146,6 @@ func resourceArmLogAnalyticsSolutionRead(d *schema.ResourceData, meta interface{ d.Set("name", resp.Name) d.Set("location", resp.Location) d.Set("resource_group_name", resGroup) - d.Set("workspace_resource_id", resp.ID) d.Set("plan", flattenAzureRmLogAnalyticsSolutionPlan(*resp.Plan)) return nil } @@ -195,7 +205,6 @@ func flattenAzureRmLogAnalyticsSolutionPlan(plan operationsmanagement.SolutionPl plans := make([]interface{}, 0) values := make(map[string]interface{}) - values["name"] = *plan.Name values["product"] = *plan.Product values["promotion_code"] = *plan.PromotionCode values["publisher"] = *plan.Publisher diff --git a/azurerm/resource_arm_log_analytics_solution_test.go b/azurerm/resource_arm_log_analytics_solution_test.go index 92ac0373ae07..a0feace7c0ca 100644 --- a/azurerm/resource_arm_log_analytics_solution_test.go +++ b/azurerm/resource_arm_log_analytics_solution_test.go @@ -21,7 +21,7 @@ func TestAccAzureRMLogAnalyticsSolution(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogAnalyticsSolutionExists("azurerm_log_analytics_solution.solution"), + testCheckAzureRMLogAnalyticsSolutionExists("azurerm_log_analytics_solution.test"), ), }, }, @@ -91,26 +91,26 @@ resource "azurerm_resource_group" "test" { location = "%s" } -resource "azurerm_log_analytics_workspace" "workspace" { +resource "azurerm_log_analytics_workspace" "test" { name = "acctest-dep-%d" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" sku = "Free" } -resource "azurerm_log_analytics_solution" "solution" { - name = "acctest-%d" +resource "azurerm_log_analytics_solution" "test" { + solution_name = "Containers" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" - workspace_resource_id = "${azurerm_log_analytics_workspace.workspace.id}" - + workspace_resource_id = "${azurerm_log_analytics_workspace.test.id}" + workspace_name = "${azurerm_log_analytics_workspace.test.name}" + plan { - name = "Containers" publisher = "Microsoft" product = "OMSGallery/Containers" } } -`, rInt, location, rInt, rInt) +`, rInt, location, rInt) } // func testAccAzureRMLogAnalyticsSolution_Temp(rInt int, location string) string { diff --git a/examples/log-analytics-container-monitoring/main.tf b/examples/log-analytics-container-monitoring/main.tf new file mode 100644 index 000000000000..782f30afafaf --- /dev/null +++ b/examples/log-analytics-container-monitoring/main.tf @@ -0,0 +1,33 @@ +resource "azurerm_resource_group" "test" { + name = "k8s-log-analytics-test" + location = "westeurope" +} + +resource "random_id" "workspace" { + keepers = { + # Generate a new id each time we switch to a new resource group + group_name = "${azurerm_resource_group.test.name}" + } + + byte_length = 8 +} + +resource "azurerm_log_analytics_workspace" "test" { + name = "k8s-workspace-${random_id.workspace.hex}" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + sku = "Free" +} + +resource "azurerm_log_analytics_solution" "test" { + solution_name = "Containers" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + workspace_resource_id = "${azurerm_log_analytics_workspace.test.id}" + workspace_name = "${azurerm_log_analytics_workspace.test.name}" + + plan { + publisher = "Microsoft" + product = "OMSGallery/Containers" + } +} \ No newline at end of file diff --git a/examples/log-analytics-container-monitoring/outputs.tf b/examples/log-analytics-container-monitoring/outputs.tf new file mode 100644 index 000000000000..d6adecaf6ec4 --- /dev/null +++ b/examples/log-analytics-container-monitoring/outputs.tf @@ -0,0 +1,10 @@ + +// These outputs can be used to deploy the monitoring Daemonset into your k8s cluster +// https://docs.microsoft.com/en-us/azure/aks/tutorial-kubernetes-monitor +output "workspace_id" { + value = "${azurerm_log_analytics_workspace.test.workspace_id}" +} + +output "workspace_key" { + value = "${azurerm_log_analytics_workspace.test.primary_shared_key}" +} From 30afb16efbb32c091db54f5e3e4737d5706c84cb Mon Sep 17 00:00:00 2001 From: Lawrence Gripper Date: Thu, 8 Mar 2018 12:15:49 +0000 Subject: [PATCH 04/10] Removed logging code --- azurerm/config.go | 32 +------------------ .../operationsmanagement/solutions.go | 3 +- 2 files changed, 2 insertions(+), 33 deletions(-) diff --git a/azurerm/config.go b/azurerm/config.go index 16ead67892e0..91fa50d4e040 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -742,37 +742,7 @@ func (c *ArmClient) registerOperationalInsightsClients(endpoint, subscriptionId solutionsClient := operationsmanagement.NewSolutionsClient(subscriptionId, "Microsoft.OperationsManagement", "solutions", "testing") c.configureClient(&solutionsClient.Client, auth) c.solutionsClient = solutionsClient - // c.solutionsClient.RequestInspector = LogRequestPreparer() - // c.solutionsClient.ResponseInspector = LogResponseDecorator() -} - -// func LogRequestPreparer() autorest.PrepareDecorator { -// return func(p autorest.Preparer) autorest.Preparer { -// return autorest.PreparerFunc(func(r *http.Request) (*http.Request, error) { -// // resDump, _ := httputil.DumpRequestOut(r, true) -// // log.Println(string(resDump)) -// // return r, nil - -// r, err := p.Prepare(r) -// if err == nil { -// resDump, _ := httputil.DumpRequestOut(r, true) -// log.Println(string(resDump)) -// } -// return r, err -// }) -// } -// } - -// func LogResponseDecorator() autorest.RespondDecorator { -// return func(p autorest.Responder) autorest.Responder { -// return autorest.ResponderFunc(func(r *http.Response) error { -// _ = p.Respond(r) -// dump, _ := httputil.DumpResponse(r, true) -// log.Println(string(dump)) -// return nil -// }) -// } -// } +} func (c *ArmClient) registerRedisClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) { redisClient := redis.NewClientWithBaseURI(endpoint, subscriptionId) diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/solutions.go b/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/solutions.go index 3a392d2e4e9b..be6f5501e6e4 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/solutions.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement/solutions.go @@ -19,11 +19,10 @@ package operationsmanagement import ( "context" - "net/http" - "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/azure" "github.com/Azure/go-autorest/autorest/validation" + "net/http" ) // SolutionsClient is the operations Management Client From 051e77c24678fc4215fb1dbcd9a5bd569db7c20c Mon Sep 17 00:00:00 2001 From: Lawrence Gripper Date: Thu, 8 Mar 2018 13:25:32 +0000 Subject: [PATCH 05/10] Created docs for resource --- .../resource_arm_log_analytics_solution.go | 1 + .../r/log_analytics_solution.html.markdown | 75 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 website/docs/r/log_analytics_solution.html.markdown diff --git a/azurerm/resource_arm_log_analytics_solution.go b/azurerm/resource_arm_log_analytics_solution.go index 3dd388f195be..2e5894c4899d 100644 --- a/azurerm/resource_arm_log_analytics_solution.go +++ b/azurerm/resource_arm_log_analytics_solution.go @@ -29,6 +29,7 @@ func resourceArmLogAnalyticsSolution() *schema.Resource { "solution_name": { Type: schema.TypeString, Required: true, + ForceNew: true, }, "location": locationSchema(), diff --git a/website/docs/r/log_analytics_solution.html.markdown b/website/docs/r/log_analytics_solution.html.markdown new file mode 100644 index 000000000000..2d5e227fec40 --- /dev/null +++ b/website/docs/r/log_analytics_solution.html.markdown @@ -0,0 +1,75 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_log_analytics_solution" +sidebar_current: "docs-azurerm-resource-oms-log-analytics-solution" +description: |- + Creates a new Log Analytics (formally Operational Insights) Solution. +--- + +# azurerm_log_analytics_solution + +Creates a new Log Analytics (formally Operational Insights) Solution. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "test" { + name = "k8s-log-analytics-test" + location = "westeurope" +} + +resource "random_id" "workspace" { + keepers = { + # Generate a new id each time we switch to a new resource group + group_name = "${azurerm_resource_group.test.name}" + } + + byte_length = 8 +} + +resource "azurerm_log_analytics_workspace" "test" { + name = "k8s-workspace-${random_id.workspace.hex}" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + sku = "Free" +} + +resource "azurerm_log_analytics_solution" "test" { + solution_name = "Containers" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + workspace_resource_id = "${azurerm_log_analytics_workspace.test.id}" + workspace_name = "${azurerm_log_analytics_workspace.test.name}" + + plan { + publisher = "Microsoft" + product = "OMSGallery/Containers" + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `solution_name` - (Required) Specifies the name of the solution to be deployed. See [here for options](https://docs.microsoft.com/en-us/azure/log-analytics/log-analytics-add-solutions). Note: Resource tested with only `Container` solution. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the resource group in which the Log Analytics solution is created. Changing this forces a new resource to be created. Note: The solution and it's related workspace can only exist in the same resource group. + +* `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. + +* `workspace_resource_id` - (Required) The full resource ID of the Log Analytics workspace with which the solution will be linked. For example: `/subscriptions/00000000-0000-0000-0000-00000000/resourcegroups/examplegroupname/providers/Microsoft.OperationalInsights/workspaces/exampleWorkspaceName` + +* `workspace_resource_name` - (Required) The full name of the Log Analytics workspace with which the solution will be linked. For example: `exampleWorkspaceName` + +* `plan.publisher` - (Required) The publisher of the solution. For example `Microsoft`. Changing this forces a new resource to be created. + +* `plan.product` - (Required) The product name of the solution. For example `OMSGallery/Containers`. Changing this forces a new resource to be created. + +* `plan.promotion_code` - (Optional) A promotion code to be used with the solution. + +## Attributes Reference + +The following attributes are exported: + +* `name` and `plan.name` - These are identical and are generated from the `plan.product` and the `workspace_resource_name`. From 9db47256d1277849d902e58c6b0ffe18d2ace2f9 Mon Sep 17 00:00:00 2001 From: lawrencegripper Date: Fri, 9 Mar 2018 12:55:28 +0000 Subject: [PATCH 06/10] Fixed review feedback. Added new basic test & example. Updated docs. --- .../resource_arm_log_analytics_solution.go | 68 ++++++++++++------- ...esource_arm_log_analytics_solution_test.go | 68 +++++++++++++------ .../main.tf | 35 +++++++--- vendor/vendor.json | 4 +- .../r/log_analytics_solution.html.markdown | 54 +++++++-------- 5 files changed, 145 insertions(+), 84 deletions(-) diff --git a/azurerm/resource_arm_log_analytics_solution.go b/azurerm/resource_arm_log_analytics_solution.go index 2e5894c4899d..f34e5266e33e 100644 --- a/azurerm/resource_arm_log_analytics_solution.go +++ b/azurerm/resource_arm_log_analytics_solution.go @@ -3,6 +3,7 @@ package azurerm import ( "fmt" "log" + "strings" "github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement" @@ -21,11 +22,6 @@ func resourceArmLogAnalyticsSolution() *schema.Resource { }, Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Computed: true, - }, - "solution_name": { Type: schema.TypeString, Required: true, @@ -68,11 +64,19 @@ func resourceArmLogAnalyticsSolution() *schema.Resource { "workspace_name": { Type: schema.TypeString, Required: true, + ForceNew: true, }, "workspace_resource_id": { Type: schema.TypeString, Required: true, + ForceNew: true, + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + if strings.ToLower(old) == strings.ToLower(new) { + return true + } + return false + }, }, }, } @@ -141,13 +145,33 @@ func resourceArmLogAnalyticsSolutionRead(d *schema.ResourceData, meta interface{ } if resp.Plan == nil { - return fmt.Errorf("Error making Read request on AzureRM Log Analytics solutions '%s': %+v Plan was nil", name, err) + return fmt.Errorf("Error making Read request on AzureRM Log Analytics solutions '%s': Plan was nil", name) } - d.Set("name", resp.Name) d.Set("location", resp.Location) d.Set("resource_group_name", resGroup) - d.Set("plan", flattenAzureRmLogAnalyticsSolutionPlan(*resp.Plan)) + + // Reversing the mapping used to get .solution_name + // expecting resp.Name to be in format "SolutionName(WorkspaceName)". + if resp.Name != nil && strings.Contains(*resp.Name, "(") { + if parts := strings.Split(*resp.Name, "("); len(parts) == 2 { + d.Set("solution_name", parts[0]) + workspaceName := strings.TrimPrefix(parts[1], "(") + workspaceName = strings.TrimSuffix(workspaceName, ")") + d.Set("workspace_name", workspaceName) + } else { + return fmt.Errorf("Error making Read request on AzureRM Log Analytics solutions '%v': isn't in expected format 'Solution(WorkspaceName)'", resp.Name) + } + } else { + return fmt.Errorf("Error making Read request on AzureRM Log Analytics solutions '%v': isn't in expected format 'Solution(WorkspaceName)'", resp.Name) + } + + if props := resp.Properties; props != nil { + d.Set("workspace_resource_id", props.WorkspaceResourceID) + } + if plan := resp.Plan; plan != nil { + d.Set("plan", flattenAzureRmLogAnalyticsSolutionPlan(*resp.Plan)) + } return nil } @@ -178,25 +202,16 @@ func expandAzureRmLogAnalyticsSolutionPlan(d *schema.ResourceData) operationsman plans := d.Get("plan").([]interface{}) plan := plans[0].(map[string]interface{}) - expandedPlan := operationsmanagement.SolutionPlan{} - - if name := plan["name"].(string); len(name) > 0 { - expandedPlan.Name = &name - } - - if publisher := plan["publisher"].(string); len(publisher) > 0 { - expandedPlan.Publisher = &publisher - } - - if promotionCode := plan["promotion_code"].(string); len(promotionCode) > 0 { - expandedPlan.PromotionCode = &promotionCode - } else { - blankString := "" - expandedPlan.PromotionCode = &blankString - } + name := plan["name"].(string) + publisher := plan["publisher"].(string) + promotionCode := plan["promotion_code"].(string) + product := plan["product"].(string) - if product := plan["product"].(string); len(product) > 0 { - expandedPlan.Product = &product + expandedPlan := operationsmanagement.SolutionPlan{ + Name: utils.String(name), + PromotionCode: utils.String(promotionCode), + Publisher: utils.String(publisher), + Product: utils.String(product), } return expandedPlan @@ -206,6 +221,7 @@ func flattenAzureRmLogAnalyticsSolutionPlan(plan operationsmanagement.SolutionPl plans := make([]interface{}, 0) values := make(map[string]interface{}) + values["name"] = plan.Name values["product"] = *plan.Product values["promotion_code"] = *plan.PromotionCode values["publisher"] = *plan.Publisher diff --git a/azurerm/resource_arm_log_analytics_solution_test.go b/azurerm/resource_arm_log_analytics_solution_test.go index a0feace7c0ca..910b015e81c1 100644 --- a/azurerm/resource_arm_log_analytics_solution_test.go +++ b/azurerm/resource_arm_log_analytics_solution_test.go @@ -10,9 +10,27 @@ import ( "github.com/hashicorp/terraform/terraform" ) -func TestAccAzureRMLogAnalyticsSolution(t *testing.T) { +func TestAccAzureRMLogAnalyticsSolution_basic_containerMonitoring(t *testing.T) { ri := acctest.RandInt() - config := testAccAzureRMLogAnalyticsSolution(ri, testLocation()) + config := testAccAzureRMLogAnalyticsSolution_containerMonitoring(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMLogAnalyticsSolutionDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogAnalyticsSolutionExists("azurerm_log_analytics_solution.test"), + ), + }, + }, + }) +} + +func TestAccAzureRMLogAnalyticsSolution_basic_security(t *testing.T) { + ri := acctest.RandInt() + config := testAccAzureRMLogAnalyticsSolution_security(ri, testLocation()) resource.Test(t, resource.TestCase{ Providers: testAccProviders, @@ -84,7 +102,7 @@ func testCheckAzureRMLogAnalyticsSolutionExists(name string) resource.TestCheckF } } -func testAccAzureRMLogAnalyticsSolution(rInt int, location string) string { +func testAccAzureRMLogAnalyticsSolution_containerMonitoring(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "oms-acctestRG-%d" @@ -113,19 +131,31 @@ resource "azurerm_log_analytics_solution" "test" { `, rInt, location, rInt) } -// func testAccAzureRMLogAnalyticsSolution_Temp(rInt int, location string) string { -// return fmt.Sprintf(` -// resource "azurerm_log_analytics_solution" "solution" { -// name = "acctest" -// location = "westeurope" -// resource_group_name = "lg-terraformtest" -// workspace_resource_id = "/subscriptions/5774ad8f-d51e-4456-a72e-0447910568d3/resourcegroups/lg-terraformtest/providers/microsoft.operationalinsights/workspaces/lg-testoms" - -// plan { -// name = "Containers" -// publisher = "Microsoft" -// product = "OMSGallery/Containers" -// } -// } -// `) -// } +func testAccAzureRMLogAnalyticsSolution_security(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "oms-acctestRG-%d" + location = "%s" +} + +resource "azurerm_log_analytics_workspace" "test" { + name = "acctest-dep-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + sku = "Free" +} + +resource "azurerm_log_analytics_solution" "test" { + solution_name = "Security" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + workspace_resource_id = "${azurerm_log_analytics_workspace.test.id}" + workspace_name = "${azurerm_log_analytics_workspace.test.name}" + + plan { + publisher = "Microsoft" + product = "OMSGallery/Security" + } +} +`, rInt, location, rInt) +} diff --git a/examples/log-analytics-container-monitoring/main.tf b/examples/log-analytics-container-monitoring/main.tf index 782f30afafaf..52bb40b6f1e3 100644 --- a/examples/log-analytics-container-monitoring/main.tf +++ b/examples/log-analytics-container-monitoring/main.tf @@ -1,6 +1,6 @@ resource "azurerm_resource_group" "test" { - name = "k8s-log-analytics-test" - location = "westeurope" + name = "k8s-log-analytics-test" + location = "westeurope" } resource "random_id" "workspace" { @@ -11,16 +11,29 @@ resource "random_id" "workspace" { byte_length = 8 } - + resource "azurerm_log_analytics_workspace" "test" { - name = "k8s-workspace-${random_id.workspace.hex}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - sku = "Free" + name = "k8s-workspace-${random_id.workspace.hex}" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + sku = "Free" } - + resource "azurerm_log_analytics_solution" "test" { - solution_name = "Containers" + solution_name = "Containers" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + workspace_resource_id = "${azurerm_log_analytics_workspace.test.id}" + workspace_name = "${azurerm_log_analytics_workspace.test.name}" + + plan { + publisher = "Microsoft" + product = "OMSGallery/Containers" + } +} + +resource "azurerm_log_analytics_solution" "test2" { + solution_name = "Security" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" workspace_resource_id = "${azurerm_log_analytics_workspace.test.id}" @@ -28,6 +41,6 @@ resource "azurerm_log_analytics_solution" "test" { plan { publisher = "Microsoft" - product = "OMSGallery/Containers" + product = "OMSGallery/Security" } -} \ No newline at end of file +} diff --git a/vendor/vendor.json b/vendor/vendor.json index 4c8526326ce4..48b4f40ec7d5 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -158,7 +158,9 @@ "checksumSHA1": "WMfs+FCE3stapwrAvAS3fjFZlHk=", "path": "github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement", "revision": "21b68149ccf7c16b3f028bb4c7fd0ab458fe308f", - "revisionTime": "2018-02-12T16:31:56Z" + "revisionTime": "2018-02-16T17:41:56Z", + "version": "v12.5.0-beta", + "versionExact": "v12.5.0-beta" }, { "checksumSHA1": "qOcKrxfayIRgAKlAZu9XYTSfeA0=", diff --git a/website/docs/r/log_analytics_solution.html.markdown b/website/docs/r/log_analytics_solution.html.markdown index 2d5e227fec40..9f79156fded2 100644 --- a/website/docs/r/log_analytics_solution.html.markdown +++ b/website/docs/r/log_analytics_solution.html.markdown @@ -14,8 +14,8 @@ Creates a new Log Analytics (formally Operational Insights) Solution. ```hcl resource "azurerm_resource_group" "test" { - name = "k8s-log-analytics-test" - location = "westeurope" + name = "k8s-log-analytics-test" + location = "westeurope" } resource "random_id" "workspace" { @@ -26,25 +26,25 @@ resource "random_id" "workspace" { byte_length = 8 } - + resource "azurerm_log_analytics_workspace" "test" { - name = "k8s-workspace-${random_id.workspace.hex}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - sku = "Free" + name = "k8s-workspace-${random_id.workspace.hex}" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + sku = "Free" } - + resource "azurerm_log_analytics_solution" "test" { - solution_name = "Containers" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - workspace_resource_id = "${azurerm_log_analytics_workspace.test.id}" - workspace_name = "${azurerm_log_analytics_workspace.test.name}" - - plan { - publisher = "Microsoft" - product = "OMSGallery/Containers" - } + solution_name = "Containers" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + workspace_resource_id = "${azurerm_log_analytics_workspace.test.id}" + workspace_name = "${azurerm_log_analytics_workspace.test.name}" + + plan { + publisher = "Microsoft" + product = "OMSGallery/Containers" + } } ``` @@ -52,24 +52,24 @@ resource "azurerm_log_analytics_solution" "test" { The following arguments are supported: -* `solution_name` - (Required) Specifies the name of the solution to be deployed. See [here for options](https://docs.microsoft.com/en-us/azure/log-analytics/log-analytics-add-solutions). Note: Resource tested with only `Container` solution. Changing this forces a new resource to be created. +* `solution_name` - (Required) Specifies the name of the solution to be deployed. See [here for options](https://docs.microsoft.com/en-us/azure/log-analytics/log-analytics-add-solutions).Changing this forces a new resource to be created. * `resource_group_name` - (Required) The name of the resource group in which the Log Analytics solution is created. Changing this forces a new resource to be created. Note: The solution and it's related workspace can only exist in the same resource group. * `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. -* `workspace_resource_id` - (Required) The full resource ID of the Log Analytics workspace with which the solution will be linked. For example: `/subscriptions/00000000-0000-0000-0000-00000000/resourcegroups/examplegroupname/providers/Microsoft.OperationalInsights/workspaces/exampleWorkspaceName` +* `workspace_resource_id` - (Required) The full resource ID of the Log Analytics workspace with which the solution will be linked. Changing this forces a new resource to be created. -* `workspace_resource_name` - (Required) The full name of the Log Analytics workspace with which the solution will be linked. For example: `exampleWorkspaceName` +* `workspace_resource_name` - (Required) The full name of the Log Analytics workspace with which the solution will be linked. Changing this forces a new resource to be created. -* `plan.publisher` - (Required) The publisher of the solution. For example `Microsoft`. Changing this forces a new resource to be created. +* `plan` - A `plan` block as documented below. -* `plan.product` - (Required) The product name of the solution. For example `OMSGallery/Containers`. Changing this forces a new resource to be created. +--- -* `plan.promotion_code` - (Optional) A promotion code to be used with the solution. +A `plan` block includes: -## Attributes Reference +* `publisher` - (Required) The publisher of the solution. For example `Microsoft`. Changing this forces a new resource to be created. -The following attributes are exported: +* `product` - (Required) The product name of the solution. For example `OMSGallery/Containers`. Changing this forces a new resource to be created. -* `name` and `plan.name` - These are identical and are generated from the `plan.product` and the `workspace_resource_name`. +* `promotion_code` - (Optional) A promotion code to be used with the solution. From fd0d8fead6fef9de2f3142c1a4bc769ca3982c69 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 12 Mar 2018 10:36:51 -0500 Subject: [PATCH 07/10] Documenting import support for Log Analytics Workspaces & Solutions --- website/docs/r/log_analytics_solution.html.markdown | 9 +++++++++ website/docs/r/log_analytics_workspace.html.markdown | 11 ++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/website/docs/r/log_analytics_solution.html.markdown b/website/docs/r/log_analytics_solution.html.markdown index 9f79156fded2..6738b1b719a1 100644 --- a/website/docs/r/log_analytics_solution.html.markdown +++ b/website/docs/r/log_analytics_solution.html.markdown @@ -73,3 +73,12 @@ A `plan` block includes: * `product` - (Required) The product name of the solution. For example `OMSGallery/Containers`. Changing this forces a new resource to be created. * `promotion_code` - (Optional) A promotion code to be used with the solution. + + +## Import + +Log Analytics Solutions can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_log_analytics_solution.solution1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.OperationsManagement/solutions/solution1 +``` diff --git a/website/docs/r/log_analytics_workspace.html.markdown b/website/docs/r/log_analytics_workspace.html.markdown index 28a6fbd9aea0..690856f653c7 100644 --- a/website/docs/r/log_analytics_workspace.html.markdown +++ b/website/docs/r/log_analytics_workspace.html.markdown @@ -55,4 +55,13 @@ The following attributes are exported: * `workspace_id` - The Workspace (or Customer) ID for the Log Analytics Workspace. -* `portal_url` - The Portal URL for the Log Analytics Workspace. \ No newline at end of file +* `portal_url` - The Portal URL for the Log Analytics Workspace. + + +## Import + +Log Analytics Workspaces can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_log_analytics_workspace.workspace1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.OperationalInsights/workspaces/workspace1 +``` From 912a26834cda508589a6f6d507c886f89682564a Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 12 Mar 2018 10:38:15 -0500 Subject: [PATCH 08/10] Adding a sidebar entry for OMS Solutions --- website/azurerm.erb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/website/azurerm.erb b/website/azurerm.erb index 9912e43d8711..fb05121b4993 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -585,6 +585,10 @@ > OMS Resources