hashicorp/terraform · error

retrieving : model was nil

Error message

retrieving %s: model was nil

What it means

Thrown by Azure buildClient when storageAccountsClient.GetProperties returned no error but resp.Model is nil, i.e. the SDK handed back a 'success' response with no payload model. This is an SDK contract violation or an unexpected empty body from ARM, not a normal user-config error.

Solutions

  1. Report it as a bug against Terraform/go-azure-sdk with the storage account kind and the ARM response, since the contract was violated.
  2. Update to a Terraform version that links a go-azure-sdk release matching the current ARM storage API.
  3. Retry once; if ARM returned an intermittent empty body it may succeed on a second call.
  4. If you maintain the SDK client, ensure GetProperties always sets Model on a 2xx response or returns an error instead.

Example fix

null
Defensive patterns

Strategy: try-catch

Validate before calling

// Cannot truly validate from outside; at most, retry once on this SDK-contract failure.
// Real prevention is on the SDK side: ensure GetProperties sets Model on 2xx.

Type guard

null

Try / catch

client, err := azure.NewClient(ctx, cfg)
if err != nil && strings.Contains(err.Error(), "model was nil") {
    // retry once; if it persists, report an SDK/ARM bug
}

Prevention

When it happens

Trigger: The go-azure-sdk storageaccounts.GetProperties call returns resp=nil-model-but-no-error. This happens with a version skew between the linked go-azure-sdk and the ARM API shape, an ARM response that returned 200 with an empty body, or a custom/mock storage client that does not populate Model.

Common situations: Running a Terraform build against an incompatible go-azure-sdk revision; ARM returning an unusual response for a preview/special storage account; a test double that forgets to set Model. End users on released Terraform almost never hit this unless the ARM service misbehaves.

Related errors


AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11). Data as JSON: /api/errors/58ac62176d2169d2. Report an issue: GitHub.

Appendix: source

Thrown at internal/backend/remote-state/azure/api_client.go:109

		if config.SubscriptionID == "" {
			return nil, fmt.Errorf("subscription id not specified")
		}

		// Setup the SA client.
		client.storageAccountsClient, err = storageaccounts.NewStorageAccountsClientWithBaseURI(config.AuthConfig.Environment.ResourceManager)
		if err != nil {
			return nil, fmt.Errorf("building Storage Accounts client: %+v", err)
		}
		client.configureClient(client.storageAccountsClient.Client, resourceManagerAuth)

		// Populating the storage account detail
		storageAccountId := commonids.NewStorageAccountID(config.SubscriptionID, config.ResourceGroupName, client.storageAccountName)
		resp, err := client.storageAccountsClient.GetProperties(ctx, storageAccountId, storageaccounts.DefaultGetPropertiesOperationOptions())
		if err != nil {
			return nil, fmt.Errorf("retrieving %s: %+v", storageAccountId, err)
		}
		if resp.Model == nil {
			return nil, fmt.Errorf("retrieving %s: model was nil", storageAccountId)
		}
		client.accountDetail, err = populateAccountDetails(storageAccountId, *resp.Model)
		if err != nil {
			return nil, fmt.Errorf("populating details for %s: %+v", storageAccountId, err)
		}
	}

	return &client, nil
}

func (c *Client) getBlobClient(ctx context.Context) (bc *blobs.Client, err error) {
	if c.blobsClient != nil {
		return c.blobsClient, nil
	}

	defer func() {
		if err == nil {
			c.blobsClient = bc

View on GitHub (pinned to d32a084675)