Provider is giving error when using module.
terraform init
Initializing the backend...
Initializing modules...
There are some problems with the configuration, described below.
The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.
╷
│ Error: Module is incompatible with count, for_each, and depends_on
│
│ on main.tf line 19, in module "sre-central-slo":
│ 19: for_each = local.slos_flattened
│
│ The module at module.sre-central-slo is a legacy module which contains its own local provider configurations, and so calls to it may not use the count, for_each, or depends_on arguments.
│
│ If you also control the module "./..", consider updating this module to instead expect provider configurations to be passed by its caller.
╵
Please find the folder structure :-
main.tf
–provider.tf
–version.tf
module-folder
– module.tf
– provider.tf
main.tf →
resource "dynatrace_slo" "sre-central-slo" {
name = var.slo_name
evaluation = var.evaluation
filter = var.filter_name
metric_expression = var.metric
target = var.slo_target
warning = var.slo_warning
timeframe = var.timeframe
provider = dynatrace.dynatrace_api
}
provider.tf–>
terraform {
required_version = "~> 1.2"
required_providers {
dynatrace = {
source = "dynatrace-oss/dynatrace"
version = ">= 1.20.0"
}
}
}
provider "dynatrace" {
dt_env_url = var.dynatrace_url
dt_api_token = var.dynatrace_api_token
alias = "dynatrace_api"
}
module.tf →
locals {
json_files = fileset("${path.module}/solutions", "*/*.json")
solutions = {
for filename in local.json_files :
"${jsondecode(file("${path.module}/solutions/${filename}"))["solution_name"]}-${jsondecode(file("${path.module}/solutions/${filename}"))["environment"]}" => jsondecode(file("${path.module}/solutions/${filename}"))
}
slo = [for solution in local.solutions : {
for slo in solution.slo : "${solution.sre_team}-${solution.product_id}-${solution.solution_name}-${solution.environment}" => {
product_management_zone = try(solution.product_management_zone, null)
slo_target = try(solution.slo[0].slo_target, "98")
slo_warning = try(solution.slo[0].slo_warning, "99")
} if try(solution.slo, null) != null
}]
slos_flattened = merge([for solution in local.slo : solution]...)
}
module "sre-central-slo" {
source = "../"
for_each = local.slos_flattened
slo_name = "${each.key}-slo"
evaluation = "AGGREGATE"
filter_name = each.value.product_management_zone != null ? "type(SYNTHETIC_TEST),entityName.startsWith(\"${each.key}\"),mzName(\"${each.value.product_management_zone}\", \"${var.default_mz_name}\")" : "type(SYNTHETIC_TEST),entityName.startsWith(\"${each.key}\"),mzName(\"${var.default_mz_name}\")"
metric = "(builtin:synthetic.browser.availability.location.total:splitBy())"
slo_target = each.value.slo_target
slo_warning = each.value.slo_warning
timeframe = "-1w"
}
MOdule folder provider.tf →
terraform {
required_version = "~> 1.2"
required_providers {
dynatrace = {
source = "dynatrace-oss/dynatrace"
version = ">= 1.20.0"
}
}
}
provider "dynatrace" {
dt_env_url = var.dynatrace_url
dt_api_token = var.dynatrace_api_token
alias = "dynatrace_api"
}