Skip to content

azurermApplicationInsightsApiKey

Manages an Application Insights API key.

Example Usage

import * as cdktf from "cdktf";
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
const azurermResourceGroupExample = new azurerm.resourceGroup.ResourceGroup(
  this,
  "example",
  {
    location: "West Europe",
    name: "tf-test",
  }
);
const azurermApplicationInsightsExample =
  new azurerm.applicationInsights.ApplicationInsights(this, "example_1", {
    application_type: "web",
    location: azurermResourceGroupExample.location,
    name: "tf-test-appinsights",
    resource_group_name: azurermResourceGroupExample.name,
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermApplicationInsightsExample.overrideLogicalId("example");
const azurermApplicationInsightsApiKeyAuthenticateSdkControlChannel =
  new azurerm.applicationInsightsApiKey.ApplicationInsightsApiKey(
    this,
    "authenticate_sdk_control_channel",
    {
      application_insights_id: azurermApplicationInsightsExample.id,
      name: "tf-test-appinsights-authenticate-sdk-control-channel-api-key",
      read_permissions: ["agentconfig"],
    }
  );
const azurermApplicationInsightsApiKeyFullPermissions =
  new azurerm.applicationInsightsApiKey.ApplicationInsightsApiKey(
    this,
    "full_permissions",
    {
      application_insights_id: azurermApplicationInsightsExample.id,
      name: "tf-test-appinsights-full-permissions-api-key",
      read_permissions: [
        "agentconfig",
        "aggregate",
        "api",
        "draft",
        "extendqueries",
        "search",
      ],
      write_permissions: ["annotations"],
    }
  );
const azurermApplicationInsightsApiKeyReadTelemetry =
  new azurerm.applicationInsightsApiKey.ApplicationInsightsApiKey(
    this,
    "read_telemetry",
    {
      application_insights_id: azurermApplicationInsightsExample.id,
      name: "tf-test-appinsights-read-telemetry-api-key",
      read_permissions: [
        "aggregate",
        "api",
        "draft",
        "extendqueries",
        "search",
      ],
    }
  );
const azurermApplicationInsightsApiKeyWriteAnnotations =
  new azurerm.applicationInsightsApiKey.ApplicationInsightsApiKey(
    this,
    "write_annotations",
    {
      application_insights_id: azurermApplicationInsightsExample.id,
      name: "tf-test-appinsights-write-annotations-api-key",
      write_permissions: ["annotations"],
    }
  );
const cdktfTerraformOutputAuthenticateSdkControlChannel =
  new cdktf.TerraformOutput(this, "authenticate_sdk_control_channel_6", {
    value: azurermApplicationInsightsApiKeyAuthenticateSdkControlChannel.apiKey,
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
cdktfTerraformOutputAuthenticateSdkControlChannel.overrideLogicalId(
  "authenticate_sdk_control_channel"
);
new cdktf.TerraformOutput(this, "full_permissions_api_key", {
  value: azurermApplicationInsightsApiKeyFullPermissions.apiKey,
});
new cdktf.TerraformOutput(this, "read_telemetry_api_key", {
  value: azurermApplicationInsightsApiKeyReadTelemetry.apiKey,
});
new cdktf.TerraformOutput(this, "write_annotations_api_key", {
  value: azurermApplicationInsightsApiKeyWriteAnnotations.apiKey,
});

Argument Reference

The following arguments are supported:

  • name - (Required) Specifies the name of the Application Insights API key. Changing this forces a new resource to be created.

  • applicationInsightsId - (Required) The ID of the Application Insights component on which the API key operates. Changing this forces a new resource to be created.

  • readPermissions - (Optional) Specifies the list of read permissions granted to the API key. Valid values are agentconfig, aggregate, api, draft, extendqueries, search. Please note these values are case sensitive. Changing this forces a new resource to be created.

  • writePermissions - (Optional) Specifies the list of write permissions granted to the API key. Valid values are annotations. Please note these values are case sensitive. Changing this forces a new resource to be created.

-> Note: At least one read or write permission must be defined.

Attributes Reference

The following attributes are exported:

  • id - The ID of the Application Insights API key.

  • apiKey - The API Key secret (Sensitive).

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

  • create - (Defaults to 30 minutes) Used when creating the Application Insights API Key.
  • update - (Defaults to 30 minutes) Used when updating the Application Insights API Key.
  • read - (Defaults to 5 minutes) Used when retrieving the Application Insights API Key.
  • delete - (Defaults to 30 minutes) Used when deleting the Application Insights API Key.

Import

Application Insights API keys can be imported using the resourceId, e.g.

terraform import azurerm_application_insights_api_key.my_key /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Insights/components/instance1/apiKeys/00000000-0000-0000-0000-000000000000

-> Note: The secret apiKey cannot be retrieved during an import. You will need to edit the state by hand to set the secret value if you happen to have it backed up somewhere.