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

Update Terraform for Azure Logs #58

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
134 changes: 94 additions & 40 deletions deploy.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@
* the License.
*/

### Terraform Setup ###
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 3.50.0"
}
}
}


### Providers ###
provider "azurerm" {
features {}
}

### Variables ###
variable "lm_company_name" {
type = string
Expand All @@ -38,6 +54,48 @@ variable "azure_client_id" {
description = "Azure Application Client ID"
}

variable "lm_apiClientDebug" {
type = bool
description = "(optional) Enable API debugging"
default = false
}

variable "lm_logLevel" {
type = string
description = "(optional) LM Log App log level"
default = "WARNING"
validation {
condition = contains([
"TRACE",
"DEBUG",
"INFORMATION",
"WARNING",
"ERROR",
"CRITICAL",
"NONE",
], upper(var.lm_logLevel) )
error_message = "lm_logLevel must be one of `TRACE`,`DEBUG`,`INFORMATION`,`WARNING`,`ERROR`,`CRITICAL`,`NONE`"
}
}

variable "lm_logRegexScrubPattern" {
type = string
description = "(optional) Regex scrub string"
default = null
}

variable "lm_sourceCodeBranch" {
type = string
description = "(optional) Code branch to deploy lm azure app from."
default = "master"
}

variable "lm_metadataKeys" {
type = string
description = "(Optional) Metadata keys to include in records"
default = "resourceId"
}

variable "tags" {
description = "Tags given to the resources created by this template"
type = map(string)
Expand All @@ -59,12 +117,10 @@ locals {
deployedBy = "Terraform"
}
)
}

### Providers ###
provider "azurerm" {
version = ">= 2.0.0"
features {}
lm_auth_string = "{ \"LM_ACCESS_ID\" : \"${var.lm_access_id}\", \"LM_ACCESS_KEY\" : \"${var.lm_access_key}\", \"LM_BEARER_TOKEN\" : \"\" }"
lm_package_url = "https://github.com/logicmonitor/lm-logs-azure/raw/${var.lm_sourceCodeBranch}/package/lm-logs-azure.zip"
lm_web_job_storage = "DefaultEndpointsProtocol=https;AccountName=${azurerm_storage_account.lm_logs.name};AccountKey=${azurerm_storage_account.lm_logs.primary_access_key}"
}

### Resources ###
Expand Down Expand Up @@ -127,57 +183,55 @@ resource "azurerm_storage_account" "lm_logs" {
tags = local.tags
}

## App Service Plan ##
resource "azurerm_app_service_plan" "lm_logs" {
## Service Plan ##
resource "azurerm_service_plan" "lm_logs" {
name = "${local.namespace}-service-plan"
resource_group_name = azurerm_resource_group.lm_logs.name
location = var.azure_region
kind = "FunctionApp"
reserved = true
os_type = "Linux"
sku_name = "S1"
tags = local.tags
sku {
tier = "Standard"
size = "S1"
}

}

## Function App ##
resource "azurerm_function_app" "lm_logs" {
## Linux Function App ##
resource "azurerm_linux_function_app" "lm_logs" {
name = local.namespace
resource_group_name = azurerm_resource_group.lm_logs.name
location = var.azure_region
app_service_plan_id = azurerm_app_service_plan.lm_logs.id
service_plan_id = azurerm_service_plan.lm_logs.id
storage_account_name = azurerm_storage_account.lm_logs.name
storage_account_access_key = azurerm_storage_account.lm_logs.primary_access_key
os_type = "linux"
https_only = true
version = "~3"
tags = local.tags

site_config {
always_on = true
linux_fx_version = "java|11"
use_32_bit_worker_process = false
always_on = true
use_32_bit_worker = false
http2_enabled = true

application_stack{
java_version = 11
}
}

app_settings = {
FUNCTIONS_WORKER_RUNTIME = "java"
FUNCTIONS_EXTENSION_VERSION = "~3"
WEBSITE_RUN_FROM_PACKAGE = "https://github.com/logicmonitor/lm-logs-azure/raw/master/package/lm-logs-azure.zip"
LogsEventHubConnectionString = azurerm_eventhub_authorization_rule.lm_logs_listener.primary_connection_string
LogicMonitorCompanyName = var.lm_company_name
LogicMonitorAccessId = var.lm_access_id
LogicMonitorAccessKey = var.lm_access_key
AzureClientID = var.azure_client_id
/* Uncomment to set custom connection timeout */
# LogApiClientConnectTimeout = 10000

/* Uncomment to set custom read timeout */
# LogApiClientReadTimeout = 10000

/* Uncomment to turn on HTTP debugging */
# LogApiClientDebugging = true

/* Uncomment to remove matching text from the logs */
# LogRegexScrub = "\\d+\\.\\d+\\.\\d+\\.\\d+"
APPLICATION_NAME = "lm-logs-azure"
AzureClientID = var.azure_client_id
AzureWebJobsStorage = local.lm_web_job_storage
FUNCTION_APP_EDIT_MODE = "readwrite"
FUNCTIONS_WORKER_RUNTIME = "java"
FUNCTIONS_WORKER_PROCESS_COUNT = 1
Include_Metadata_keys = var.lm_metadataKeys
LogsEventHubConnectionString = azurerm_eventhub_authorization_rule.lm_logs_listener.primary_connection_string
LM_COMPANY = var.lm_company_name
LM_AUTH = local.lm_auth_string
LogApiClientConnectTimeout = 10000
LogApiClientReadTimeout = 10000
LogApiClientDebugging = var.lm_apiClientDebug
LOG_LEVEL = var.lm_logLevel
LogRegexScrub = var.lm_logRegexScrubPattern
WEBSITE_RUN_FROM_PACKAGE = local.lm_package_url
}
}

Expand Down