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

Switch main.telemetry.tf content based on whether there is azurerm provider declared or not #118

Merged
merged 2 commits into from
Aug 7, 2024
Merged
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
7 changes: 4 additions & 3 deletions terraform/telemetry.grept.hcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# re-render the telemetry file to use azapi_client_config instead of azurerm_client_config
locals {
telemetry_azapi_content = try(replace(data.http.main_telemetry.response_body, "azurerm_client_config", "azapi_client_config"), "")
telemetry_azapi_content = try(replace(data.http.main_telemetry.response_body, "azurerm_client_config", "azapi_client_config"), "")
azurerm_provider_declared = try(strcontains(file("terraform.tf"), "source = \"hashicorp/azurerm\""), false)
}

# get the reference telemetry file
Expand All @@ -11,13 +12,13 @@ data "http" "main_telemetry" {

# Local file must use either azurerm_client_config or azapi_client_config
rule "must_be_true" "main_telemetry" {
condition = sha1(file("main.telemetry.tf")) == sha1(data.http.main_telemetry.response_body) || sha1(file("main.telemetry.tf")) == sha1(local.telemetry_azapi_content)
condition = try(sha1(file("main.telemetry.tf")) == sha1(data.http.main_telemetry.response_body), false) || try(sha1(file("main.telemetry.tf")) == sha1(local.telemetry_azapi_content), false)
error_message = "The main.telemetry.tf file must be present in the repository."
}

# Default to azurerm_client_config for the fix
fix "local_file" "main_telemetry" {
rule_ids = [rule.must_be_true.main_telemetry.id]
paths = ["main.telemetry.tf"]
content = data.http.main_telemetry.response_body
content = local.azurerm_provider_declared ? data.http.main_telemetry.response_body : local.telemetry_azapi_content
}
Loading