Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

New Resource: azurerm_application_insights_workbook #17368

Merged
merged 16 commits into from
Jul 20, 2022
Merged
Prev Previous commit
Next Next commit
update
ms-zhenhua committed Jun 30, 2022
commit be93fe4105f06ef041438e686c728fb9fc806522
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ func (r ApplicationInsightsWorkbookResource) ModelObject() interface{} {
}

func (r ApplicationInsightsWorkbookResource) IDValidationFunc() pluginsdk.SchemaValidateFunc {
return validate.WorkbookID
return applicationinsights.ValidateWorkbookID
}

func (r ApplicationInsightsWorkbookResource) Arguments() map[string]*pluginsdk.Schema {
@@ -131,7 +131,7 @@ func (r ApplicationInsightsWorkbookResource) Create() sdk.ResourceFunc {
return fmt.Errorf("decoding: %+v", err)
}

client := metadata.Client.AppInsights.ApplicationInsightsClient
client := metadata.Client.AppInsights.WorkbookClient
subscriptionId := metadata.Client.Account.SubscriptionId
id := applicationinsights.NewWorkbookID(subscriptionId, model.ResourceGroupName, model.Name)
existing, err := client.WorkbooksGet(ctx, id, applicationinsights.WorkbooksGetOperationOptions{CanFetchContent: utils.Bool(true)})
@@ -185,7 +185,7 @@ func (r ApplicationInsightsWorkbookResource) Update() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 30 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.AppInsights.ApplicationInsightsClient
client := metadata.Client.AppInsights.WorkbookClient

id, err := applicationinsights.ParseWorkbookID(metadata.ResourceData.Id())
if err != nil {
@@ -240,7 +240,7 @@ func (r ApplicationInsightsWorkbookResource) Read() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 5 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.AppInsights.ApplicationInsightsClient
client := metadata.Client.AppInsights.WorkbookClient

id, err := applicationinsights.ParseWorkbookID(metadata.ResourceData.Id())
if err != nil {
@@ -314,7 +314,7 @@ func (r ApplicationInsightsWorkbookResource) Delete() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 30 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.AppInsights.ApplicationInsightsClient
client := metadata.Client.AppInsights.WorkbookClient

id, err := applicationinsights.ParseWorkbookID(metadata.ResourceData.Id())
if err != nil {
Original file line number Diff line number Diff line change
@@ -97,7 +97,7 @@ func (r ApplicationInsightsWorkbookResource) Exists(ctx context.Context, clients
return nil, err
}

client := clients.AppInsights.ApplicationInsightsClient
client := clients.AppInsights.WorkbookClient
resp, err := client.WorkbooksGet(ctx, *id, applicationinsights.WorkbooksGetOperationOptions{CanFetchContent: utils.Bool(true)})
if err != nil {
if response.WasNotFound(resp.HttpResponse) {
34 changes: 17 additions & 17 deletions internal/services/applicationinsights/client/client.go
Original file line number Diff line number Diff line change
@@ -2,19 +2,19 @@ package client

import (
"github.com/Azure/azure-sdk-for-go/services/appinsights/mgmt/2020-02-02/insights"
"github.com/hashicorp/go-azure-sdk/resource-manager/applicationinsights/2022-04-01/applicationinsights"
workbook "github.com/hashicorp/go-azure-sdk/resource-manager/applicationinsights/2022-04-01/applicationinsights"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/applicationinsights/azuresdkhacks"
)

type Client struct {
AnalyticsItemsClient *insights.AnalyticsItemsClient
APIKeysClient *insights.APIKeysClient
ComponentsClient *insights.ComponentsClient
WebTestsClient *azuresdkhacks.WebTestsClient
BillingClient *insights.ComponentCurrentBillingFeaturesClient
SmartDetectionRuleClient *insights.ProactiveDetectionConfigurationsClient
ApplicationInsightsClient *applicationinsights.ApplicationInsightsClient
AnalyticsItemsClient *insights.AnalyticsItemsClient
APIKeysClient *insights.APIKeysClient
ComponentsClient *insights.ComponentsClient
WebTestsClient *azuresdkhacks.WebTestsClient
BillingClient *insights.ComponentCurrentBillingFeaturesClient
SmartDetectionRuleClient *insights.ProactiveDetectionConfigurationsClient
WorkbookClient *workbook.ApplicationInsightsClient
}

func NewClient(o *common.ClientOptions) *Client {
@@ -37,16 +37,16 @@ func NewClient(o *common.ClientOptions) *Client {
smartDetectionRuleClient := insights.NewProactiveDetectionConfigurationsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&smartDetectionRuleClient.Client, o.ResourceManagerAuthorizer)

applicationInsightsClient := applicationinsights.NewApplicationInsightsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&applicationInsightsClient.Client, o.ResourceManagerAuthorizer)
workbookClient := workbook.NewApplicationInsightsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&workbookClient.Client, o.ResourceManagerAuthorizer)

return &Client{
AnalyticsItemsClient: &analyticsItemsClient,
APIKeysClient: &apiKeysClient,
ComponentsClient: &componentsClient,
WebTestsClient: &webTestsWorkaroundClient,
BillingClient: &billingClient,
SmartDetectionRuleClient: &smartDetectionRuleClient,
ApplicationInsightsClient: &applicationInsightsClient,
AnalyticsItemsClient: &analyticsItemsClient,
APIKeysClient: &apiKeysClient,
ComponentsClient: &componentsClient,
WebTestsClient: &webTestsWorkaroundClient,
BillingClient: &billingClient,
SmartDetectionRuleClient: &smartDetectionRuleClient,
WorkbookClient: &workbookClient,
}
}
Original file line number Diff line number Diff line change
@@ -3,24 +3,8 @@ package validate
import (
"fmt"
"strings"

"github.com/hashicorp/go-azure-sdk/resource-manager/applicationinsights/2022-04-01/applicationinsights"
)

func WorkbookID(input interface{}, key string) (warnings []string, errors []error) {
v, ok := input.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected %q to be a string", key))
return
}

if _, err := applicationinsights.ParseWorkbookID(v); err != nil {
errors = append(errors, err)
}

return
}

func StringDoesNotContainUpperCaseLetter(input interface{}, k string) (warnings []string, errors []error) {
v, ok := input.(string)
if !ok {