Orchrestation to create a 1st resource, then 2nd and change settings of 1st based on 2nd resource in same terraform code

I need help for below 2 points on Azure deployment using terraform, could you please help me.

  1. How can I get the output of DNS servers in terraform template deployment (azurerm_template_deployment) of Azure AD Domain Services. Please help me what should I mention in the outputs section of json template (Attached).template.txt (2.3 KB)
  2. I need to update the DNS server names (which should come from Azure AD DS) in the vnet. For that first I am creating a vnet (and subnet), then in vnet creation the Azure AD DS and after Azure AD DS completion, update the custom DNS server settings of the same vnet. How could I achieve that ? terraform.txt (1.9 KB)

I am attaching the section of terraform code which I am using. Please let me know if I miss something.

This is cyclic-dependency, you need to break the cycle. You can’t change a resource by defining it twice, remember that Terraform is descriptive in nature: you describe the desired end-state, not the steps to get there.

Maybe you can pick the IP addresses in advance, and so have them as a shared parent to the vnet and AD resources?

Normally, the Terraform developers try to solve cyclic dependencies by breaking down resources into smaller components, but the underlying API from the provider doesn’t always allow this.