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

prepare for new telemetry solution #124

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ The following requirements are needed by this module:

- <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) (~> 3.71)

- <a name="requirement_modtm"></a> [modtm](#requirement\_modtm) (~> 0.3)

- <a name="requirement_random"></a> [random](#requirement\_random) (~> 3.5)

## Providers
Expand All @@ -36,6 +38,8 @@ The following providers are used by this module:

- <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) (~> 3.71)

- <a name="provider_modtm"></a> [modtm](#provider\_modtm) (~> 0.3)

- <a name="provider_random"></a> [random](#provider\_random) (~> 3.5)

## Resources
Expand All @@ -47,9 +51,11 @@ The following resources are used by this module:
- [azurerm_private_endpoint.this_unmanaged_dns_zone_groups](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_endpoint) (resource)
- [azurerm_private_endpoint_application_security_group_association.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_endpoint_application_security_group_association) (resource)
- [azurerm_resource_group.TODO](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) (resource)
- [azurerm_resource_group_template_deployment.telemetry](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group_template_deployment) (resource)
- [azurerm_role_assignment.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) (resource)
- [random_id.telem](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id) (resource)
- [modtm_telemetry.telemetry](https://registry.terraform.io/providers/azure/modtm/latest/docs/resources/telemetry) (resource)
- [random_uuid.telemetry](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/uuid) (resource)
- [azurerm_client_config.telemetry](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/client_config) (data source)
- [modtm_module_source.telemetry](https://registry.terraform.io/providers/azure/modtm/latest/docs/data-sources/module_source) (data source)

<!-- markdownlint-disable MD013 -->
## Required Inputs
Expand Down
6 changes: 6 additions & 0 deletions examples/default/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ terraform {
source = "hashicorp/azurerm"
version = "~> 3.74"
}
modtm = {
source = "azure/modtm"
version = "~> 0.3"
}
random = {
source = "hashicorp/random"
version = "~> 3.5"
Expand Down Expand Up @@ -74,6 +78,8 @@ The following requirements are needed by this module:

- <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) (~> 3.74)

- <a name="requirement_modtm"></a> [modtm](#requirement\_modtm) (~> 0.3)

- <a name="requirement_random"></a> [random](#requirement\_random) (~> 3.5)

## Providers
Expand Down
4 changes: 4 additions & 0 deletions examples/default/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ terraform {
source = "hashicorp/azurerm"
version = "~> 3.74"
}
modtm = {
source = "azure/modtm"
version = "~> 0.3"
}
random = {
source = "hashicorp/random"
version = "~> 3.5"
Expand Down
42 changes: 1 addition & 41 deletions locals.telemetry.tf
Original file line number Diff line number Diff line change
@@ -1,41 +1 @@
locals {
# TODO: change this to the name of the module. See https://azure.github.io/Azure-Verified-Modules/specs/shared/#id-sfr3---category-telemetry---deploymentusage-telemetry
module_name = "CHANGEME"
# TODO: Change this. Should be either `res` or `ptn`
module_type = "res"
# This constructs the ARM deployment name that is used for the telemetry.
# We shouldn't ever hit the 64 character limit but use substr just in case.
telem_arm_deployment_name = substr(
format(
"%s.%s.%s.v%s.%s",
local.telem_puid,
local.module_type,
substr(local.module_name, 0, 30),
replace(local.module_version, ".", "-"),
local.telem_random_hex
),
0,
64
)
# This is an empty ARM deployment template.
telem_arm_template_content = jsonencode(
{
"$schema" = "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion" = "1.0.0.0",
"parameters" = {},
"variables" = {},
"resources" = [],
"outputs" = {
"telemetry" = {
"type" = "String",
"value" = "For more information, see https://aka.ms/avm/telemetry"
}
}
}
)
# This is the unique id AVM Terraform modules that is supplied by the AVM team.
# See https://azure.github.io/Azure-Verified-Modules/specs/shared/#id-sfr3---category-telemetry---deploymentusage-telemetry
telem_puid = "46d3xgtf"
# This ensures we don't get errors if telemetry is disabled.
telem_random_hex = can(random_id.telem[0].hex) ? random_id.telem[0].hex : ""
}
# This file is intentionally empty followiung migration to modtm provider.
27 changes: 17 additions & 10 deletions main.telemetry.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
resource "random_id" "telem" {
data "azurerm_client_config" "telemetry" {
count = var.enable_telemetry ? 1 : 0
}

data "modtm_module_source" "telemetry" {
count = var.enable_telemetry ? 1 : 0
module_path = path.module
}

byte_length = 4
resource "random_uuid" "telemetry" {
count = var.enable_telemetry ? 1 : 0
}

# This is the module telemetry deployment that is only created if telemetry is enabled.
# It is deployed to the resource's resource group.
resource "azurerm_resource_group_template_deployment" "telemetry" {
resource "modtm_telemetry" "telemetry" {
count = var.enable_telemetry ? 1 : 0

deployment_mode = "Incremental"
name = local.telem_arm_deployment_name
resource_group_name = var.resource_group_name
tags = null
template_content = local.telem_arm_template_content
tags = {
subscription_id = one(data.azurerm_client_config.telemetry).subscription_id
tenant_id = one(data.azurerm_client_config.telemetry).tenant_id
module_source = one(data.modtm_module_source.telemetry).module_source
module_version = one(data.modtm_module_source.telemetry).module_version
random_id = one(random_uuid.telemetry).result
}
}
4 changes: 4 additions & 0 deletions terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ terraform {
source = "hashicorp/azurerm"
version = "~> 3.71"
}
modtm = {
source = "azure/modtm"
version = "~> 0.3"
}
random = {
source = "hashicorp/random"
version = "~> 3.5"
Expand Down
1 change: 1 addition & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ This variable controls whether or not telemetry is enabled for the module.
For more information see <https://aka.ms/avm/telemetryinfo>.
If it is set to false, then no telemetry will be collected.
DESCRIPTION
nullable = false
}

variable "lock" {
Expand Down