Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

refactoring appinsights use the new sdk version #718

Merged
merged 4 commits into from
Jan 19, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"sync"
"time"

"github.com/Azure/azure-sdk-for-go/arm/appinsights"
"github.com/Azure/azure-sdk-for-go/arm/authorization"
"github.com/Azure/azure-sdk-for-go/arm/automation"
"github.com/Azure/azure-sdk-for-go/arm/cdn"
Expand All @@ -33,6 +32,7 @@ import (
"github.com/Azure/azure-sdk-for-go/arm/resources/resources"
"github.com/Azure/azure-sdk-for-go/arm/resources/subscriptions"
keyVault "github.com/Azure/azure-sdk-for-go/dataplane/keyvault"
"github.com/Azure/azure-sdk-for-go/services/appinsights/mgmt/2015-05-01/insights"
Copy link
Contributor

Choose a reason for hiding this comment

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

Given the package insights is used in multiple places within Azure (e.g. #478), I think it might be sensible to alias this import - I'll push a commit to update this

"github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2017-09-30/containerservice"
"github.com/Azure/azure-sdk-for-go/services/search/mgmt/2015-08-19/search"
"github.com/Azure/azure-sdk-for-go/services/servicebus/mgmt/2017-04-01/servicebus"
Expand Down Expand Up @@ -127,7 +127,7 @@ type ArmClient struct {
keyVaultClient keyvault.VaultsClient
keyVaultManagementClient keyVault.ManagementClient

appInsightsClient appinsights.ComponentsClient
appInsightsClient insights.ComponentsClient

// Authentication
roleAssignmentsClient authorization.RoleAssignmentsClient
Expand Down Expand Up @@ -600,13 +600,7 @@ func getArmClient(c *authentication.Config) (*ArmClient, error) {
dc.SkipResourceProviderRegistration = c.SkipProviderRegistration
client.deploymentsClient = dc

ai := appinsights.NewComponentsClientWithBaseURI(endpoint, c.SubscriptionID)
setUserAgent(&ai.Client)
ai.Authorizer = auth
ai.Sender = sender
ai.SkipResourceProviderRegistration = c.SkipProviderRegistration
client.appInsightsClient = ai

client.registerAppInsightsClient(endpoint, c.SubscriptionID, auth, sender)
client.registerAutomationClients(endpoint, c.SubscriptionID, auth, sender)
client.registerAuthentication(endpoint, graphEndpoint, c.SubscriptionID, c.TenantID, auth, graphAuth, sender)
client.registerCDNClients(endpoint, c.SubscriptionID, auth, sender)
Expand All @@ -625,6 +619,15 @@ func getArmClient(c *authentication.Config) (*ArmClient, error) {
return &client, nil
}

func (c *ArmClient) registerAppInsightsClient(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) {
ai := insights.NewComponentsClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&ai.Client)
ai.Authorizer = auth
ai.Sender = sender
ai.SkipResourceProviderRegistration = c.skipProviderRegistration
c.appInsightsClient = ai
}

func (c *ArmClient) registerAutomationClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) {
accountClient := automation.NewAccountClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&accountClient.Client)
Expand Down
25 changes: 14 additions & 11 deletions azurerm/resource_arm_application_insights.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"net/http"

"github.com/Azure/azure-sdk-for-go/arm/appinsights"
"github.com/Azure/azure-sdk-for-go/services/appinsights/mgmt/2015-05-01/insights"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
Expand Down Expand Up @@ -38,8 +38,8 @@ func resourceArmApplicationInsights() *schema.Resource {
ForceNew: true,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
ValidateFunc: validation.StringInSlice([]string{
string(appinsights.Web),
string(appinsights.Other),
string(insights.Web),
string(insights.Other),
}, true),
},

Expand All @@ -60,6 +60,7 @@ func resourceArmApplicationInsights() *schema.Resource {

func resourceArmApplicationInsightsCreateOrUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).appInsightsClient
ctx := meta.(*ArmClient).StopContext

log.Printf("[INFO] preparing arguments for AzureRM Application Insights creation.")

Expand All @@ -69,25 +70,25 @@ func resourceArmApplicationInsightsCreateOrUpdate(d *schema.ResourceData, meta i
location := d.Get("location").(string)
tags := d.Get("tags").(map[string]interface{})

applicationInsightsComponentProperties := appinsights.ApplicationInsightsComponentProperties{
applicationInsightsComponentProperties := insights.ApplicationInsightsComponentProperties{
ApplicationID: &name,
ApplicationType: appinsights.ApplicationType(applicationType),
ApplicationType: insights.ApplicationType(applicationType),
}

insightProperties := appinsights.ApplicationInsightsComponent{
insightProperties := insights.ApplicationInsightsComponent{
Name: &name,
Location: &location,
Kind: &applicationType,
ApplicationInsightsComponentProperties: &applicationInsightsComponentProperties,
Tags: expandTags(tags),
}

_, err := client.CreateOrUpdate(resGroup, name, insightProperties)
_, err := client.CreateOrUpdate(ctx, resGroup, name, insightProperties)
if err != nil {
return err
}

read, err := client.Get(resGroup, name)
read, err := client.Get(ctx, resGroup, name)
if err != nil {
return err
}
Expand All @@ -102,6 +103,7 @@ func resourceArmApplicationInsightsCreateOrUpdate(d *schema.ResourceData, meta i

func resourceArmApplicationInsightsRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).appInsightsClient
ctx := meta.(*ArmClient).StopContext

id, err := parseAzureResourceID(d.Id())
if err != nil {
Expand All @@ -113,7 +115,7 @@ func resourceArmApplicationInsightsRead(d *schema.ResourceData, meta interface{}
resGroup := id.ResourceGroup
name := id.Path["components"]

resp, err := client.Get(resGroup, name)
resp, err := client.Get(ctx, resGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
d.SetId("")
Expand All @@ -138,7 +140,8 @@ func resourceArmApplicationInsightsRead(d *schema.ResourceData, meta interface{}
}

func resourceArmApplicationInsightsDelete(d *schema.ResourceData, meta interface{}) error {
AppInsightsClient := meta.(*ArmClient).appInsightsClient
client := meta.(*ArmClient).appInsightsClient
ctx := meta.(*ArmClient).StopContext

id, err := parseAzureResourceID(d.Id())
if err != nil {
Expand All @@ -149,7 +152,7 @@ func resourceArmApplicationInsightsDelete(d *schema.ResourceData, meta interface

log.Printf("[DEBUG] Deleting AzureRM Application Insights '%s' (resource group '%s')", name, resGroup)

resp, err := AppInsightsClient.Delete(resGroup, name)
resp, err := client.Delete(ctx, resGroup, name)
if err != nil {
if resp.StatusCode == http.StatusNotFound {
return nil
Expand Down
6 changes: 4 additions & 2 deletions azurerm/resource_arm_application_insights_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func TestAccAzureRMApplicationInsights_basicOther(t *testing.T) {

func testCheckAzureRMApplicationInsightsDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*ArmClient).appInsightsClient
ctx := testAccProvider.Meta().(*ArmClient).StopContext

for _, rs := range s.RootModule().Resources {
if rs.Type != "azurerm_application_insights" {
Expand All @@ -61,7 +62,7 @@ func testCheckAzureRMApplicationInsightsDestroy(s *terraform.State) error {
name := rs.Primary.Attributes["name"]
resourceGroup := rs.Primary.Attributes["resource_group_name"]

resp, err := conn.Get(resourceGroup, name)
resp, err := conn.Get(ctx, resourceGroup, name)

if err != nil {
return nil
Expand Down Expand Up @@ -90,8 +91,9 @@ func testCheckAzureRMApplicationInsightsExists(name string) resource.TestCheckFu
}

conn := testAccProvider.Meta().(*ArmClient).appInsightsClient
ctx := testAccProvider.Meta().(*ArmClient).StopContext

resp, err := conn.Get(resourceGroup, name)
resp, err := conn.Get(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("Bad: Get on appInsightsClient: %+v", err)
}
Expand Down
53 changes: 0 additions & 53 deletions vendor/github.com/Azure/azure-sdk-for-go/arm/appinsights/client.go

This file was deleted.

Loading