-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.telemetry.tf
More file actions
60 lines (51 loc) · 1.91 KB
/
main.telemetry.tf
File metadata and controls
60 lines (51 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
data "azapi_client_config" "telemetry" {
count = var.enable_telemetry ? 1 : 0
}
data "modtm_module_source" "telemetry" {
count = var.enable_telemetry ? 1 : 0
module_path = path.module
}
locals {
# If your module does not support a location, then set this local to "unknown"
# If the location is sourced from a collection or other value, then you can update this local to set it to the location
main_location = var.location
}
resource "random_uuid" "telemetry" {
count = var.enable_telemetry ? 1 : 0
}
resource "modtm_telemetry" "telemetry" {
count = var.enable_telemetry ? 1 : 0
tags = merge({
subscription_id = one(data.azapi_client_config.telemetry).subscription_id
tenant_id = one(data.azapi_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
}, { location = local.main_location })
}
locals {
avm_azapi_headers = !var.enable_telemetry ? {} : (local.fork_avm ? {
fork_avm = "true"
random_id = one(random_uuid.telemetry).result
} : {
avm = "true"
random_id = one(random_uuid.telemetry).result
avm_module_source = one(data.modtm_module_source.telemetry).module_source
avm_module_version = one(data.modtm_module_source.telemetry).module_version
})
}
locals {
fork_avm = !anytrue([for r in local.valid_module_source_regex : can(regex(r, one(data.modtm_module_source.telemetry).module_source))])
}
locals {
valid_module_source_regex = [
"registry.terraform.io/[A|a]zure/.+",
"registry.opentofu.io/[A|a]zure/.+",
"git::https://github\\.com/[A|a]zure/.+",
"git::ssh:://git@github\\.com/[A|a]zure/.+",
]
}
locals {
# tflint-ignore: terraform_unused_declarations
avm_azapi_header = join(" ", [for k, v in local.avm_azapi_headers : "${k}=${v}"])
}