terraform-provider-dynatrace
terraform-provider-dynatrace copied to clipboard
[Bug] Management zones missing the ID
After a export of the management zones the optional ID is missing (https://registry.terraform.io/providers/dynatrace-oss/dynatrace/latest/docs/resources/management_zone)
resource "dynatrace_management_zone" "XX_XXX_XXX" { name = "WK_Remote_Services" rules { type = "SERVICE" enabled = true conditions { process_metadata { attribute = "PROCESS_GROUP_PREDEFINED_METADATA" dynamic_key = "KUBERNETES_NAMESPACE" ....
This ID would be needed to assign them in the alerting profile.
The id
an attribute that terraform insists on - it's in fact not allowed to be specified explicitly by a provider. Essentially it's the identifier terraform uses within the state to identify a management zone uniquely.
Reading through a couple of currently open issues (like #57) I believe what you're battling with at the moment is the fact, that you would require the ID of certain resources (like the management zone) in order to define others. The culprit behind that is, that the Dynatrace REST API insists on creating new IDs for newly created resources - instead of allowing you to specify the identifier yourself.
That topic haunts me for a while already - and I'm not quite there yet to provide a proper and convenient solution. But it's on my todo list.
Not sure if I'm misunderstanding this issue, but if the management zone and alerting profile are managed by Terraform, can't you just reference it?
resource "dynatrace_alerting_profile" "alerting_profile" {
display_name = "${local.zone_name} Alerting"
mz_id = dynatrace_management_zone.zone.id
Just to clarify... I use this today for dozens of management zones without issue. The zones/profiles were all created by Terraform or imported into state if they were pre-existing...
Thanks @JosephHobbs for chiming in here. If I'm not mistaken, @ppaltmann is looking for a way to use the exported .tf files without modifications - and that's currently not possible. Using them as a basis for creating something consistent, like you are doing it, definitely works.
@JosephHobbs did you import your ressources after you used the "new" export / legacy download functionality?
unfortunately no. In my case, I did all my legacy imports before the export download was working. Long story short, I 'hacked' mine into the Terraform state...
@JosephHobbs we kind of started the same to get Terraform with the import statement in the same state as our env ;)
Hello everyone,
If I'm not mistaken we can close this ticket.
The most recent version of the -export
feature allows you to specify also the flag -ref
, which automatically downloads dependencies.
In other words, if you export an alerting profile using the -ref
option also the management zones it refers to will be downloaded.
Right now you still required to manually import these resources (terraform import
) into your local state. Specifying the flag -id
when using the export functionality helps here. It generates the ID as a comment at the beginning of all downloaded .tf files.