Skip to content

Commit

Permalink
Merge pull request #4 from clouddrove/Hurodata-51
Browse files Browse the repository at this point in the history
[Hurodata-51] add - existing app insights service can be attached to app service
  • Loading branch information
d4kverma committed Apr 13, 2023
2 parents 67daa73 + 81c0b43 commit 5ca0506
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions _example/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module "resource_group" {
version = "1.0.1"

label_order = ["name", "environment"]
name = "rg-rbac"
environment = "examplee"
name = "rg-example"
environment = "test"
location = "Canada Central"
}

Expand All @@ -18,7 +18,7 @@ module "app-service" {
source = "../../"
enabled = true
name = "app"
environment = "test"
environment = "teting"
label_order = ["name", "environment", ]
resource_group_name = module.resource_group.resource_group_name
location = module.resource_group.resource_group_location
Expand Down
15 changes: 8 additions & 7 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ locals {
# app insights
app_insights = try(data.azurerm_application_insights.main.0, try(azurerm_application_insights.main.0, {}))

default_app_settings = var.application_insights_enabled ? {
APPLICATION_INSIGHTS_IKEY = try(local.app_insights.instrumentation_key, "")
APPINSIGHTS_INSTRUMENTATIONKEY = try(local.app_insights.instrumentation_key, "")
APPLICATIONINSIGHTS_CONNECTION_STRING = try(local.app_insights.connection_string, "")
ApplicationInsightsAgent_EXTENSION_VERSION = "~2"
} : {}

# Default configuration for Site config block
default_site_config = {
always_on = "true"
Expand Down Expand Up @@ -79,7 +86,7 @@ resource "azurerm_app_service" "main" {
https_only = var.enable_https
client_cert_enabled = var.enable_client_certificate
tags = module.labels.tags
app_settings = var.app_settings
app_settings = merge(local.default_app_settings, var.app_settings)

dynamic "site_config" {
for_each = [merge(local.default_site_config, var.site_config)]
Expand Down Expand Up @@ -222,18 +229,12 @@ resource "azurerm_private_dns_zone_virtual_network_link" "vent-link" {
# App Insights

data "azurerm_application_insights" "main" {
depends_on = [
azurerm_app_service.main
]
count = var.application_insights_enabled && var.application_insights_id != null ? 1 : 0
name = split("/", var.application_insights_id)[8]
resource_group_name = split("/", var.application_insights_id)[4]
}

resource "azurerm_application_insights" "main" {
depends_on = [
azurerm_app_service.main
]
count = var.application_insights_enabled && var.application_insights_id == null ? 1 : 0
name = lower(format("app-insights-%s", var.app_insights_name))
location = var.location
Expand Down

0 comments on commit 5ca0506

Please sign in to comment.