title: Getting "Failure sending request: StatusCode=429 -- Original Error: context deadline exceeded" on Terraform
body: <p>Terraform is throwing an error &quot;Failure sending request: StatusCode=429 -- Original Error: context deadline exceeded&quot; when creating over 2000 A and CNAME records on Azure.</p>
  <p>Tried Terraform v0.13.5 and v0.14, same error</p>
  <p>Using version 2.39 of the azurerm plugin</p>
  <p>An example of my terraform code:</p>
  <pre><code>provider &quot;azurerm&quot; {
  #    version=&quot;2.39&quot;
      features {}
  }
  
  resource &quot;azurerm_resource_group&quot; &quot;example&quot; {
    name     = &quot;large-rg&quot;
    location = &quot;West US&quot;
  }
  
  resource &quot;azurerm_dns_zone&quot; &quot;example&quot; {
    name                = &quot;dnsrecords.com&quot;
    resource_group_name = azurerm_resource_group.example.name
  }
  
  resource &quot;azurerm_dns_a_record&quot; &quot;arecord&quot; {
          name                = &quot; arecord &quot;
          zone_name           = &quot; dnsrecords.com&quot;
          resource_group_name = &quot;large-rg&quot;
          ttl                 = 300
          records             = [&quot;1.1.1.1&quot;]
  }
  
  resource &quot;azurerm_dns_cname_record&quot; &quot;cname&quot; {
          name                = &quot;cname&quot;
          zone_name           = &quot; dnsrecords.com&quot;
          resource_group_name = &quot;large-rg&quot;
          ttl                 = 300
          record              = &quot;testing.trafficmanager.net.&quot;
  }
  </code></pre>
  <p>Getting this in the logs</p>
  <pre><code>2020/12/09 17:11:22 [TRACE] eval: *terraform.EvalWriteState 
  2020/12/09 17:11:22 [TRACE] EvalWriteState: recording 1 dependencies for azurerm_dns_zone.example 
  2020/12/09 17:11:22 [TRACE] EvalWriteState: writing current state object for azurerm_dns_zone.example 
  2020/12/09 17:11:22 [TRACE] [walkRefresh] Exiting eval tree: azurerm_dns_zone.example 
  2020/12/09 17:11:22 [TRACE] vertex &quot;azurerm_dns_zone.example&quot;: visit complete 
  2020/12/09 17:11:22 [TRACE] vertex &quot;azurerm_dns_zone.example&quot;: dynamic subgraph completed successfully 
  2020/12/09 17:11:22 [TRACE] vertex &quot;azurerm_dns_zone.example&quot;: visit complete 
  2020/12/09 17:11:22 [TRACE] vertex &quot;azurerm_dns_zone.example (expand)&quot;: dynamic subgraph completed successfully 
  2020/12/09 17:11:22 [TRACE] vertex &quot;azurerm_dns_zone.example (expand)&quot;: visit complete 
  2020/12/09 17:11:22 [TRACE] dag/walk: upstream of &quot;provider[\&quot;registry.terraform.io/hashicorp/azurerm\&quot;] (close)&quot; errored, so skipping 
  2020/12/09 17:11:22 [TRACE] dag/walk: upstream of &quot;root&quot; errored, so skipping 
  2020/12/09 17:11:22 [TRACE] statemgr.Filesystem: removing lock metadata file .terraform.tfstate.lock.info 
  2020/12/09 17:11:22 [TRACE] statemgr.Filesystem: unlocked by closing terraform.tfstate 
  2020-12-09T17:11:22.725-0800 [DEBUG] plugin: plugin process exited: path=.terraform/plugins/registry.terraform.io/hashicorp/azurerm/2.39.0/windows_amd64/terraform-provider-azurerm_v2.39.0_x5.exe pid=18812 
  2020-12-09T17:11:22.725-0800 [DEBUG] plugin: plugin exited
  </code></pre>
  <p>Edit:
  I split the records into batches of around 170 records and created its own terraform.tf and folder. I would run <code>terraform init</code> then import the exact same resource group and dns zone, in this case <code>large-rg</code> and <code>dnsrecords.com</code>. Next step was running <code>terraform plan</code> then <code>terraform apply</code>.</p>
  <p>What would happen is that it would first throw the <code>StatusCode=429</code> error, but rerunning it would solve the error. Adding a new record to it will also work.</p>
  <p>Doing it this way isn't ideal just because of the size of the records. The amount of records will only get larger as time passes.</p>
  <p>Looks like a limitation of Terraform.</p>
  <p>Edit2:
  Nancy Xiong provided a link where the recommended solution is to use multiple smaller state files. <a href="https://github.com/terraform-providers/terraform-provider-azurerm/pull/6866" rel="nofollow noreferrer">https://github.com/terraform-providers/terraform-provider-azurerm/pull/6866</a></p>