Terraform is great — until it isn’t. One of the biggest pain points in managing infrastructure as code is dealing with existing resources that Terraform doesn’t recognize. The dreaded import process has always been a manual, error-prone, and annoying step in my workflow.

Azure has some resources that show up on the usual suspects list: Azure Monitor Diagnostic Setting, Role Assignments, Virtual Network Peerings to name a few. Today it was the Swift Connection for my Azure Function which allows my Azure Function to connect to a private network.

The Toil of Writing Import Blocks

Every Terraform practitioner knows the pain:

  • You define your resources.
  • You run terraform apply.
  • Something goes wrong — transient error, misconfiguration, gremlins, “ThErE bE dRAGONs!!!!1!”
  • Terraform tries to create a resource that already exists in Azure.
  • Terraform throws an error.
  • You manually figure out the resource ID and write an import block by hand.
  • You apply, then delete the import block, then apply again.

It’s an unnecessary, repetitive task that adds zero value.

The ChatGPT Breakthrough: No More Manual Import Blocks

I realized I was wasting time. Why should I manually write these import blocks when I could just ask ChatGPT to do it?

So I tried it.

My Prompt:

write a terraform import block for this

then I smash the Terraform panic output:

import { to = azurerm_app_service_virtual_network_swift_connection.main id = “/subscriptions/a8dc551f-cbe8–47e9–87c1-d9570ac6d69d/resourceGroups/rg-tsg-svc-assessment-ppe/providers/Microsoft.Web/sites/func-tsg-svc-assessment-ppe/config/virtualNetwork” }

and it produces this response:

import {
  to = azurerm_app_service_virtual_network_swift_connection.main
  id = "/subscriptions/a8dc551f-cbe8-47e9-87c1-d9570ac6d69d/resourceGroups/rg-tsg-svc-assessment-ppe/providers/Microsoft.Web/sites/func-tsg-svc-assessment-ppe/config/virtualNetwork"
}

#WINNING!!!!

Terraform Apply: The Toil-Free Workflow

With ChatGPT handling the import block generation, my new Terraform workflow looks like this:

  1. Copy-paste the Terraform error into ChatGPT.
  2. ChatGPT generates the import block instantly.
  3. Paste the import block into my Terraform config.
  4. Run Terraform Apply.
  5. Delete the import block.
  6. Run Terraform Apply again.

Why This Matters

This is sooo useful for anyone managing with Terraform:

  • ✅ No more manual import blocks.
  • ✅ No more copy-pasting resource IDs by hand.
  • ✅ No more wasted time.
  • ✅ No more toil.

Terraform just works, without the frustration.

Final Thoughts

Infrastructure-as-code is supposed to automate cloud provisioning — not create extra manual steps. Thanks to ChatGPT, I’ve eliminated one of the most tedious parts of my Terraform workflow. This is winning at life, my friends.

Now, I don’t write import blocks. I let AI do it for me.