From bd7b44bad4b4b0e0308082bc4bf126ef898be015 Mon Sep 17 00:00:00 2001 From: lstolyarov Date: Sun, 11 Jun 2017 14:25:45 +0100 Subject: [PATCH 1/9] Adding azure app insights resource --- azurerm/config.go | 9 + azurerm/provider.go | 2 + azurerm/resource_arm_app_insights.go | 138 +++++ .../arm/appinsights/client.go | 53 ++ .../arm/appinsights/components.go | 497 +++++++++++++++++ .../arm/appinsights/models.go | 226 ++++++++ .../arm/appinsights/operations.go | 123 +++++ .../arm/appinsights/version.go | 29 + .../arm/appinsights/webtests.go | 499 ++++++++++++++++++ .../Azure/azure-sdk-for-go/arm/security.tf | 145 +++++ 10 files changed, 1721 insertions(+) create mode 100644 azurerm/resource_arm_app_insights.go create mode 100755 vendor/github.com/Azure/azure-sdk-for-go/arm/appinsights/client.go create mode 100755 vendor/github.com/Azure/azure-sdk-for-go/arm/appinsights/components.go create mode 100755 vendor/github.com/Azure/azure-sdk-for-go/arm/appinsights/models.go create mode 100755 vendor/github.com/Azure/azure-sdk-for-go/arm/appinsights/operations.go create mode 100755 vendor/github.com/Azure/azure-sdk-for-go/arm/appinsights/version.go create mode 100755 vendor/github.com/Azure/azure-sdk-for-go/arm/appinsights/webtests.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/arm/security.tf diff --git a/azurerm/config.go b/azurerm/config.go index 8fdb95d19a7a..f30244cd5c65 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -7,6 +7,7 @@ import ( "net/http" "net/http/httputil" + "github.com/Azure/azure-sdk-for-go/arm/appinsights" "github.com/Azure/azure-sdk-for-go/arm/cdn" "github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/Azure/azure-sdk-for-go/arm/containerregistry" @@ -104,6 +105,8 @@ type ArmClient struct { keyVaultClient keyvault.VaultsClient sqlElasticPoolsClient sql.ElasticPoolsClient + + appInsightsClient appinsights.ComponentsClient } func withRequestLogging() autorest.SendDecorator { @@ -476,6 +479,12 @@ func (c *Config) getArmClient() (*ArmClient, error) { sqlepc.Sender = autorest.CreateSender(withRequestLogging()) client.sqlElasticPoolsClient = sqlepc + ai := appinsights.NewComponentsClientWithBaseURI(endpoint, c.SubscriptionID) + setUserAgent(&ai.Client) + ai.Authorizer = auth + ai.Sender = autorest.CreateSender(withRequestLogging()) + client.appInsightsClient = ai + return &client, nil } diff --git a/azurerm/provider.go b/azurerm/provider.go index 05c10505cfd9..69e6bc754177 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -120,6 +120,8 @@ func Provider() terraform.ResourceProvider { "azurerm_virtual_network": resourceArmVirtualNetwork(), "azurerm_virtual_network_peering": resourceArmVirtualNetworkPeering(), + "azurerm_app_insights": resourceArmAppInsights(), + // These resources use the Riviera SDK "azurerm_dns_a_record": resourceArmDnsARecord(), "azurerm_dns_aaaa_record": resourceArmDnsAAAARecord(), diff --git a/azurerm/resource_arm_app_insights.go b/azurerm/resource_arm_app_insights.go new file mode 100644 index 000000000000..0e7a5bf3ee7c --- /dev/null +++ b/azurerm/resource_arm_app_insights.go @@ -0,0 +1,138 @@ +package azurerm + +import ( + "fmt" + "log" + "net/http" + + "github.com/Azure/azure-sdk-for-go/arm/appinsights" + "github.com/hashicorp/terraform/helper/schema" +) + +func resourceArmAppInsights() *schema.Resource { + return &schema.Resource{ + Create: resourceArmAppInsightsCreateOrUpdate, + Read: resourceArmAppInsightsRead, + Update: resourceArmAppInsightsCreateOrUpdate, + Delete: resourceArmAppInsightsDelete, + + Schema: map[string]*schema.Schema{ + "resource_group_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "kind": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "location": locationSchema(), + "tags": tagsSchema(), + "instrumentation_key": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func resourceArmAppInsightsCreateOrUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient) + AppInsightsClient := client.appInsightsClient + + log.Printf("[INFO] preparing arguments for Azure ARM App Insights creation.") + + name := d.Get("name").(string) + resGroup := d.Get("resource_group_name").(string) + insightsType := "microsoft.insights/components" + kind := d.Get("kind").(string) + location := d.Get("location").(string) + tags := d.Get("tags").(map[string]interface{}) + requestSource := "IbizaAIExtension" + + applicationInsightsComponentProperties := appinsights.ApplicationInsightsComponentProperties{ + ApplicationID: &name, + ApplicationType: appinsights.ApplicationType(insightsType), + RequestSource: appinsights.RequestSource(requestSource), + } + + insightProperties := appinsights.ApplicationInsightsComponent{ + Name: &name, + Type: &insightsType, + Location: &location, + Tags: expandTags(tags), + Kind: &kind, + ApplicationInsightsComponentProperties: &applicationInsightsComponentProperties, + } + + _, err := AppInsightsClient.CreateOrUpdate(resGroup, name, insightProperties) + if err != nil { + return err + } + + read, err := AppInsightsClient.Get(resGroup, name) + if err != nil { + return err + } + if read.ID == nil { + return fmt.Errorf("Cannot read app insights %s (resource group %s) ID", name, resGroup) + } + + d.SetId(*read.ID) + + return resourceArmAppInsightsRead(d, meta) +} + +func resourceArmAppInsightsRead(d *schema.ResourceData, meta interface{}) error { + AppInsightsClient := meta.(*ArmClient).appInsightsClient + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + + log.Printf("[DEBUG] Reading app insights %s", id) + + resGroup := id.ResourceGroup + name := id.Path["components"] + + resp, err := AppInsightsClient.Get(resGroup, name) + if err != nil { + if resp.StatusCode == http.StatusNotFound { + d.SetId("") + return nil + } + return fmt.Errorf("Error making Read request on Azure app insights %s: %s", name, err) + } + + instrumentationKey := resp.ApplicationInsightsComponentProperties.InstrumentationKey + + d.Set("name", name) + d.Set("resource_group_name", resGroup) + d.Set("instrumentation_key", instrumentationKey) + + return nil +} + +func resourceArmAppInsightsDelete(d *schema.ResourceData, meta interface{}) error { + AppInsightsClient := meta.(*ArmClient).appInsightsClient + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resGroup := id.ResourceGroup + name := id.Path["components"] + + log.Printf("[DEBUG] Deleting app insights %s: %s", resGroup, name) + + _, err = AppInsightsClient.Delete(resGroup, name) + + return err +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/appinsights/client.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/appinsights/client.go new file mode 100755 index 000000000000..e00640451a69 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/appinsights/client.go @@ -0,0 +1,53 @@ +// Package appinsights implements the Azure ARM Appinsights service API version +// . +// +// Composite Swagger for Application Insights Management Client +package appinsights + +// 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 1.0.1.0 +// 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 Appinsights + DefaultBaseURI = "https://management.azure.com" +) + +// ManagementClient is the base client for Appinsights. +type ManagementClient struct { + autorest.Client + BaseURI string + SubscriptionID string +} + +// New creates an instance of the ManagementClient client. +func New(subscriptionID string) ManagementClient { + return NewWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewWithBaseURI creates an instance of the ManagementClient client. +func NewWithBaseURI(baseURI string, subscriptionID string) ManagementClient { + return ManagementClient{ + Client: autorest.NewClientWithUserAgent(UserAgent()), + BaseURI: baseURI, + SubscriptionID: subscriptionID, + } +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/appinsights/components.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/appinsights/components.go new file mode 100755 index 000000000000..45c5c8282a56 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/appinsights/components.go @@ -0,0 +1,497 @@ +package appinsights + +// 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 1.0.1.0 +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "net/http" +) + +// ComponentsClient is the composite Swagger for Application Insights +// Management Client +type ComponentsClient struct { + ManagementClient +} + +// NewComponentsClient creates an instance of the ComponentsClient client. +func NewComponentsClient(subscriptionID string) ComponentsClient { + return NewComponentsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewComponentsClientWithBaseURI creates an instance of the ComponentsClient +// client. +func NewComponentsClientWithBaseURI(baseURI string, subscriptionID string) ComponentsClient { + return ComponentsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CreateOrUpdate creates (or updates) an Application Insights component. Note: +// You cannot specify a different value for InstrumentationKey nor AppId in the +// Put operation. +// +// resourceGroupName is the name of the resource group. resourceName is the +// name of the Application Insights component resource. insightProperties is +// properties that need to be specified to create an Application Insights +// component. +func (client ComponentsClient) CreateOrUpdate(resourceGroupName string, resourceName string, insightProperties ApplicationInsightsComponent) (result ApplicationInsightsComponent, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: insightProperties, + Constraints: []validation.Constraint{{Target: "insightProperties.Kind", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewErrorWithValidationError(err, "appinsights.ComponentsClient", "CreateOrUpdate") + } + + req, err := client.CreateOrUpdatePreparer(resourceGroupName, resourceName, insightProperties) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.ComponentsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "appinsights.ComponentsClient", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.ComponentsClient", "CreateOrUpdate", resp, "Failure responding to request") + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client ComponentsClient) CreateOrUpdatePreparer(resourceGroupName string, resourceName string, insightProperties ApplicationInsightsComponent) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "resourceName": autorest.Encode("path", resourceName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-05-01" + 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.insights/components/{resourceName}", pathParameters), + autorest.WithJSON(insightProperties), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client ComponentsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client ComponentsClient) CreateOrUpdateResponder(resp *http.Response) (result ApplicationInsightsComponent, 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 an Application Insights component. +// +// resourceGroupName is the name of the resource group. resourceName is the +// name of the Application Insights component resource. +func (client ComponentsClient) Delete(resourceGroupName string, resourceName string) (result autorest.Response, err error) { + req, err := client.DeletePreparer(resourceGroupName, resourceName) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.ComponentsClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "appinsights.ComponentsClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.ComponentsClient", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client ComponentsClient) DeletePreparer(resourceGroupName string, resourceName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "resourceName": autorest.Encode("path", resourceName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-05-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/components/{resourceName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client ComponentsClient) DeleteSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client ComponentsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get returns an Application Insights component. +// +// resourceGroupName is the name of the resource group. resourceName is the +// name of the Application Insights component resource. +func (client ComponentsClient) Get(resourceGroupName string, resourceName string) (result ApplicationInsightsComponent, err error) { + req, err := client.GetPreparer(resourceGroupName, resourceName) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.ComponentsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "appinsights.ComponentsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.ComponentsClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client ComponentsClient) GetPreparer(resourceGroupName string, resourceName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "resourceName": autorest.Encode("path", resourceName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-05-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/components/{resourceName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client ComponentsClient) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client ComponentsClient) GetResponder(resp *http.Response) (result ApplicationInsightsComponent, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List gets a list of all Application Insights components within a +// subscription. +func (client ComponentsClient) List() (result ApplicationInsightsComponentListResult, err error) { + req, err := client.ListPreparer() + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.ComponentsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "appinsights.ComponentsClient", "List", resp, "Failure sending request") + return + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.ComponentsClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client ComponentsClient) ListPreparer() (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-05-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/microsoft.insights/components", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client ComponentsClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client ComponentsClient) ListResponder(resp *http.Response) (result ApplicationInsightsComponentListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListNextResults retrieves the next set of results, if any. +func (client ComponentsClient) ListNextResults(lastResults ApplicationInsightsComponentListResult) (result ApplicationInsightsComponentListResult, err error) { + req, err := lastResults.ApplicationInsightsComponentListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "appinsights.ComponentsClient", "List", nil, "Failure preparing next results request") + } + if req == nil { + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "appinsights.ComponentsClient", "List", resp, "Failure sending next results request") + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.ComponentsClient", "List", resp, "Failure responding to next results request") + } + + return +} + +// ListByResourceGroup gets a list of Application Insights components within a +// resource group. +// +// resourceGroupName is the name of the resource group. +func (client ComponentsClient) ListByResourceGroup(resourceGroupName string) (result ApplicationInsightsComponentListResult, err error) { + req, err := client.ListByResourceGroupPreparer(resourceGroupName) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.ComponentsClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + resp, err := client.ListByResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "appinsights.ComponentsClient", "ListByResourceGroup", resp, "Failure sending request") + return + } + + result, err = client.ListByResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.ComponentsClient", "ListByResourceGroup", resp, "Failure responding to request") + } + + return +} + +// ListByResourceGroupPreparer prepares the ListByResourceGroup request. +func (client ComponentsClient) ListByResourceGroupPreparer(resourceGroupName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-05-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/components", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client ComponentsClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (client ComponentsClient) ListByResourceGroupResponder(resp *http.Response) (result ApplicationInsightsComponentListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListByResourceGroupNextResults retrieves the next set of results, if any. +func (client ComponentsClient) ListByResourceGroupNextResults(lastResults ApplicationInsightsComponentListResult) (result ApplicationInsightsComponentListResult, err error) { + req, err := lastResults.ApplicationInsightsComponentListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "appinsights.ComponentsClient", "ListByResourceGroup", nil, "Failure preparing next results request") + } + if req == nil { + return + } + + resp, err := client.ListByResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "appinsights.ComponentsClient", "ListByResourceGroup", resp, "Failure sending next results request") + } + + result, err = client.ListByResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.ComponentsClient", "ListByResourceGroup", resp, "Failure responding to next results request") + } + + return +} + +// UpdateTags updates an existing component's tags. To update other fields use +// the CreateOrUpdate method. +// +// resourceGroupName is the name of the resource group. resourceName is the +// name of the Application Insights component resource. componentTags is +// updated tag information to set into the component instance. +func (client ComponentsClient) UpdateTags(resourceGroupName string, resourceName string, componentTags TagsResource) (result ApplicationInsightsComponent, err error) { + req, err := client.UpdateTagsPreparer(resourceGroupName, resourceName, componentTags) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.ComponentsClient", "UpdateTags", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateTagsSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "appinsights.ComponentsClient", "UpdateTags", resp, "Failure sending request") + return + } + + result, err = client.UpdateTagsResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.ComponentsClient", "UpdateTags", resp, "Failure responding to request") + } + + return +} + +// UpdateTagsPreparer prepares the UpdateTags request. +func (client ComponentsClient) UpdateTagsPreparer(resourceGroupName string, resourceName string, componentTags TagsResource) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "resourceName": autorest.Encode("path", resourceName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-05-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsJSON(), + autorest.AsPatch(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/components/{resourceName}", pathParameters), + autorest.WithJSON(componentTags), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// UpdateTagsSender sends the UpdateTags request. The method will close the +// http.Response Body if it receives an error. +func (client ComponentsClient) UpdateTagsSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// UpdateTagsResponder handles the response to the UpdateTags request. The method always +// closes the http.Response Body. +func (client ComponentsClient) UpdateTagsResponder(resp *http.Response) (result ApplicationInsightsComponent, 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/arm/appinsights/models.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/appinsights/models.go new file mode 100755 index 000000000000..0cf0bb0ad08e --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/appinsights/models.go @@ -0,0 +1,226 @@ +package appinsights + +// 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 1.0.1.0 +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/date" + "github.com/Azure/go-autorest/autorest/to" + "net/http" +) + +// ApplicationType enumerates the values for application type. +type ApplicationType string + +const ( + // Other specifies the other state for application type. + Other ApplicationType = "other" + // Web specifies the web state for application type. + Web ApplicationType = "web" +) + +// FlowType enumerates the values for flow type. +type FlowType string + +const ( + // Bluefield specifies the bluefield state for flow type. + Bluefield FlowType = "Bluefield" +) + +// RequestSource enumerates the values for request source. +type RequestSource string + +const ( + // Rest specifies the rest state for request source. + Rest RequestSource = "rest" +) + +// WebTestKind enumerates the values for web test kind. +type WebTestKind string + +const ( + // Multistep specifies the multistep state for web test kind. + Multistep WebTestKind = "multistep" + // Ping specifies the ping state for web test kind. + Ping WebTestKind = "ping" +) + +// ApplicationInsightsComponent is an Application Insights component +// definition. +type ApplicationInsightsComponent struct { + autorest.Response `json:"-"` + ID *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` + Location *string `json:"location,omitempty"` + Tags *map[string]*string `json:"tags,omitempty"` + Kind *string `json:"kind,omitempty"` + *ApplicationInsightsComponentProperties `json:"properties,omitempty"` +} + +// ApplicationInsightsComponentListResult is describes the list of Application +// Insights Resources. +type ApplicationInsightsComponentListResult struct { + autorest.Response `json:"-"` + Value *[]ApplicationInsightsComponent `json:"value,omitempty"` + NextLink *string `json:"nextLink,omitempty"` +} + +// ApplicationInsightsComponentListResultPreparer prepares a request to retrieve the next set of results. It returns +// nil if no more results exist. +func (client ApplicationInsightsComponentListResult) ApplicationInsightsComponentListResultPreparer() (*http.Request, error) { + if client.NextLink == nil || len(to.String(client.NextLink)) <= 0 { + return nil, nil + } + return autorest.Prepare(&http.Request{}, + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(client.NextLink))) +} + +// ApplicationInsightsComponentProperties is properties that define an +// Application Insights component resource. +type ApplicationInsightsComponentProperties struct { + ApplicationID *string `json:"ApplicationId,omitempty"` + AppID *string `json:"AppId,omitempty"` + ApplicationType ApplicationType `json:"Application_Type,omitempty"` + FlowType FlowType `json:"Flow_Type,omitempty"` + RequestSource RequestSource `json:"Request_Source,omitempty"` + InstrumentationKey *string `json:"InstrumentationKey,omitempty"` + CreationDate *date.Time `json:"CreationDate,omitempty"` + TenantID *string `json:"TenantId,omitempty"` + HockeyAppID *string `json:"HockeyAppId,omitempty"` + HockeyAppToken *string `json:"HockeyAppToken,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + SamplingPercentage *float64 `json:"SamplingPercentage,omitempty"` +} + +// ErrorResponse is error reponse indicates Insights service is not able to +// process the incoming request. The reason is provided in the error message. +type ErrorResponse struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` +} + +// Operation is cDN REST API operation +type Operation struct { + Name *string `json:"name,omitempty"` + Display *OperationDisplay `json:"display,omitempty"` +} + +// OperationDisplay is the object that represents the operation. +type OperationDisplay struct { + Provider *string `json:"provider,omitempty"` + Resource *string `json:"resource,omitempty"` + Operation *string `json:"operation,omitempty"` +} + +// OperationListResult is result of the request to list CDN operations. It +// contains a list of operations and a URL link to get the next set of results. +type OperationListResult struct { + autorest.Response `json:"-"` + Value *[]Operation `json:"value,omitempty"` + NextLink *string `json:"nextLink,omitempty"` +} + +// OperationListResultPreparer prepares a request to retrieve the next set of results. It returns +// nil if no more results exist. +func (client OperationListResult) OperationListResultPreparer() (*http.Request, error) { + if client.NextLink == nil || len(to.String(client.NextLink)) <= 0 { + return nil, nil + } + return autorest.Prepare(&http.Request{}, + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(client.NextLink))) +} + +// Resource is an azure resource object +type Resource struct { + ID *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` + Location *string `json:"location,omitempty"` + Tags *map[string]*string `json:"tags,omitempty"` +} + +// TagsResource is a container holding only the Tags for a resource, allowing +// the user to update the tags on a WebTest instance. +type TagsResource struct { + Tags *map[string]*string `json:"tags,omitempty"` +} + +// WebTest is an Application Insights web test definition. +type WebTest struct { + autorest.Response `json:"-"` + ID *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` + Location *string `json:"location,omitempty"` + Tags *map[string]*string `json:"tags,omitempty"` + Kind WebTestKind `json:"kind,omitempty"` + *WebTestProperties `json:"properties,omitempty"` +} + +// WebTestGeolocation is geo-physical location to run a web test from. You must +// specify one or more locations for the test to run from. +type WebTestGeolocation struct { + Location *string `json:"Id,omitempty"` +} + +// WebTestListResult is a list of 0 or more Application Insights web test +// definitions. +type WebTestListResult struct { + autorest.Response `json:"-"` + Value *[]WebTest `json:"value,omitempty"` + NextLink *string `json:"nextLink,omitempty"` +} + +// WebTestListResultPreparer prepares a request to retrieve the next set of results. It returns +// nil if no more results exist. +func (client WebTestListResult) WebTestListResultPreparer() (*http.Request, error) { + if client.NextLink == nil || len(to.String(client.NextLink)) <= 0 { + return nil, nil + } + return autorest.Prepare(&http.Request{}, + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(client.NextLink))) +} + +// WebTestProperties is metadata describing a web test for an Azure resource. +type WebTestProperties struct { + SyntheticMonitorID *string `json:"SyntheticMonitorId,omitempty"` + WebTestName *string `json:"Name,omitempty"` + Description *string `json:"Description,omitempty"` + Enabled *bool `json:"Enabled,omitempty"` + Frequency *int32 `json:"Frequency,omitempty"` + Timeout *int32 `json:"Timeout,omitempty"` + WebTestKind WebTestKind `json:"Kind,omitempty"` + RetryEnabled *bool `json:"RetryEnabled,omitempty"` + Locations *[]WebTestGeolocation `json:"Locations,omitempty"` + Configuration *WebTestPropertiesConfiguration `json:"Configuration,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` +} + +// WebTestPropertiesConfiguration is an XML configuration specification for a +// WebTest. +type WebTestPropertiesConfiguration struct { + WebTest *string `json:"WebTest,omitempty"` +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/appinsights/operations.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/appinsights/operations.go new file mode 100755 index 000000000000..37e9fd47c843 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/appinsights/operations.go @@ -0,0 +1,123 @@ +package appinsights + +// 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 1.0.1.0 +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "net/http" +) + +// OperationsClient is the composite Swagger for Application Insights +// Management Client +type OperationsClient struct { + ManagementClient +} + +// NewOperationsClient creates an instance of the OperationsClient client. +func NewOperationsClient(subscriptionID string) OperationsClient { + return NewOperationsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewOperationsClientWithBaseURI creates an instance of the OperationsClient +// client. +func NewOperationsClientWithBaseURI(baseURI string, subscriptionID string) OperationsClient { + return OperationsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// List lists all of the available insights REST API operations. +func (client OperationsClient) List() (result OperationListResult, err error) { + req, err := client.ListPreparer() + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.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, "appinsights.OperationsClient", "List", resp, "Failure sending request") + return + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.OperationsClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client OperationsClient) ListPreparer() (*http.Request, error) { + const APIVersion = "2015-05-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPath("/providers/microsoft.insights/operations"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// 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) +} + +// 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 +} + +// ListNextResults retrieves the next set of results, if any. +func (client OperationsClient) ListNextResults(lastResults OperationListResult) (result OperationListResult, err error) { + req, err := lastResults.OperationListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "appinsights.OperationsClient", "List", nil, "Failure preparing next results request") + } + if req == nil { + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "appinsights.OperationsClient", "List", resp, "Failure sending next results request") + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.OperationsClient", "List", resp, "Failure responding to next results request") + } + + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/appinsights/version.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/appinsights/version.go new file mode 100755 index 000000000000..d8e37bc801d5 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/appinsights/version.go @@ -0,0 +1,29 @@ +package appinsights + +// 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 1.0.1.0 +// 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/v10.0.2-beta arm-appinsights/" +} + +// Version returns the semantic version (see http://semver.org) of the client. +func Version() string { + return "v10.0.2-beta" +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/appinsights/webtests.go b/vendor/github.com/Azure/azure-sdk-for-go/arm/appinsights/webtests.go new file mode 100755 index 000000000000..509dfe804c65 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/appinsights/webtests.go @@ -0,0 +1,499 @@ +package appinsights + +// 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 1.0.1.0 +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "net/http" +) + +// WebTestsClient is the composite Swagger for Application Insights Management +// Client +type WebTestsClient struct { + ManagementClient +} + +// NewWebTestsClient creates an instance of the WebTestsClient client. +func NewWebTestsClient(subscriptionID string) WebTestsClient { + return NewWebTestsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewWebTestsClientWithBaseURI creates an instance of the WebTestsClient +// client. +func NewWebTestsClientWithBaseURI(baseURI string, subscriptionID string) WebTestsClient { + return WebTestsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CreateOrUpdate creates or updates an Application Insights web test +// definition. +// +// resourceGroupName is the name of the resource group. webTestName is the name +// of the Application Insights webtest resource. webTestDefinition is +// properties that need to be specified to create or update an Application +// Insights web test definition. +func (client WebTestsClient) CreateOrUpdate(resourceGroupName string, webTestName string, webTestDefinition WebTest) (result WebTest, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: webTestDefinition, + Constraints: []validation.Constraint{{Target: "webTestDefinition.WebTestProperties", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "webTestDefinition.WebTestProperties.SyntheticMonitorID", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "webTestDefinition.WebTestProperties.WebTestName", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "webTestDefinition.WebTestProperties.Locations", Name: validation.Null, Rule: true, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewErrorWithValidationError(err, "appinsights.WebTestsClient", "CreateOrUpdate") + } + + req, err := client.CreateOrUpdatePreparer(resourceGroupName, webTestName, webTestDefinition) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.WebTestsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "appinsights.WebTestsClient", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.WebTestsClient", "CreateOrUpdate", resp, "Failure responding to request") + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client WebTestsClient) CreateOrUpdatePreparer(resourceGroupName string, webTestName string, webTestDefinition WebTest) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + "webTestName": autorest.Encode("path", webTestName), + } + + const APIVersion = "2015-05-01" + 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.insights/webtests/{webTestName}", pathParameters), + autorest.WithJSON(webTestDefinition), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client WebTestsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client WebTestsClient) CreateOrUpdateResponder(resp *http.Response) (result WebTest, 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 an Application Insights web test. +// +// resourceGroupName is the name of the resource group. webTestName is the name +// of the Application Insights webtest resource. +func (client WebTestsClient) Delete(resourceGroupName string, webTestName string) (result autorest.Response, err error) { + req, err := client.DeletePreparer(resourceGroupName, webTestName) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.WebTestsClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "appinsights.WebTestsClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.WebTestsClient", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client WebTestsClient) DeletePreparer(resourceGroupName string, webTestName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + "webTestName": autorest.Encode("path", webTestName), + } + + const APIVersion = "2015-05-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/webtests/{webTestName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client WebTestsClient) DeleteSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client WebTestsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get get a specific Application Insights web test definition. +// +// resourceGroupName is the name of the resource group. webTestName is the name +// of the Application Insights webtest resource. +func (client WebTestsClient) Get(resourceGroupName string, webTestName string) (result WebTest, err error) { + req, err := client.GetPreparer(resourceGroupName, webTestName) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.WebTestsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "appinsights.WebTestsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.WebTestsClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client WebTestsClient) GetPreparer(resourceGroupName string, webTestName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + "webTestName": autorest.Encode("path", webTestName), + } + + const APIVersion = "2015-05-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/webtests/{webTestName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client WebTestsClient) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client WebTestsClient) GetResponder(resp *http.Response) (result WebTest, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List get all Application Insights web test alerts definitioned within a +// subscription. +func (client WebTestsClient) List() (result WebTestListResult, err error) { + req, err := client.ListPreparer() + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.WebTestsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "appinsights.WebTestsClient", "List", resp, "Failure sending request") + return + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.WebTestsClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client WebTestsClient) ListPreparer() (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-05-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/microsoft.insights/webtests", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client WebTestsClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client WebTestsClient) ListResponder(resp *http.Response) (result WebTestListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListNextResults retrieves the next set of results, if any. +func (client WebTestsClient) ListNextResults(lastResults WebTestListResult) (result WebTestListResult, err error) { + req, err := lastResults.WebTestListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "appinsights.WebTestsClient", "List", nil, "Failure preparing next results request") + } + if req == nil { + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "appinsights.WebTestsClient", "List", resp, "Failure sending next results request") + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.WebTestsClient", "List", resp, "Failure responding to next results request") + } + + return +} + +// ListByResourceGroup get all Application Insights web tests defined within a +// specified resource group. +// +// resourceGroupName is the name of the resource group. +func (client WebTestsClient) ListByResourceGroup(resourceGroupName string) (result WebTestListResult, err error) { + req, err := client.ListByResourceGroupPreparer(resourceGroupName) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.WebTestsClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + resp, err := client.ListByResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "appinsights.WebTestsClient", "ListByResourceGroup", resp, "Failure sending request") + return + } + + result, err = client.ListByResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.WebTestsClient", "ListByResourceGroup", resp, "Failure responding to request") + } + + return +} + +// ListByResourceGroupPreparer prepares the ListByResourceGroup request. +func (client WebTestsClient) ListByResourceGroupPreparer(resourceGroupName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-05-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/webtests", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client WebTestsClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (client WebTestsClient) ListByResourceGroupResponder(resp *http.Response) (result WebTestListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListByResourceGroupNextResults retrieves the next set of results, if any. +func (client WebTestsClient) ListByResourceGroupNextResults(lastResults WebTestListResult) (result WebTestListResult, err error) { + req, err := lastResults.WebTestListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "appinsights.WebTestsClient", "ListByResourceGroup", nil, "Failure preparing next results request") + } + if req == nil { + return + } + + resp, err := client.ListByResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "appinsights.WebTestsClient", "ListByResourceGroup", resp, "Failure sending next results request") + } + + result, err = client.ListByResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.WebTestsClient", "ListByResourceGroup", resp, "Failure responding to next results request") + } + + return +} + +// UpdateTags creates or updates an Application Insights web test definition. +// +// resourceGroupName is the name of the resource group. webTestName is the name +// of the Application Insights webtest resource. webTestTags is updated tag +// information to set into the web test instance. +func (client WebTestsClient) UpdateTags(resourceGroupName string, webTestName string, webTestTags TagsResource) (result WebTest, err error) { + req, err := client.UpdateTagsPreparer(resourceGroupName, webTestName, webTestTags) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.WebTestsClient", "UpdateTags", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateTagsSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "appinsights.WebTestsClient", "UpdateTags", resp, "Failure sending request") + return + } + + result, err = client.UpdateTagsResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "appinsights.WebTestsClient", "UpdateTags", resp, "Failure responding to request") + } + + return +} + +// UpdateTagsPreparer prepares the UpdateTags request. +func (client WebTestsClient) UpdateTagsPreparer(resourceGroupName string, webTestName string, webTestTags TagsResource) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + "webTestName": autorest.Encode("path", webTestName), + } + + const APIVersion = "2015-05-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsJSON(), + autorest.AsPatch(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/webtests/{webTestName}", pathParameters), + autorest.WithJSON(webTestTags), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare(&http.Request{}) +} + +// UpdateTagsSender sends the UpdateTags request. The method will close the +// http.Response Body if it receives an error. +func (client WebTestsClient) UpdateTagsSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req) +} + +// UpdateTagsResponder handles the response to the UpdateTags request. The method always +// closes the http.Response Body. +func (client WebTestsClient) UpdateTagsResponder(resp *http.Response) (result WebTest, 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/arm/security.tf b/vendor/github.com/Azure/azure-sdk-for-go/arm/security.tf new file mode 100644 index 000000000000..4cd5498fe8ec --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/arm/security.tf @@ -0,0 +1,145 @@ +resource "azurerm_network_security_group" "network_security_group" { + name = "kls-fabric-security-group" + location = "${var.location}" + resource_group_name = "${module.fabric_resource_group.name}" +} + +resource "azurerm_network_security_rule" "inbound_1" { + name = "KPMG1" + priority = 100 + direction = "Inbound" + access = "Allow" + protocol = "Tcp" + source_port_range = "*" + destination_port_range = "19000" + source_address_prefix = "158.180.192.10/32" + destination_address_prefix = "*" + resource_group_name = "${module.fabric_resource_group.name}" + network_security_group_name = "${azurerm_network_security_group.network_security_group.name}" +} + +resource "azurerm_network_security_rule" "inbound_2" { + name = "KPMG2" + priority = 110 + direction = "Inbound" + access = "Allow" + protocol = "Tcp" + source_port_range = "*" + destination_port_range = "19080" + source_address_prefix = "158.180.192.10/32" + destination_address_prefix = "*" + resource_group_name = "${module.fabric_resource_group.name}" + network_security_group_name = "${azurerm_network_security_group.network_security_group.name}" +} + +resource "azurerm_network_security_rule" "inbound_3" { + name = "KPMG3" + priority = 120 + direction = "Inbound" + access = "Allow" + protocol = "Tcp" + source_port_range = "*" + destination_port_range = "19000" + source_address_prefix = "154.58.104.234/32" + destination_address_prefix = "*" + resource_group_name = "${module.fabric_resource_group.name}" + network_security_group_name = "${azurerm_network_security_group.network_security_group.name}" +} + +resource "azurerm_network_security_rule" "inbound_4" { + name = "KPMG4" + priority = 130 + direction = "Inbound" + access = "Allow" + protocol = "Tcp" + source_port_range = "*" + destination_port_range = "19080" + source_address_prefix = "154.58.104.234/32" + destination_address_prefix = "*" + resource_group_name = "${module.fabric_resource_group.name}" + network_security_group_name = "${azurerm_network_security_group.network_security_group.name}" +} + +resource "azurerm_network_security_rule" "inbound_5" { + name = "KPMG5" + priority = 140 + direction = "Inbound" + access = "Allow" + protocol = "Tcp" + source_port_range = "*" + destination_port_range = "19000" + source_address_prefix = "213.123.41.146/32" + destination_address_prefix = "*" + resource_group_name = "${module.fabric_resource_group.name}" + network_security_group_name = "${azurerm_network_security_group.network_security_group.name}" +} + +resource "azurerm_network_security_rule" "inbound_6" { + name = "KPMG6" + priority = 150 + direction = "Inbound" + access = "Allow" + protocol = "Tcp" + source_port_range = "*" + destination_port_range = "19080" + source_address_prefix = "213.123.41.146/32" + destination_address_prefix = "*" + resource_group_name = "${module.fabric_resource_group.name}" + network_security_group_name = "${azurerm_network_security_group.network_security_group.name}" +} + +resource "azurerm_network_security_rule" "inbound_7" { + name = "KPMG7" + priority = 160 + direction = "Inbound" + access = "Allow" + protocol = "Tcp" + source_port_range = "*" + destination_port_range = "19000" + source_address_prefix = "213.123.41.194/32" + destination_address_prefix = "*" + resource_group_name = "${module.fabric_resource_group.name}" + network_security_group_name = "${azurerm_network_security_group.network_security_group.name}" +} + +resource "azurerm_network_security_rule" "inbound_8" { + name = "KPMG8" + priority = 170 + direction = "Inbound" + access = "Allow" + protocol = "Tcp" + source_port_range = "*" + destination_port_range = "19080" + source_address_prefix = "213.123.41.194/32" + destination_address_prefix = "*" + resource_group_name = "${module.fabric_resource_group.name}" + network_security_group_name = "${azurerm_network_security_group.network_security_group.name}" +} + +resource "azurerm_network_security_rule" "inbound_9" { + name = "KPMG9" + priority = 180 + direction = "Inbound" + access = "Allow" + protocol = "Tcp" + source_port_range = "*" + destination_port_range = "19000" + source_address_prefix = "212.183.140.18/32" + destination_address_prefix = "*" + resource_group_name = "${module.fabric_resource_group.name}" + network_security_group_name = "${azurerm_network_security_group.network_security_group.name}" +} + +resource "azurerm_network_security_rule" "inbound_10" { + name = "KPMG10" + priority = 190 + direction = "Inbound" + access = "Allow" + protocol = "Tcp" + source_port_range = "*" + destination_port_range = "19080" + source_address_prefix = "212.183.140.18/32" + destination_address_prefix = "*" + resource_group_name = "${module.fabric_resource_group.name}" + network_security_group_name = "${azurerm_network_security_group.network_security_group.name}" +} From 3bf895859f1be0ff40a8c61e01b87a0d885ad208 Mon Sep 17 00:00:00 2001 From: lstolyarov Date: Mon, 12 Jun 2017 20:15:31 +0100 Subject: [PATCH 2/9] adding vendor dependencies and minor changes --- azurerm/resource_arm_app_insights.go | 42 +++-- .../Azure/azure-sdk-for-go/arm/security.tf | 145 ------------------ vendor/vendor.json | 8 + 3 files changed, 33 insertions(+), 162 deletions(-) delete mode 100644 vendor/github.com/Azure/azure-sdk-for-go/arm/security.tf diff --git a/azurerm/resource_arm_app_insights.go b/azurerm/resource_arm_app_insights.go index 0e7a5bf3ee7c..24627a888ef5 100644 --- a/azurerm/resource_arm_app_insights.go +++ b/azurerm/resource_arm_app_insights.go @@ -9,12 +9,12 @@ import ( "github.com/hashicorp/terraform/helper/schema" ) -func resourceArmAppInsights() *schema.Resource { +func resourceArmApplicationInsights() *schema.Resource { return &schema.Resource{ - Create: resourceArmAppInsightsCreateOrUpdate, - Read: resourceArmAppInsightsRead, - Update: resourceArmAppInsightsCreateOrUpdate, - Delete: resourceArmAppInsightsDelete, + Create: resourceArmApplicationInsightsCreateOrUpdate, + Read: resourceArmApplicationInsightsRead, + Update: resourceArmApplicationInsightsCreateOrUpdate, + Delete: resourceArmApplicationInsightsDelete, Schema: map[string]*schema.Schema{ "resource_group_name": { @@ -42,11 +42,11 @@ func resourceArmAppInsights() *schema.Resource { } } -func resourceArmAppInsightsCreateOrUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceArmApplicationInsightsCreateOrUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*ArmClient) AppInsightsClient := client.appInsightsClient - log.Printf("[INFO] preparing arguments for Azure ARM App Insights creation.") + log.Printf("[INFO] preparing arguments for AzureRM Application Insights creation.") name := d.Get("name").(string) resGroup := d.Get("resource_group_name").(string) @@ -81,15 +81,15 @@ func resourceArmAppInsightsCreateOrUpdate(d *schema.ResourceData, meta interface return err } if read.ID == nil { - return fmt.Errorf("Cannot read app insights %s (resource group %s) ID", name, resGroup) + return fmt.Errorf("Cannot read application insights %s (resource group %s) ID", name, resGroup) } d.SetId(*read.ID) - return resourceArmAppInsightsRead(d, meta) + return resourceArmApplicationInsightsRead(d, meta) } -func resourceArmAppInsightsRead(d *schema.ResourceData, meta interface{}) error { +func resourceArmApplicationInsightsRead(d *schema.ResourceData, meta interface{}) error { AppInsightsClient := meta.(*ArmClient).appInsightsClient id, err := parseAzureResourceID(d.Id()) @@ -97,7 +97,7 @@ func resourceArmAppInsightsRead(d *schema.ResourceData, meta interface{}) error return err } - log.Printf("[DEBUG] Reading app insights %s", id) + log.Printf("[DEBUG] Reading application insights %s", id) resGroup := id.ResourceGroup name := id.Path["components"] @@ -108,19 +108,21 @@ func resourceArmAppInsightsRead(d *schema.ResourceData, meta interface{}) error d.SetId("") return nil } - return fmt.Errorf("Error making Read request on Azure app insights %s: %s", name, err) + return fmt.Errorf("Error making Read request on AzureRM application insights %s: %s", name, err) } - instrumentationKey := resp.ApplicationInsightsComponentProperties.InstrumentationKey - d.Set("name", name) d.Set("resource_group_name", resGroup) - d.Set("instrumentation_key", instrumentationKey) + if resp.ApplicationInsightsComponentProperties != nil { + d.Set("application_id", resp.ApplicationInsightsComponentProperties.ApplicationID) + d.Set("application_type", string(resp.ApplicationInsightsComponentProperties.ApplicationType)) + d.Set("instrumentation_key", resp.ApplicationInsightsComponentProperties.InstrumentationKey) + } return nil } -func resourceArmAppInsightsDelete(d *schema.ResourceData, meta interface{}) error { +func resourceArmApplicationInsightsDelete(d *schema.ResourceData, meta interface{}) error { AppInsightsClient := meta.(*ArmClient).appInsightsClient id, err := parseAzureResourceID(d.Id()) @@ -130,9 +132,15 @@ func resourceArmAppInsightsDelete(d *schema.ResourceData, meta interface{}) erro resGroup := id.ResourceGroup name := id.Path["components"] - log.Printf("[DEBUG] Deleting app insights %s: %s", resGroup, name) + log.Printf("[DEBUG] Deleting application insights %s: %s", resGroup, name) _, err = AppInsightsClient.Delete(resGroup, name) + if err != nil { + if accResp.StatusCode == http.StatusNotFound { + return nil + } + return fmt.Errorf("Error issuing AzureRM delete request for Application Insights '%s': %+v", name, err) + } return err } diff --git a/vendor/github.com/Azure/azure-sdk-for-go/arm/security.tf b/vendor/github.com/Azure/azure-sdk-for-go/arm/security.tf deleted file mode 100644 index 4cd5498fe8ec..000000000000 --- a/vendor/github.com/Azure/azure-sdk-for-go/arm/security.tf +++ /dev/null @@ -1,145 +0,0 @@ -resource "azurerm_network_security_group" "network_security_group" { - name = "kls-fabric-security-group" - location = "${var.location}" - resource_group_name = "${module.fabric_resource_group.name}" -} - -resource "azurerm_network_security_rule" "inbound_1" { - name = "KPMG1" - priority = 100 - direction = "Inbound" - access = "Allow" - protocol = "Tcp" - source_port_range = "*" - destination_port_range = "19000" - source_address_prefix = "158.180.192.10/32" - destination_address_prefix = "*" - resource_group_name = "${module.fabric_resource_group.name}" - network_security_group_name = "${azurerm_network_security_group.network_security_group.name}" -} - -resource "azurerm_network_security_rule" "inbound_2" { - name = "KPMG2" - priority = 110 - direction = "Inbound" - access = "Allow" - protocol = "Tcp" - source_port_range = "*" - destination_port_range = "19080" - source_address_prefix = "158.180.192.10/32" - destination_address_prefix = "*" - resource_group_name = "${module.fabric_resource_group.name}" - network_security_group_name = "${azurerm_network_security_group.network_security_group.name}" -} - -resource "azurerm_network_security_rule" "inbound_3" { - name = "KPMG3" - priority = 120 - direction = "Inbound" - access = "Allow" - protocol = "Tcp" - source_port_range = "*" - destination_port_range = "19000" - source_address_prefix = "154.58.104.234/32" - destination_address_prefix = "*" - resource_group_name = "${module.fabric_resource_group.name}" - network_security_group_name = "${azurerm_network_security_group.network_security_group.name}" -} - -resource "azurerm_network_security_rule" "inbound_4" { - name = "KPMG4" - priority = 130 - direction = "Inbound" - access = "Allow" - protocol = "Tcp" - source_port_range = "*" - destination_port_range = "19080" - source_address_prefix = "154.58.104.234/32" - destination_address_prefix = "*" - resource_group_name = "${module.fabric_resource_group.name}" - network_security_group_name = "${azurerm_network_security_group.network_security_group.name}" -} - -resource "azurerm_network_security_rule" "inbound_5" { - name = "KPMG5" - priority = 140 - direction = "Inbound" - access = "Allow" - protocol = "Tcp" - source_port_range = "*" - destination_port_range = "19000" - source_address_prefix = "213.123.41.146/32" - destination_address_prefix = "*" - resource_group_name = "${module.fabric_resource_group.name}" - network_security_group_name = "${azurerm_network_security_group.network_security_group.name}" -} - -resource "azurerm_network_security_rule" "inbound_6" { - name = "KPMG6" - priority = 150 - direction = "Inbound" - access = "Allow" - protocol = "Tcp" - source_port_range = "*" - destination_port_range = "19080" - source_address_prefix = "213.123.41.146/32" - destination_address_prefix = "*" - resource_group_name = "${module.fabric_resource_group.name}" - network_security_group_name = "${azurerm_network_security_group.network_security_group.name}" -} - -resource "azurerm_network_security_rule" "inbound_7" { - name = "KPMG7" - priority = 160 - direction = "Inbound" - access = "Allow" - protocol = "Tcp" - source_port_range = "*" - destination_port_range = "19000" - source_address_prefix = "213.123.41.194/32" - destination_address_prefix = "*" - resource_group_name = "${module.fabric_resource_group.name}" - network_security_group_name = "${azurerm_network_security_group.network_security_group.name}" -} - -resource "azurerm_network_security_rule" "inbound_8" { - name = "KPMG8" - priority = 170 - direction = "Inbound" - access = "Allow" - protocol = "Tcp" - source_port_range = "*" - destination_port_range = "19080" - source_address_prefix = "213.123.41.194/32" - destination_address_prefix = "*" - resource_group_name = "${module.fabric_resource_group.name}" - network_security_group_name = "${azurerm_network_security_group.network_security_group.name}" -} - -resource "azurerm_network_security_rule" "inbound_9" { - name = "KPMG9" - priority = 180 - direction = "Inbound" - access = "Allow" - protocol = "Tcp" - source_port_range = "*" - destination_port_range = "19000" - source_address_prefix = "212.183.140.18/32" - destination_address_prefix = "*" - resource_group_name = "${module.fabric_resource_group.name}" - network_security_group_name = "${azurerm_network_security_group.network_security_group.name}" -} - -resource "azurerm_network_security_rule" "inbound_10" { - name = "KPMG10" - priority = 190 - direction = "Inbound" - access = "Allow" - protocol = "Tcp" - source_port_range = "*" - destination_port_range = "19080" - source_address_prefix = "212.183.140.18/32" - destination_address_prefix = "*" - resource_group_name = "${module.fabric_resource_group.name}" - network_security_group_name = "${azurerm_network_security_group.network_security_group.name}" -} diff --git a/vendor/vendor.json b/vendor/vendor.json index c2a730060651..b430c3c4caff 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -2,6 +2,14 @@ "comment": "", "ignore": "appengine test github.com/hashicorp/nomad/", "package": [ + { + "checksumSHA1": "Beu5GwttkjDfz+YZ4q5L15R10Z8=", + "path": "github.com/Azure/azure-sdk-for-go/arm/appinsights", + "revision": "5841475edc7c8725d79885d635aa8956f97fdf0e", + "revisionTime": "2017-05-10T22:14:13Z", + "version": "=v10.0.2-beta", + "versionExact": "v10.0.2-beta" + }, { "checksumSHA1": "cmMpbgzcc+qBJOOO80ZmgLdij5I=", "path": "github.com/Azure/azure-sdk-for-go/arm/cdn", From a1bfccd34797898eeb3eb0289390e326c714939d Mon Sep 17 00:00:00 2001 From: lstolyarov Date: Mon, 12 Jun 2017 20:17:39 +0100 Subject: [PATCH 3/9] adding vendor dependencies and minor changes --- azurerm/provider.go | 2 +- azurerm/resource_arm_app_insights.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/azurerm/provider.go b/azurerm/provider.go index 69e6bc754177..41d816d947ad 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -120,7 +120,7 @@ func Provider() terraform.ResourceProvider { "azurerm_virtual_network": resourceArmVirtualNetwork(), "azurerm_virtual_network_peering": resourceArmVirtualNetworkPeering(), - "azurerm_app_insights": resourceArmAppInsights(), + "azurerm_application_insights": resourceArmApplicationInsights(), // These resources use the Riviera SDK "azurerm_dns_a_record": resourceArmDnsARecord(), diff --git a/azurerm/resource_arm_app_insights.go b/azurerm/resource_arm_app_insights.go index 24627a888ef5..165e6cea4d84 100644 --- a/azurerm/resource_arm_app_insights.go +++ b/azurerm/resource_arm_app_insights.go @@ -134,9 +134,9 @@ func resourceArmApplicationInsightsDelete(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Deleting application insights %s: %s", resGroup, name) - _, err = AppInsightsClient.Delete(resGroup, name) + resp, err := AppInsightsClient.Delete(resGroup, name) if err != nil { - if accResp.StatusCode == http.StatusNotFound { + if resp.StatusCode == http.StatusNotFound { return nil } return fmt.Errorf("Error issuing AzureRM delete request for Application Insights '%s': %+v", name, err) From c2fac3eef1e1361c21b52a6866ae493b96382c96 Mon Sep 17 00:00:00 2001 From: lstolyarov Date: Wed, 21 Jun 2017 17:42:13 +0100 Subject: [PATCH 4/9] adding acceptance tests --- azurerm/import_arm_app_insights_test.go | 34 +++++++++ azurerm/resource_arm_app_insights_test.go | 92 +++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 azurerm/import_arm_app_insights_test.go create mode 100644 azurerm/resource_arm_app_insights_test.go diff --git a/azurerm/import_arm_app_insights_test.go b/azurerm/import_arm_app_insights_test.go new file mode 100644 index 000000000000..c39ba73c87f2 --- /dev/null +++ b/azurerm/import_arm_app_insights_test.go @@ -0,0 +1,34 @@ +package azurerm + +import ( + "testing" + + "fmt" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAzureRMAppInsights_importBasic(t *testing.T) { + resourceName := "azurerm_application_insights.test" + + ri := acctest.RandInt() + config := fmt.Sprintf(testAccAzureRMApplicationInsights_basic, ri, ri, ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppInsightsDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/azurerm/resource_arm_app_insights_test.go b/azurerm/resource_arm_app_insights_test.go new file mode 100644 index 000000000000..5a41c9520eb5 --- /dev/null +++ b/azurerm/resource_arm_app_insights_test.go @@ -0,0 +1,92 @@ +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 TestAccAzureRMAppInsights_basic(t *testing.T) { + + ri := acctest.RandInt() + config := fmt.Sprintf(testAccAzureRMApplicationInsights_basic, ri, ri, ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppInsightsDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAppInsightsExists("azurerm_application_insights.test"), + ), + }, + }, + }) +} + +func testCheckAzureRMAppInsightsDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*ArmClient).appInsightsClient + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_application_insights" { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := conn.Get(resourceGroup, name) + + if err != nil { + return nil + } + + if resp.StatusCode != http.StatusNotFound { + return fmt.Errorf("App Insights still exists:\n%#v", resp.ApplicationInsightsComponentProperties) + } + } + + return nil +} + +func testCheckAzureRMAppInsightsExists(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 App Insights: %s", name) + } + + conn := testAccProvider.Meta().(*ArmClient).appInsightsClient + + resp, err := conn.Get(resourceGroup, name) + if err != nil { + return fmt.Errorf("Bad: Get on appInsightsClient: %s", err) + } + + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Bad: App Insights %q (resource group: %q) does not exist", name, resourceGroup) + } + + return nil + } +} + +var testAccAzureRMApplicationInsights_basic = ` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "West US" +} +` From 36d1680adf9c956a82cb9556cc567ea6d49b7d82 Mon Sep 17 00:00:00 2001 From: lstolyarov Date: Wed, 21 Jun 2017 18:19:45 +0100 Subject: [PATCH 5/9] making acc tests to pass --- azurerm/import_arm_app_insights_test.go | 2 +- azurerm/resource_arm_app_insights.go | 26 +++++++++++++---------- azurerm/resource_arm_app_insights_test.go | 10 +++++++-- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/azurerm/import_arm_app_insights_test.go b/azurerm/import_arm_app_insights_test.go index c39ba73c87f2..d61342ca42d1 100644 --- a/azurerm/import_arm_app_insights_test.go +++ b/azurerm/import_arm_app_insights_test.go @@ -13,7 +13,7 @@ func TestAccAzureRMAppInsights_importBasic(t *testing.T) { resourceName := "azurerm_application_insights.test" ri := acctest.RandInt() - config := fmt.Sprintf(testAccAzureRMApplicationInsights_basic, ri, ri, ri) + config := fmt.Sprintf(testAccAzureRMApplicationInsights_basic, ri, ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, diff --git a/azurerm/resource_arm_app_insights.go b/azurerm/resource_arm_app_insights.go index 165e6cea4d84..e4104b734fa9 100644 --- a/azurerm/resource_arm_app_insights.go +++ b/azurerm/resource_arm_app_insights.go @@ -7,6 +7,7 @@ import ( "github.com/Azure/azure-sdk-for-go/arm/appinsights" "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" ) func resourceArmApplicationInsights() *schema.Resource { @@ -27,10 +28,15 @@ func resourceArmApplicationInsights() *schema.Resource { Required: true, ForceNew: true, }, - "kind": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + "application_type": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + DiffSuppressFunc: ignoreCaseDiffSuppressFunc, + ValidateFunc: validation.StringInSlice([]string{ + string(appinsights.Web), + string(appinsights.Other), + }, true), }, "location": locationSchema(), "tags": tagsSchema(), @@ -50,24 +56,20 @@ func resourceArmApplicationInsightsCreateOrUpdate(d *schema.ResourceData, meta i name := d.Get("name").(string) resGroup := d.Get("resource_group_name").(string) - insightsType := "microsoft.insights/components" - kind := d.Get("kind").(string) + applicationType := d.Get("application_type").(string) location := d.Get("location").(string) tags := d.Get("tags").(map[string]interface{}) - requestSource := "IbizaAIExtension" applicationInsightsComponentProperties := appinsights.ApplicationInsightsComponentProperties{ ApplicationID: &name, - ApplicationType: appinsights.ApplicationType(insightsType), - RequestSource: appinsights.RequestSource(requestSource), + ApplicationType: appinsights.ApplicationType(applicationType), } insightProperties := appinsights.ApplicationInsightsComponent{ Name: &name, - Type: &insightsType, Location: &location, Tags: expandTags(tags), - Kind: &kind, + Kind: &applicationType, ApplicationInsightsComponentProperties: &applicationInsightsComponentProperties, } @@ -119,6 +121,8 @@ func resourceArmApplicationInsightsRead(d *schema.ResourceData, meta interface{} d.Set("instrumentation_key", resp.ApplicationInsightsComponentProperties.InstrumentationKey) } + flattenAndSetTags(d, resp.Tags) + return nil } diff --git a/azurerm/resource_arm_app_insights_test.go b/azurerm/resource_arm_app_insights_test.go index 5a41c9520eb5..ed57d5b6bf8d 100644 --- a/azurerm/resource_arm_app_insights_test.go +++ b/azurerm/resource_arm_app_insights_test.go @@ -13,7 +13,7 @@ import ( func TestAccAzureRMAppInsights_basic(t *testing.T) { ri := acctest.RandInt() - config := fmt.Sprintf(testAccAzureRMApplicationInsights_basic, ri, ri, ri) + config := fmt.Sprintf(testAccAzureRMApplicationInsights_basic, ri, ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -87,6 +87,12 @@ func testCheckAzureRMAppInsightsExists(name string) resource.TestCheckFunc { var testAccAzureRMApplicationInsights_basic = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" - location = "West US" + location = "West Europe" +} +resource "azurerm_application_insights" "test" { + name = "acctestappinsights-%d" + location = "West Europe" + resource_group_name = "${azurerm_resource_group.test.name}" + application_type = "web" } ` From f814fe283ad8110717fc16ca78a563ef9199dcf4 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 23 Jun 2017 14:10:53 +0100 Subject: [PATCH 6/9] Fixing up the PR comments --- azurerm/import_arm_app_insights_test.go | 8 ++-- azurerm/resource_arm_app_insights.go | 52 ++++++++++++++--------- azurerm/resource_arm_app_insights_test.go | 35 ++++++++------- 3 files changed, 55 insertions(+), 40 deletions(-) diff --git a/azurerm/import_arm_app_insights_test.go b/azurerm/import_arm_app_insights_test.go index d61342ca42d1..9abffb05a1a8 100644 --- a/azurerm/import_arm_app_insights_test.go +++ b/azurerm/import_arm_app_insights_test.go @@ -3,22 +3,20 @@ package azurerm import ( "testing" - "fmt" - "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" ) -func TestAccAzureRMAppInsights_importBasic(t *testing.T) { +func TestAccAzureRMApplicationInsights_importBasic(t *testing.T) { resourceName := "azurerm_application_insights.test" ri := acctest.RandInt() - config := fmt.Sprintf(testAccAzureRMApplicationInsights_basic, ri, ri) + config := testAccAzureRMApplicationInsights_basic(ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testCheckAzureRMAppInsightsDestroy, + CheckDestroy: testCheckAzureRMApplicationInsightsDestroy, Steps: []resource.TestStep{ { Config: config, diff --git a/azurerm/resource_arm_app_insights.go b/azurerm/resource_arm_app_insights.go index e4104b734fa9..8218cdb942e5 100644 --- a/azurerm/resource_arm_app_insights.go +++ b/azurerm/resource_arm_app_insights.go @@ -16,18 +16,25 @@ func resourceArmApplicationInsights() *schema.Resource { Read: resourceArmApplicationInsightsRead, Update: resourceArmApplicationInsightsCreateOrUpdate, Delete: resourceArmApplicationInsightsDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ - "resource_group_name": { + "name": { Type: schema.TypeString, Required: true, ForceNew: true, }, - "name": { + + "resource_group_name": { Type: schema.TypeString, Required: true, ForceNew: true, }, + + "location": locationSchema(), + "application_type": { Type: schema.TypeString, Required: true, @@ -38,8 +45,14 @@ func resourceArmApplicationInsights() *schema.Resource { string(appinsights.Other), }, true), }, - "location": locationSchema(), - "tags": tagsSchema(), + + "tags": tagsSchema(), + + "app_id": { + Type: schema.TypeString, + Computed: true, + }, + "instrumentation_key": { Type: schema.TypeString, Computed: true, @@ -49,8 +62,7 @@ func resourceArmApplicationInsights() *schema.Resource { } func resourceArmApplicationInsightsCreateOrUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*ArmClient) - AppInsightsClient := client.appInsightsClient + client := meta.(*ArmClient).appInsightsClient log.Printf("[INFO] preparing arguments for AzureRM Application Insights creation.") @@ -68,22 +80,22 @@ func resourceArmApplicationInsightsCreateOrUpdate(d *schema.ResourceData, meta i insightProperties := appinsights.ApplicationInsightsComponent{ Name: &name, Location: &location, - Tags: expandTags(tags), Kind: &applicationType, ApplicationInsightsComponentProperties: &applicationInsightsComponentProperties, + Tags: expandTags(tags), } - _, err := AppInsightsClient.CreateOrUpdate(resGroup, name, insightProperties) + _, err := client.CreateOrUpdate(resGroup, name, insightProperties) if err != nil { return err } - read, err := AppInsightsClient.Get(resGroup, name) + read, err := client.Get(resGroup, name) if err != nil { return err } if read.ID == nil { - return fmt.Errorf("Cannot read application insights %s (resource group %s) ID", name, resGroup) + return fmt.Errorf("Cannot read AzureRM Application Insights '%s' (Resource Group %s) ID", name, resGroup) } d.SetId(*read.ID) @@ -92,33 +104,35 @@ func resourceArmApplicationInsightsCreateOrUpdate(d *schema.ResourceData, meta i } func resourceArmApplicationInsightsRead(d *schema.ResourceData, meta interface{}) error { - AppInsightsClient := meta.(*ArmClient).appInsightsClient + client := meta.(*ArmClient).appInsightsClient id, err := parseAzureResourceID(d.Id()) if err != nil { return err } - log.Printf("[DEBUG] Reading application insights %s", id) + log.Printf("[DEBUG] Reading AzureRM Application Insights '%s'", id) resGroup := id.ResourceGroup name := id.Path["components"] - resp, err := AppInsightsClient.Get(resGroup, name) + resp, err := client.Get(resGroup, name) if err != nil { if resp.StatusCode == http.StatusNotFound { d.SetId("") return nil } - return fmt.Errorf("Error making Read request on AzureRM application insights %s: %s", name, err) + return fmt.Errorf("Error making Read request on AzureRM Application Insights '%s': %+v", name, err) } d.Set("name", name) d.Set("resource_group_name", resGroup) - if resp.ApplicationInsightsComponentProperties != nil { - d.Set("application_id", resp.ApplicationInsightsComponentProperties.ApplicationID) - d.Set("application_type", string(resp.ApplicationInsightsComponentProperties.ApplicationType)) - d.Set("instrumentation_key", resp.ApplicationInsightsComponentProperties.InstrumentationKey) + d.Set("location", azureRMNormalizeLocation(*resp.Location)) + + if props := resp.ApplicationInsightsComponentProperties; props != nil { + d.Set("application_type", string(props.ApplicationType)) + d.Set("app_id", props.AppID) + d.Set("instrumentation_key", props.InstrumentationKey) } flattenAndSetTags(d, resp.Tags) @@ -136,7 +150,7 @@ func resourceArmApplicationInsightsDelete(d *schema.ResourceData, meta interface resGroup := id.ResourceGroup name := id.Path["components"] - log.Printf("[DEBUG] Deleting application insights %s: %s", resGroup, name) + log.Printf("[DEBUG] Deleting AzureRM Application Insights '%s' (resource group '%s')", name, resGroup) resp, err := AppInsightsClient.Delete(resGroup, name) if err != nil { diff --git a/azurerm/resource_arm_app_insights_test.go b/azurerm/resource_arm_app_insights_test.go index ed57d5b6bf8d..005b34f2a4b7 100644 --- a/azurerm/resource_arm_app_insights_test.go +++ b/azurerm/resource_arm_app_insights_test.go @@ -10,27 +10,27 @@ import ( "github.com/hashicorp/terraform/terraform" ) -func TestAccAzureRMAppInsights_basic(t *testing.T) { +func TestAccAzureRMApplicationInsights_basic(t *testing.T) { ri := acctest.RandInt() - config := fmt.Sprintf(testAccAzureRMApplicationInsights_basic, ri, ri) + config := testAccAzureRMApplicationInsights_basic(ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testCheckAzureRMAppInsightsDestroy, + CheckDestroy: testCheckAzureRMApplicationInsightsDestroy, Steps: []resource.TestStep{ { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppInsightsExists("azurerm_application_insights.test"), + testCheckAzureRMApplicationInsightsExists("azurerm_application_insights.test"), ), }, }, }) } -func testCheckAzureRMAppInsightsDestroy(s *terraform.State) error { +func testCheckAzureRMApplicationInsightsDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*ArmClient).appInsightsClient for _, rs := range s.RootModule().Resources { @@ -48,14 +48,14 @@ func testCheckAzureRMAppInsightsDestroy(s *terraform.State) error { } if resp.StatusCode != http.StatusNotFound { - return fmt.Errorf("App Insights still exists:\n%#v", resp.ApplicationInsightsComponentProperties) + return fmt.Errorf("Application Insights still exists:\n%#v", resp.ApplicationInsightsComponentProperties) } } return nil } -func testCheckAzureRMAppInsightsExists(name string) resource.TestCheckFunc { +func testCheckAzureRMApplicationInsightsExists(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] @@ -77,22 +77,25 @@ func testCheckAzureRMAppInsightsExists(name string) resource.TestCheckFunc { } if resp.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: App Insights %q (resource group: %q) does not exist", name, resourceGroup) + return fmt.Errorf("Bad: Application Insights '%q' (resource group: '%q') does not exist", name, resourceGroup) } return nil } } -var testAccAzureRMApplicationInsights_basic = ` +func testAccAzureRMApplicationInsights_basic(rInt int) string { + return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "West Europe" + name = "acctestRG-%d" + location = "West Europe" } + resource "azurerm_application_insights" "test" { - name = "acctestappinsights-%d" - location = "West Europe" - resource_group_name = "${azurerm_resource_group.test.name}" - application_type = "web" + name = "acctestappinsights-%d" + location = "West Europe" + resource_group_name = "${azurerm_resource_group.test.name}" + application_type = "web" +} +`, rInt, rInt) } -` From ce4c4d94b2c0137f8539f6909c1dc186b44255b3 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 23 Jun 2017 15:50:46 +0100 Subject: [PATCH 7/9] Added tests covering the `other` application type --- azurerm/import_arm_app_insights_test.go | 28 +++++++++++++-- azurerm/resource_arm_app_insights_test.go | 42 +++++++++++++++++++++-- 2 files changed, 65 insertions(+), 5 deletions(-) diff --git a/azurerm/import_arm_app_insights_test.go b/azurerm/import_arm_app_insights_test.go index 9abffb05a1a8..21e70686ed2a 100644 --- a/azurerm/import_arm_app_insights_test.go +++ b/azurerm/import_arm_app_insights_test.go @@ -7,11 +7,35 @@ import ( "github.com/hashicorp/terraform/helper/resource" ) -func TestAccAzureRMApplicationInsights_importBasic(t *testing.T) { +func TestAccAzureRMApplicationInsights_importBasicWeb(t *testing.T) { resourceName := "azurerm_application_insights.test" ri := acctest.RandInt() - config := testAccAzureRMApplicationInsights_basic(ri) + config := testAccAzureRMApplicationInsights_basicWeb(ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMApplicationInsightsDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMApplicationInsights_importBasicOther(t *testing.T) { + resourceName := "azurerm_application_insights.test" + + ri := acctest.RandInt() + config := testAccAzureRMApplicationInsights_basicWeb(ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, diff --git a/azurerm/resource_arm_app_insights_test.go b/azurerm/resource_arm_app_insights_test.go index 005b34f2a4b7..1ee45ea22404 100644 --- a/azurerm/resource_arm_app_insights_test.go +++ b/azurerm/resource_arm_app_insights_test.go @@ -10,10 +10,30 @@ import ( "github.com/hashicorp/terraform/terraform" ) -func TestAccAzureRMApplicationInsights_basic(t *testing.T) { +func TestAccAzureRMApplicationInsights_basicWeb(t *testing.T) { ri := acctest.RandInt() - config := testAccAzureRMApplicationInsights_basic(ri) + config := testAccAzureRMApplicationInsights_basicWeb(ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMApplicationInsightsDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApplicationInsightsExists("azurerm_application_insights.test"), + ), + }, + }, + }) +} + +func TestAccAzureRMApplicationInsights_basicOther(t *testing.T) { + + ri := acctest.RandInt() + config := testAccAzureRMApplicationInsights_basicOther(ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -84,7 +104,7 @@ func testCheckAzureRMApplicationInsightsExists(name string) resource.TestCheckFu } } -func testAccAzureRMApplicationInsights_basic(rInt int) string { +func testAccAzureRMApplicationInsights_basicWeb(rInt int) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -99,3 +119,19 @@ resource "azurerm_application_insights" "test" { } `, rInt, rInt) } + +func testAccAzureRMApplicationInsights_basicOther(rInt int) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "West Europe" +} + +resource "azurerm_application_insights" "test" { + name = "acctestappinsights-%d" + location = "West Europe" + resource_group_name = "${azurerm_resource_group.test.name}" + application_type = "other" +} +`, rInt, rInt) +} From 6860ffe6824fec64dab8f429a57069d571e40a19 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 23 Jun 2017 16:47:48 +0100 Subject: [PATCH 8/9] Renaming app_insights -> application_insights --- ...p_insights_test.go => import_arm_application_insights_test.go} | 0 ...e_arm_app_insights.go => resource_arm_application_insights.go} | 0 ...insights_test.go => resource_arm_application_insights_test.go} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename azurerm/{import_arm_app_insights_test.go => import_arm_application_insights_test.go} (100%) rename azurerm/{resource_arm_app_insights.go => resource_arm_application_insights.go} (100%) rename azurerm/{resource_arm_app_insights_test.go => resource_arm_application_insights_test.go} (100%) diff --git a/azurerm/import_arm_app_insights_test.go b/azurerm/import_arm_application_insights_test.go similarity index 100% rename from azurerm/import_arm_app_insights_test.go rename to azurerm/import_arm_application_insights_test.go diff --git a/azurerm/resource_arm_app_insights.go b/azurerm/resource_arm_application_insights.go similarity index 100% rename from azurerm/resource_arm_app_insights.go rename to azurerm/resource_arm_application_insights.go diff --git a/azurerm/resource_arm_app_insights_test.go b/azurerm/resource_arm_application_insights_test.go similarity index 100% rename from azurerm/resource_arm_app_insights_test.go rename to azurerm/resource_arm_application_insights_test.go From 39f4b66c071d31c387b84c87cf5420145fc7dc78 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 23 Jun 2017 16:54:54 +0100 Subject: [PATCH 9/9] Adding documentation for Application Insights --- website/azurerm.erb | 13 +++- .../docs/r/application_insights.html.markdown | 62 +++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 website/docs/r/application_insights.html.markdown diff --git a/website/azurerm.erb b/website/azurerm.erb index 95c5b39791cf..9390565995a2 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -21,7 +21,7 @@ > azurerm_resource_group - + > azurerm_public_ip @@ -37,6 +37,17 @@ + > + Application Insights Resources + + + > CDN Resources