Skip to content

Commit

Permalink
Merge pull request #7 from Think-Cube/patch-1
Browse files Browse the repository at this point in the history
Reorganize
  • Loading branch information
spy86 authored Mar 14, 2024
2 parents 2dfc221 + 1f5b565 commit c60aad1
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 81 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Maciej Michalski
Copyright (c) 2024 ThinkCube

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.15 |
| <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) | 3.3.0 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.6.4 |
| <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) | 3.94.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | 3.3.0 |
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | 3.94.0 |

## Modules

Expand All @@ -20,32 +20,33 @@ No modules.

| Name | Type |
|------|------|
| [azurerm_application_insights.main](https://registry.terraform.io/providers/hashicorp/azurerm/3.3.0/docs/resources/application_insights) | resource |
| [azurerm_log_analytics_workspace.main](https://registry.terraform.io/providers/hashicorp/azurerm/3.3.0/docs/resources/log_analytics_workspace) | resource |
| [azurerm_client_config.current](https://registry.terraform.io/providers/hashicorp/azurerm/3.3.0/docs/data-sources/client_config) | data source |
| [azurerm_resource_group.rg](https://registry.terraform.io/providers/hashicorp/azurerm/3.3.0/docs/data-sources/resource_group) | data source |
| [azurerm_application_insights.main](https://registry.terraform.io/providers/hashicorp/azurerm/3.94.0/docs/resources/application_insights) | resource |
| [azurerm_log_analytics_workspace.main](https://registry.terraform.io/providers/hashicorp/azurerm/3.94.0/docs/resources/log_analytics_workspace) | resource |
| [azurerm_client_config.current](https://registry.terraform.io/providers/hashicorp/azurerm/3.94.0/docs/data-sources/client_config) | data source |
| [azurerm_resource_group.main](https://registry.terraform.io/providers/hashicorp/azurerm/3.94.0/docs/data-sources/resource_group) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_application_insights_name"></a> [application\_insights\_name](#input\_application\_insights\_name) | Specifies the name of the Application Insights component. Changing this forces a new resource to be created. | `string` | n/a | yes |
| <a name="input_application_insights_type"></a> [application\_insights\_type](#input\_application\_insights\_type) | Specifies the type of Application Insights to create. Valid values are ios for iOS, java for Java web, MobileCenter for App Center, Node.JS for Node.js, other for General, phone for Windows Phone, store for Windows Store and web for ASP.NET. Please note these values are case sensitive; unmatched values are treated as ASP.NET by Azure. Changing this forces a new resource to be created. | `string` | `"web"` | no |
| <a name="input_default_tags"></a> [default\_tags](#input\_default\_tags) | A mapping of tags to assign to the resource. | `map` | n/a | yes |
| <a name="input_environment"></a> [environment](#input\_environment) | Var used for backend container name key | `string` | `"dev"` | no |
| <a name="input_application_insights_type"></a> [application\_insights\_type](#input\_application\_insights\_type) | Specifies the type of Application Insights to create. Valid values are ios for iOS, java for Java web, MobileCenter for App Center, nodejs for Node.js, and other for General. | `string` | `"web"` | no |
| <a name="input_default_tags"></a> [default\_tags](#input\_default\_tags) | A mapping of tags to assign to the resource. | `map(any)` | <pre>{<br> "ManagedByTerraform": "True"<br>}</pre> | no |
| <a name="input_environment"></a> [environment](#input\_environment) | Variable that defines the name of the environment. | `string` | `"dev"` | no |
| <a name="input_log_analytics_workspace_name"></a> [log\_analytics\_workspace\_name](#input\_log\_analytics\_workspace\_name) | Specifies the name of the Log Analytics Workspace. Workspace name should include 4-63 letters, digits or '-'. The '-' shouldn't be the first or the last symbol. Changing this forces a new resource to be created | `string` | n/a | yes |
| <a name="input_log_analytics_workspace_retention_in_days"></a> [log\_analytics\_workspace\_retention\_in\_days](#input\_log\_analytics\_workspace\_retention\_in\_days) | The workspace data retention in days. Possible values are either 7 (Free Tier only) or range between 30 and 730. | `number` | `"30"` | no |
| <a name="input_log_analytics_workspace_sku"></a> [log\_analytics\_workspace\_sku](#input\_log\_analytics\_workspace\_sku) | Specifies the SKU of the Log Analytics Workspace. Possible values are Free, PerNode, Premium, Standard, Standalone, Unlimited, CapacityReservation, and PerGB2018 (new SKU as of 2018-04-03). Defaults to PerGB2018. | `string` | `"PerGB2018"` | no |
| <a name="input_region"></a> [region](#input\_region) | Region in which resources are deployed | `string` | `"weu"` | no |
| <a name="input_resource_group_location"></a> [resource\_group\_location](#input\_resource\_group\_location) | The location/region where the virtual network is created. Changing this forces a new resource to be created. | `string` | `"West Europe"` | no |
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | The name of the resource group in which to create the virtual network. | `string` | n/a | yes |
| <a name="input_region"></a> [region](#input\_region) | Region in which resources are deployed. | `string` | `"weu"` | no |
| <a name="input_resource_group_location"></a> [resource\_group\_location](#input\_resource\_group\_location) | Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. | `string` | `"West Europe"` | no |
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | TThe name of the resource group in which to create the Application Insights component. Changing this forces a new resource to be created. | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_app_id"></a> [app\_id](#output\_app\_id) | Instrumentation Key for this Application Insights component. |
| <a name="output_id"></a> [id](#output\_id) | ID of the Application Insights component. |
| <a name="output_instrumentation_key"></a> [instrumentation\_key](#output\_instrumentation\_key) | App ID associated with this Application Insights component. |
<!-- END_TF_DOCS -->
```
| <a name="output_application_insights_id"></a> [application\_insights\_id](#output\_application\_insights\_id) | The ID of the created Application Insights instance. |
| <a name="output_log_analytics_workspace_customer_id"></a> [log\_analytics\_workspace\_customer\_id](#output\_log\_analytics\_workspace\_customer\_id) | Customer ID of the created Log Analytics Workspace. |
| <a name="output_log_analytics_workspace_id"></a> [log\_analytics\_workspace\_id](#output\_log\_analytics\_workspace\_id) | The ID of the created Log Analytics Workspace. |
| <a name="output_log_analytics_workspace_primary_shared_key"></a> [log\_analytics\_workspace\_primary\_shared\_key](#output\_log\_analytics\_workspace\_primary\_shared\_key) | Primary shared key of the created Log Analytics Workspace. |
| <a name="output_log_analytics_workspace_secondary_shared_key"></a> [log\_analytics\_workspace\_secondary\_shared\_key](#output\_log\_analytics\_workspace\_secondary\_shared\_key) | Secondary shared key of the created Log Analytics Workspace. |
<!-- END_TF_DOCS -->
13 changes: 6 additions & 7 deletions application_insights.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
resource "azurerm_application_insights" "main" {
name = "${var.environment}-${var.application_insights_name}-${var.region}-appi"
location = "${data.azurerm_resource_group.rg.location}"
resource_group_name = "${data.azurerm_resource_group.rg.name}"
application_type = "${var.application_insights_type}"
workspace_id = "${azurerm_log_analytics_workspace.main.id}"
location = data.azurerm_resource_group.main.location
resource_group_name = data.azurerm_resource_group.main.name
application_type = var.application_insights_type
workspace_id = azurerm_log_analytics_workspace.main.id
tags = var.default_tags

tags = "${var.default_tags}"

depends_on = [ azurerm_log_analytics_workspace.main ]
depends_on = [azurerm_log_analytics_workspace.main]
}
8 changes: 4 additions & 4 deletions backend.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.3.0"
source = "hashicorp/azurerm"
version = "3.94.0"
}
}
required_version = ">= 0.15"
}
required_version = ">= 1.6.4"
}
53 changes: 44 additions & 9 deletions examples/application_insights/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
## How to use
# Azure Application Insights Terraform Module

```
This Terraform module provisions an Azure Application Insights instance and a Log Analytics Workspace, integrated with the specified settings.

## Usage

### Example

```hcl
provider "azurerm" {
features {}
}
module "app-insights" {
source = "spy86/app-insights/azure"
version = "1.0.4"
source = "Think-Cube/app-insights/azure"
version = "1.0.0"
application_insights_name = "dd5ce8a0"
log_analytics_workspace_name = "bf308ab897c3"
resource_group_name = "weu-test-rg"
Expand All @@ -19,11 +25,40 @@ module "app-insights" {
region = "weu"
default_tags = {
Administrator = "Someone"
Department = "IT"
CostCentre = "ABC123"
ContactPerson = "[email protected]"
Administrator = "John Doe"
Department = "IT"
CostCentre = "CC123"
ContactPerson = "Jane Smith"
ManagedByTerraform = "True"
}
}
```
```

### Variables

* `application_insights_name`: Name of the Azure Application Insights instance.
* `log_analytics_workspace_name`: Name of the Log Analytics Workspace.
* `resource_group_name`: Name of the Azure resource group.
* `resource_group_location`: Location of the Azure resource group.
* `application_insights_type`: Type of Application Insights (e.g., web).
* `environment`: Environment for the resources (e.g., dev, prod).
* `log_analytics_workspace_retention_in_days`: Retention period for Log Analytics data (in days).
* `log_analytics_workspace_sku`: SKU for the Log Analytics Workspace.
* `region`: Azure region for the resources.
* `default_tags`: Default tags to be applied to all resources.

### Outputs

* `application_insights_id`: The ID of the created Application Insights instance.
* `log_analytics_workspace_id`: The ID of the created Log Analytics Workspace.
* `log_analytics_workspace_primary_shared_key`: Primary shared key of the created Log Analytics Workspace.
* `log_analytics_workspace_secondary_shared_key`: Secondary shared key of the created Log Analytics Workspace.
* `log_analytics_workspace_customer_id`: Customer ID of the created Log Analytics Workspace.

## License

This project is licensed under the [MIT License](https://opensource.org/licenses/MIT).

## Contribution

Feel free to contribute by opening issues or pull requests. Your feedback and improvements are highly appreciated!
11 changes: 5 additions & 6 deletions log_analytics_workspace.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
resource "azurerm_log_analytics_workspace" "main" {
name = "${var.environment}-${var.log_analytics_workspace_name}-${var.region}-log"
location = "${data.azurerm_resource_group.rg.location}"
resource_group_name = "${data.azurerm_resource_group.rg.name}"
sku = "${var.log_analytics_workspace_sku}"
retention_in_days = "${var.log_analytics_workspace_retention_in_days}"

tags = "${var.default_tags}"
location = data.azurerm_resource_group.main.location
resource_group_name = data.azurerm_resource_group.main.name
sku = var.log_analytics_workspace_sku
retention_in_days = var.log_analytics_workspace_retention_in_days
tags = var.default_tags
}
4 changes: 2 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
data "azurerm_client_config" "current" {}

data "azurerm_resource_group" "rg" {
name = "${var.resource_group_name}"
data "azurerm_resource_group" "main" {
name = var.resource_group_name
}
34 changes: 21 additions & 13 deletions output.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
output "id" {
description = "ID of the Application Insights component."
value = "${azurerm_application_insights.main.id}"
sensitive = false
output "application_insights_id" {
description = "The ID of the created Application Insights instance."
value = azurerm_application_insights.main.id
}
output "instrumentation_key" {
description = "App ID associated with this Application Insights component."
value = "${azurerm_application_insights.main.instrumentation_key}"
sensitive = false

output "log_analytics_workspace_id" {
description = "The ID of the created Log Analytics Workspace."
value = azurerm_log_analytics_workspace.main.id
}

output "log_analytics_workspace_primary_shared_key" {
description = "Primary shared key of the created Log Analytics Workspace."
value = azurerm_log_analytics_workspace.main.primary_shared_key
}

output "app_id" {
description = "Instrumentation Key for this Application Insights component."
value = "${azurerm_application_insights.main.app_id}"
sensitive = false
}
output "log_analytics_workspace_secondary_shared_key" {
description = "Secondary shared key of the created Log Analytics Workspace."
value = azurerm_log_analytics_workspace.main.secondary_shared_key
}

output "log_analytics_workspace_customer_id" {
description = "Customer ID of the created Log Analytics Workspace."
value = azurerm_log_analytics_workspace.main.customer_id
}
56 changes: 35 additions & 21 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,69 @@
# Common vars
###########################
variable "environment" {
description = "Var used for backend container name key"
type = string
default = "dev"
description = "Variable that defines the name of the environment."
type = string
default = "dev"
}
variable "default_tags" {
description = "A mapping of tags to assign to the resource."
type = map
type = map(any)
default = {
"ManagedByTerraform" = "True"
}
}
variable "region" {
description = "Region in which resources are deployed"
type = string
default = "weu"
description = "Region in which resources are deployed."
type = string
default = "weu"
}
###########################
# Resource groups vars
###########################
variable "resource_group_location" {
description = "The location/region where the virtual network is created. Changing this forces a new resource to be created."
default = "West Europe"
type = string
description = "Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created."
default = "West Europe"
type = string
}
variable "resource_group_name" {
description = "The name of the resource group in which to create the virtual network."
type = string
description = "TThe name of the resource group in which to create the Application Insights component. Changing this forces a new resource to be created."
type = string
}

###########################
# Application Insights Service vars
###########################
variable "application_insights_name" {
description = "Specifies the name of the Application Insights component. Changing this forces a new resource to be created."
type = string
type = string
}
variable "application_insights_type" {
description = "Specifies the type of Application Insights to create. Valid values are ios for iOS, java for Java web, MobileCenter for App Center, Node.JS for Node.js, other for General, phone for Windows Phone, store for Windows Store and web for ASP.NET. Please note these values are case sensitive; unmatched values are treated as ASP.NET by Azure. Changing this forces a new resource to be created."
type = string
default = "web"
description = "Specifies the type of Application Insights to create. Valid values are ios for iOS, java for Java web, MobileCenter for App Center, nodejs for Node.js, and other for General."
type = string
default = "web"

validation {
condition = can(regex("^(ios|java|MobileCenter|nodejs|other)$", var.application_insights_type))
error_message = "Invalid value for application_insights_type. Valid values are ios, java, MobileCenter, nodejs, or other."
}
}
variable "log_analytics_workspace_name" {
description = "Specifies the name of the Log Analytics Workspace. Workspace name should include 4-63 letters, digits or '-'. The '-' shouldn't be the first or the last symbol. Changing this forces a new resource to be created"
type = string
type = string
}
variable "log_analytics_workspace_sku" {
description = "Specifies the SKU of the Log Analytics Workspace. Possible values are Free, PerNode, Premium, Standard, Standalone, Unlimited, CapacityReservation, and PerGB2018 (new SKU as of 2018-04-03). Defaults to PerGB2018."
type = string
default = "PerGB2018"
type = string
default = "PerGB2018"

validation {
condition = can(regex("^(Free|PerNode|Premium|Standard|Standalone|Unlimited|CapacityReservation|PerGB2018)$", var.log_analytics_workspace_sku))
error_message = "Invalid value for log_analytics_workspace_sku. Valid values are Free, PerNode, Premium, Standard, Standalone, Unlimited, CapacityReservation, or PerGB2018."
}
}

variable "log_analytics_workspace_retention_in_days" {
description = "The workspace data retention in days. Possible values are either 7 (Free Tier only) or range between 30 and 730."
type = number
default = "30"
type = number
default = "30"
}

0 comments on commit c60aad1

Please sign in to comment.