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

App insights resource #42706

Merged
merged 9 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions eng/Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<PackageReference Update="Azure.AI.OpenAI" Version="1.0.0-beta.9" />
<PackageReference Update="Azure.ResourceManager" Version="1.11.0-alpha.20240310.2" />
<PackageReference Update="Azure.ResourceManager.AppConfiguration" Version="1.3.0-alpha.20240309.1" />
<PackageReference Update="Azure.ResourceManager.ApplicationInsights" Version="1.0.0-alpha.20240314.2" />
<PackageReference Update="Azure.ResourceManager.AppService" Version="1.1.0-alpha.20240310.1" />
<PackageReference Update="Azure.ResourceManager.Authorization" Version="1.2.0-alpha.20240309.1" />
<PackageReference Update="Azure.ResourceManager.CognitiveServices" Version="1.4.0-alpha.20240309.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ public partial class AppConfigurationStore : Azure.Provisioning.Resource<Azure.R
protected override string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; }
}
}
namespace Azure.Provisioning.ApplicationInsights
{
public partial class ApplicationInsightsComponent : Azure.Provisioning.Resource<Azure.ResourceManager.ApplicationInsights.ApplicationInsightsComponentData>
{
public ApplicationInsightsComponent(Azure.Provisioning.IConstruct scope, string kind = "web", string applicationType = "web", Azure.Provisioning.ResourceManager.ResourceGroup? parent = null, string name = "appinsights", string version = "2020-02-02", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func<string, Azure.ResourceManager.ApplicationInsights.ApplicationInsightsComponentData>)) { }
public static Azure.Provisioning.ApplicationInsights.ApplicationInsightsComponent FromExisting(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.ResourceManager.ResourceGroup? parent = null) { throw null; }
protected override string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; }
}
}
namespace Azure.Provisioning.AppService
{
public partial class AppServicePlan : Azure.Provisioning.Resource<Azure.ResourceManager.AppService.AppServicePlanData>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ public partial class AppConfigurationStore : Azure.Provisioning.Resource<Azure.R
protected override string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; }
}
}
namespace Azure.Provisioning.ApplicationInsights
{
public partial class ApplicationInsightsComponent : Azure.Provisioning.Resource<Azure.ResourceManager.ApplicationInsights.ApplicationInsightsComponentData>
{
public ApplicationInsightsComponent(Azure.Provisioning.IConstruct scope, string kind = "web", string applicationType = "web", Azure.Provisioning.ResourceManager.ResourceGroup? parent = null, string name = "appinsights", string version = "2020-02-02", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func<string, Azure.ResourceManager.ApplicationInsights.ApplicationInsightsComponentData>)) { }
public static Azure.Provisioning.ApplicationInsights.ApplicationInsightsComponent FromExisting(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.ResourceManager.ResourceGroup? parent = null) { throw null; }
protected override string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; }
}
}
namespace Azure.Provisioning.AppService
{
public partial class AppServicePlan : Azure.Provisioning.Resource<Azure.ResourceManager.AppService.AppServicePlanData>
Expand Down
2 changes: 1 addition & 1 deletion sdk/provisioning/Azure.Provisioning/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "net",
"TagPrefix": "net/provisioning/Azure.Provisioning",
"Tag": "net/provisioning/Azure.Provisioning_1a8a692724"
"Tag": "net/provisioning/Azure.Provisioning_336cf2dff6"
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<PackageReference Include="Azure.ResourceManager.Search" />
<PackageReference Include="Azure.ResourceManager.EventHubs" />
<PackageReference Include="Azure.ResourceManager.SignalR" />
<PackageReference Include="Azure.ResourceManager.ApplicationInsights" />
<PackageReference Include="System.ClientModel" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Azure.Core;
using Azure.Provisioning.CosmosDB;
using Azure.Provisioning.ResourceManager;
using Azure.ResourceManager.ApplicationInsights;
using Azure.ResourceManager.ApplicationInsights.Models;

namespace Azure.Provisioning.ApplicationInsights
{
/// <summary>
/// Represents an Application Insights component.
/// </summary>
public class ApplicationInsightsComponent : Resource<ApplicationInsightsComponentData>
{
// https://learn.microsoft.com/azure/templates/microsoft.insights/2020-02-02/components?pivots=deployment-language-bicep
private const string ResourceTypeName = "Microsoft.Insights/components";
// https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/applicationinsights/Azure.ResourceManager.ApplicationInsights/src/Generated/RestOperations/ComponentsRestOperations.cs#L36
internal const string DefaultVersion = "2020-02-02";

private static readonly Func<string, ApplicationInsightsComponentData> Empty = (name) => ArmApplicationInsightsModelFactory.ApplicationInsightsComponentData();

/// <summary>
/// Creates a new instance of the <see cref="ApplicationInsightsComponentData"/> class.
/// </summary>
/// <param name="scope">The scope.</param>
/// <param name="kind">The kind.</param>
/// <param name="applicationType">The application type.</param>
/// <param name="parent">The parent.</param>
/// <param name="name">The name.</param>
/// <param name="version">The version.</param>
/// <param name="location">The location</param>
public ApplicationInsightsComponent(
IConstruct scope,
string kind = "web",
string applicationType = "web",
ResourceGroup? parent = default,
string name = "appinsights",
string version = DefaultVersion,
AzureLocation? location = default)
: this(scope, parent, name, version, location, false, (name) => ArmApplicationInsightsModelFactory.ApplicationInsightsComponentData(
name: name,
location: location ?? Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS,
kind: kind,
applicationType: applicationType))
{
AssignProperty(data => data.Name, GetAzureName(scope, name));
}

private ApplicationInsightsComponent(
IConstruct scope,
ResourceGroup? parent,
string name,
string version = DefaultVersion,
AzureLocation? location = default,
bool isExisting = false,
Func<string, ApplicationInsightsComponentData>? creator = null)
: base(scope, parent, name, ResourceTypeName, version, creator ?? Empty, isExisting)
{
}

/// <summary>
/// Creates a new instance of the <see cref="CosmosDBAccount"/> class referencing an existing instance.
/// </summary>
/// <param name="scope">The scope.</param>
/// <param name="name">The resource name.</param>
/// <param name="parent">The resource group.</param>
/// <returns>The KeyVault instance.</returns>
public static ApplicationInsightsComponent FromExisting(IConstruct scope, string name, ResourceGroup? parent = null)
=> new ApplicationInsightsComponent(scope, parent: parent, name: name, isExisting: true);

/// <inheritdoc/>
protected override string GetAzureName(IConstruct scope, string resourceName) => GetGloballyUniqueName(resourceName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
targetScope = 'resourceGroup'

@description('')
param location string = resourceGroup().location


resource applicationInsightsComponent_FpLXFVEKV 'Microsoft.Insights/components@2020-02-02' = {
name: toLower(take(concat('appinsights', uniqueString(resourceGroup().id)), 24))
location: location
kind: 'web'
properties: {
Application_Type: 'web'
WorkspaceResourceId: 'workspaceId'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ resource signalRService_d95Jninqk 'Microsoft.SignalRService/signalR@2022-02-01'
name: 'existingSignalR'
}

resource applicationInsightsComponent_OdiSCimF0 'Microsoft.Insights/components@2020-02-02' existing = {
name: 'existingAppInsights'
}

resource applicationSettingsResource_6DtpuGITF 'Microsoft.Web/sites/config@2021-02-01' = {
parent: webSite_C2Aq73IJb
name: 'appsettings'
Expand Down
15 changes: 15 additions & 0 deletions sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Azure.Provisioning.Resources;
using Azure.Provisioning.Storage;
using Azure.Provisioning.AppConfiguration;
using Azure.Provisioning.ApplicationInsights;
using Azure.Provisioning.Authorization;
using Azure.Provisioning.CognitiveServices;
using Azure.Provisioning.CosmosDB;
Expand Down Expand Up @@ -433,6 +434,18 @@ public async Task SignalR()
await ValidateBicepAsync(interactiveMode: true);
}

[RecordedTest]
public async Task AppInsights()
{
TestInfrastructure infrastructure = new TestInfrastructure(configuration: new Configuration { UseInteractiveMode = true });
var appInsights = new ApplicationInsightsComponent(infrastructure);
appInsights.Properties.WorkspaceResourceId = "workspaceId";

infrastructure.Build(GetOutputPath());

await ValidateBicepAsync(interactiveMode: true);
}

[RecordedTest]
public async Task WebSiteUsingL2()
{
Expand Down Expand Up @@ -767,6 +780,8 @@ public async Task ExistingResources()

infra.AddResource(SignalRService.FromExisting(infra, "'existingSignalR'", rg));

infra.AddResource(ApplicationInsightsComponent.FromExisting(infra, "'existingAppInsights'", rg));

infra.Build(GetOutputPath());

await ValidateBicepAsync(BinaryData.FromObjectAsJson(
Expand Down