Terraform import not matching terraform plan

I import a resource successfully. Then when I use terraform plan, it says it will update in-place changes to that very resource I just updated.

To further confuse things, I check the state of that resource. And the properties it says its going to update are not listed in the state file.

Any thoughts why that is happening?

I find this to be a fairly normal experience.

When you write a resource block for an existing resource prior to import, it is easy to not quite match the existing state as Terraform sees it.

My normal workflow is:

  • Write resource block
  • Import
  • Plan
  • Consider changes in plan, edit resource block, re-plan, repeat as needed

Also I have found some cases where effectively no-op attribute changes show up on the first plan after an import - often null changing to empty list or things like that. I imagine that this is technically a (mild) bug in the provider, which should have import implementations that correctly set these in the first place.

So, there are multiple reasons this could happen.

To help further, you’d have to show us the actual resource definition and planned changes.

Resource I imported with:

  resource "citrixadc_service" "tf-port" {
  
      }

Changes after running terraform plan:

Terraform will perform the following actions:

  # citrixadc_service.tf-port will be updated in-place
  ~ resource "citrixadc_service" "tf-port" {
      + disabled_poll_delay    = "2s"
      + disabled_poll_interval = "5s"
      + disabled_timeout       = "2m"
        id                     = "tf-port"
        name                   = "tf-port"
        # (34 unchanged attributes hidden)
    }

Looking at the definition of this resource type:

Sure enough these 3 attributes are ones which have a default value set - and these default values match your plan.

So, you imported the existing resource, but once you plan, those defaults get applied and the provider wants to set them.