From d9838cd5dc9cc9237c2908b5c752b904bc18d851 Mon Sep 17 00:00:00 2001 From: JFolberth Date: Mon, 14 Oct 2024 12:21:34 -0400 Subject: [PATCH] update for private link (#62) (#63) * update for private link (#62) * Update e2e.yml --------- Co-authored-by: bhanu <53189346+seekerofsai@users.noreply.github.com> Co-authored-by: Jack Tracey <41163455+jtracey93@users.noreply.github.com> --- README.md | 24 +++++ examples/privatelink/README.md | 163 ++++++++++++++++++++++++++++++ examples/privatelink/_footer.md | 4 + examples/privatelink/_header.md | 3 + examples/privatelink/main.tf | 84 +++++++++++++++ examples/privatelink/variables.tf | 9 ++ main.tf | 3 + variables.tf | 18 ++++ 8 files changed, 308 insertions(+) create mode 100644 examples/privatelink/README.md create mode 100644 examples/privatelink/_footer.md create mode 100644 examples/privatelink/_header.md create mode 100644 examples/privatelink/main.tf create mode 100644 examples/privatelink/variables.tf diff --git a/README.md b/README.md index 5d6e29f..f351f20 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,30 @@ Type: `bool` Default: `true` +### [internet\_ingestion\_enabled](#input\_internet\_ingestion\_enabled) + +Description: (Optional) Enables internet ingestion. Defaults to true. + +Type: `bool` + +Default: `true` + +### [internet\_query\_enabled](#input\_internet\_query\_enabled) + +Description: (Optional) Enables internet query. Defaults to true. + +Type: `bool` + +Default: `true` + +### [local\_authentication\_disabled](#input\_local\_authentication\_disabled) + +Description: (Optional) Disables local authentication. Defaults to false. + +Type: `bool` + +Default: `false` + ### [lock](#input\_lock) Description: Controls the Resource Lock configuration for this resource. The following properties can be specified: diff --git a/examples/privatelink/README.md b/examples/privatelink/README.md new file mode 100644 index 0000000..b4a1de5 --- /dev/null +++ b/examples/privatelink/README.md @@ -0,0 +1,163 @@ + +# Privatelink + +This deploys the module with local authentication disabled, public internet ingest, query disabled with private link. + +```hcl +terraform { + required_version = "~> 1.3" + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~> 3.74" + } + random = { + source = "hashicorp/random" + version = "~> 3.5" + } + } +} + +provider "azurerm" { + features {} +} + + +## Section to provide a random Azure region for the resource group +# This allows us to randomize the region for the resource group. +module "regions" { + source = "Azure/regions/azurerm" + version = "~> 0.3" +} + +# This allows us to randomize the region for the resource group. +resource "random_integer" "region_index" { + max = length(module.regions.regions) - 1 + min = 0 +} +## End of section to provide a random Azure region for the resource group + +# This ensures we have unique CAF compliant names for our resources. +module "naming" { + source = "Azure/naming/azurerm" + version = ">= 0.3.0" +} + +# This is required for resource modules +resource "azurerm_resource_group" "this" { + location = module.regions.regions[random_integer.region_index.result].name + name = module.naming.resource_group.name_unique +} + + +#Log Analytics Workspace for diagnostic settings. Required for workspace-based diagnostic settings. +resource "azurerm_log_analytics_workspace" "this" { + location = azurerm_resource_group.this.location + name = module.naming.log_analytics_workspace.name_unique + resource_group_name = azurerm_resource_group.this.name + sku = "PerGB2018" +} + + +# This is the module call +# Do not specify location here due to the randomization above. +# Leaving location as `null` will cause the module to use the resource group location +# with a data source. +module "test" { + source = "../.." + # source = "Azure/avm--/azurerm" + # ... + location = azurerm_resource_group.this.location + name = module.naming.application_insights.name_unique + resource_group_name = azurerm_resource_group.this.name + workspace_id = azurerm_log_analytics_workspace.this.id + enable_telemetry = var.enable_telemetry # see variables.tf + local_authentication_disabled = true + internet_ingestion_enabled = false + internet_query_enabled = false +} + +resource "azurerm_monitor_private_link_scope" "this" { + name = "privatelink.scope" + resource_group_name = azurerm_resource_group.this.name +} + +resource "azurerm_monitor_private_link_scoped_service" "this" { + linked_resource_id = module.test.resource_id + name = "privatelinkscopedservice.appinsights" + resource_group_name = azurerm_resource_group.this.name + scope_name = azurerm_monitor_private_link_scope.this.name +} +``` + + +## Requirements + +The following requirements are needed by this module: + +- [terraform](#requirement\_terraform) (~> 1.3) + +- [azurerm](#requirement\_azurerm) (~> 3.74) + +- [random](#requirement\_random) (~> 3.5) + +## Resources + +The following resources are used by this module: + +- [azurerm_log_analytics_workspace.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/log_analytics_workspace) (resource) +- [azurerm_monitor_private_link_scope.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_private_link_scope) (resource) +- [azurerm_monitor_private_link_scoped_service.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_private_link_scoped_service) (resource) +- [azurerm_resource_group.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) (resource) +- [random_integer.region_index](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/integer) (resource) + + +## Required Inputs + +No required inputs. + +## Optional Inputs + +The following input variables are optional (have default values): + +### [enable\_telemetry](#input\_enable\_telemetry) + +Description: This variable controls whether or not telemetry is enabled for the module. +For more information see . +If it is set to false, then no telemetry will be collected. + +Type: `bool` + +Default: `true` + +## Outputs + +No outputs. + +## Modules + +The following Modules are called: + +### [naming](#module\_naming) + +Source: Azure/naming/azurerm + +Version: >= 0.3.0 + +### [regions](#module\_regions) + +Source: Azure/regions/azurerm + +Version: ~> 0.3 + +### [test](#module\_test) + +Source: ../.. + +Version: + + +## Data Collection + +The software may collect information about you and your use of the software and send it to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may turn off the telemetry as described in the repository. There are also some features in the software that may enable you and Microsoft to collect data from users of your applications. If you use these features, you must comply with applicable law, including providing appropriate notices to users of your applications together with a copy of Microsoft’s privacy statement. Our privacy statement is located at . You can learn more about data collection and use in the help documentation and our privacy statement. Your use of the software operates as your consent to these practices. + \ No newline at end of file diff --git a/examples/privatelink/_footer.md b/examples/privatelink/_footer.md new file mode 100644 index 0000000..bc56bcb --- /dev/null +++ b/examples/privatelink/_footer.md @@ -0,0 +1,4 @@ + +## Data Collection + +The software may collect information about you and your use of the software and send it to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may turn off the telemetry as described in the repository. There are also some features in the software that may enable you and Microsoft to collect data from users of your applications. If you use these features, you must comply with applicable law, including providing appropriate notices to users of your applications together with a copy of Microsoft’s privacy statement. Our privacy statement is located at . You can learn more about data collection and use in the help documentation and our privacy statement. Your use of the software operates as your consent to these practices. diff --git a/examples/privatelink/_header.md b/examples/privatelink/_header.md new file mode 100644 index 0000000..94ffba7 --- /dev/null +++ b/examples/privatelink/_header.md @@ -0,0 +1,3 @@ +# Privatelink + +This deploys the module with local authentication disabled, public internet ingest, query disabled with private link. diff --git a/examples/privatelink/main.tf b/examples/privatelink/main.tf new file mode 100644 index 0000000..532a543 --- /dev/null +++ b/examples/privatelink/main.tf @@ -0,0 +1,84 @@ +terraform { + required_version = "~> 1.3" + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~> 3.74" + } + random = { + source = "hashicorp/random" + version = "~> 3.5" + } + } +} + +provider "azurerm" { + features {} +} + + +## Section to provide a random Azure region for the resource group +# This allows us to randomize the region for the resource group. +module "regions" { + source = "Azure/regions/azurerm" + version = "~> 0.3" +} + +# This allows us to randomize the region for the resource group. +resource "random_integer" "region_index" { + max = length(module.regions.regions) - 1 + min = 0 +} +## End of section to provide a random Azure region for the resource group + +# This ensures we have unique CAF compliant names for our resources. +module "naming" { + source = "Azure/naming/azurerm" + version = ">= 0.3.0" +} + +# This is required for resource modules +resource "azurerm_resource_group" "this" { + location = module.regions.regions[random_integer.region_index.result].name + name = module.naming.resource_group.name_unique +} + + +#Log Analytics Workspace for diagnostic settings. Required for workspace-based diagnostic settings. +resource "azurerm_log_analytics_workspace" "this" { + location = azurerm_resource_group.this.location + name = module.naming.log_analytics_workspace.name_unique + resource_group_name = azurerm_resource_group.this.name + sku = "PerGB2018" +} + + +# This is the module call +# Do not specify location here due to the randomization above. +# Leaving location as `null` will cause the module to use the resource group location +# with a data source. +module "test" { + source = "../.." + # source = "Azure/avm--/azurerm" + # ... + location = azurerm_resource_group.this.location + name = module.naming.application_insights.name_unique + resource_group_name = azurerm_resource_group.this.name + workspace_id = azurerm_log_analytics_workspace.this.id + enable_telemetry = var.enable_telemetry # see variables.tf + local_authentication_disabled = true + internet_ingestion_enabled = false + internet_query_enabled = false +} + +resource "azurerm_monitor_private_link_scope" "this" { + name = "privatelink.scope" + resource_group_name = azurerm_resource_group.this.name +} + +resource "azurerm_monitor_private_link_scoped_service" "this" { + linked_resource_id = module.test.resource_id + name = "privatelinkscopedservice.appinsights" + resource_group_name = azurerm_resource_group.this.name + scope_name = azurerm_monitor_private_link_scope.this.name +} diff --git a/examples/privatelink/variables.tf b/examples/privatelink/variables.tf new file mode 100644 index 0000000..e52bbd6 --- /dev/null +++ b/examples/privatelink/variables.tf @@ -0,0 +1,9 @@ +variable "enable_telemetry" { + type = bool + default = true + description = <. +If it is set to false, then no telemetry will be collected. +DESCRIPTION +} diff --git a/main.tf b/main.tf index 4664517..41f8e4f 100644 --- a/main.tf +++ b/main.tf @@ -8,6 +8,9 @@ resource "azurerm_application_insights" "this" { daily_data_cap_in_gb = var.daily_data_cap_in_gb daily_data_cap_notifications_disabled = var.daily_data_cap_notifications_disabled disable_ip_masking = var.disable_ip_masking + internet_ingestion_enabled = var.internet_ingestion_enabled + internet_query_enabled = var.internet_query_enabled + local_authentication_disabled = var.local_authentication_disabled retention_in_days = var.retention_in_days sampling_percentage = var.sampling_percentage tags = var.tags diff --git a/variables.tf b/variables.tf index 6ceea88..6db98cf 100644 --- a/variables.tf +++ b/variables.tf @@ -65,6 +65,24 @@ If it is set to false, then no telemetry will be collected. DESCRIPTION } +variable "internet_ingestion_enabled" { + type = bool + default = true + description = "(Optional) Enables internet ingestion. Defaults to true." +} + +variable "internet_query_enabled" { + type = bool + default = true + description = "(Optional) Enables internet query. Defaults to true." +} + +variable "local_authentication_disabled" { + type = bool + default = false + description = "(Optional) Disables local authentication. Defaults to false." +} + variable "lock" { type = object({ kind = string