Creating Azure API Management through terraform failed because of timeout and the state file does not get updated with the resources created

Mohammed Sadiq 1 Reputation point
2023-01-06T06:33:03.087+00:00

I am trying to create Azure API Manegement service using Terraform. The issue is that APIM service takes a very long time to create and terraform apply gives context deadline exceeded error or pollingTrackerPut#checkForErrors: the response did not contain a body: StatusCode=0

Although the resource does get created after the error comes on CLI, the state file does not get updated.

There is a workaround to import the resource using terraform import command after it gets created but that is not the way it should be.

How do I resolve it?

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,227 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Cecilia Wirén 1 Reputation point MVP
    2023-01-09T08:59:05.537+00:00

    to extend the default timeout for terraform creation you can add the following to that resource:

    resource "<resource_name>" "<resource_name>" {  
      ...  
      timeouts {  
        create: "1h30m",  
        update: "2h",  
        delete: "20m"  
      }  
    }  
    

    But I have always gone for the create-import option since I don't want to block my build agent for that long. But if the timeout comes from the underlying API:s this will not help and you should file an issue: https://github.com/hashicorp/terraform-provider-azurerm/issues (or search for if anyone else have filed one)

    [edit]
    https://github.com/hashicorp/terraform-provider-azurerm/issues/17206
    (seems like a similar issue, if the timeout solution doesn't help, vote this up/follow it and provide more info if you have)


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.