Skip to content

fix: Instance image diff during Instance import#2238

Merged
ezilber-akamai merged 7 commits intolinode:devfrom
ezilber-akamai:TPT-4016-instance-import-image-diff
Feb 5, 2026
Merged

fix: Instance image diff during Instance import#2238
ezilber-akamai merged 7 commits intolinode:devfrom
ezilber-akamai:TPT-4016-instance-import-image-diff

Conversation

@ezilber-akamai
Copy link
Contributor

@ezilber-akamai ezilber-akamai commented Jan 28, 2026

📝 Description

Fixed an import/migration diff where linode_instance_disk.image was missing from state, causing unnecessary updates.

✔️ How to Test

The following test steps assume you have pulled down this PR locally.

Integration Testing:

make test-int TEST_SUITE="instancedisk"

Manual Testing:

  1. In a sandbox environment (i.e. dx-devenv), run make init followed by make apply for the following TF Configuration:
provider "linode" {}

resource "linode_instance" "test" {
  label  = "tf-disk-migration-test"
  region = "us-east"
  type   = "g6-standard-1"

  image = "linode/ubuntu22.04"
}
  1. Ensure the instance is created successfully.
  2. Run the following CLI commands and note the Disk and Config IDs:
    • linode-cli linodes disks-list <LINODE_ID>
    • linode-cli linodes configs-list <LINODE_ID>
  3. Update the TF Configuration to the following:
provider "linode" {}

resource "linode_instance" "test" {
  label  = "tf-disk-migration-test"
  region = "us-east"
  type   = "g6-standard-1"

  image = "linode/ubuntu22.04"
}

resource "linode_instance_disk" "boot" {
  linode_id = linode_instance.test.id

  label = "linode-root"
  size  = 5120

  image = linode_instance.test.image
}

resource "linode_instance_config" "cfg" {
  linode_id = linode_instance.test.id
  label     = "My Ubuntu 22.04 LTS Disk Profile"

  device {
    device_name = "sda"
    disk_id     = linode_instance_disk.boot.id
  }
}
  1. Run the following commands and ensure they run successfully:
    • terraform import linode_instance_disk.boot <LINODE_ID>,<DISK_ID>
    • terraform import linode_instance_config.cfg <LINODE_ID>,<CONFIG_ID>
  2. Run make plan and ensure that no image diff is detected.
  3. Clean up all dangling resources created for this test.

@ezilber-akamai ezilber-akamai force-pushed the TPT-4016-instance-import-image-diff branch from 9df9564 to 8291881 Compare January 28, 2026 20:41
@ezilber-akamai ezilber-akamai added the bugfix for any bug fixes in the changelog. label Jan 28, 2026
@ezilber-akamai ezilber-akamai marked this pull request as ready for review January 28, 2026 21:04
@ezilber-akamai ezilber-akamai requested review from a team as code owners January 28, 2026 21:04
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a state management issue where the image attribute was missing from the Terraform state during instance disk imports, causing unnecessary diffs and potential resource replacements.

Changes:

  • Added UseStateForUnknown() plan modifier to preserve the image attribute in state
  • Implemented logic to populate image from the parent instance during Read operations when the state value is null

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
linode/instancedisk/framework_resource_schema.go Added plan modifier to preserve image state value
linode/instancedisk/framework_resource.go Added logic to backfill image from parent instance during import

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@zliang-akamai zliang-akamai requested review from a team, dawiddzhafarov and psnoch-akamai and removed request for a team January 28, 2026 21:49
@zliang-akamai
Copy link
Member

zliang-akamai commented Jan 28, 2026

This may introduce another issue when you are importing the disk without specifying image in the TF config:

provider "linode" {}

resource "linode_instance" "test" {
  label  = "tf-disk-migration-test"
  region = "us-east"
  type   = "g6-standard-1"

  image = "linode/ubuntu22.04"
}

resource "linode_instance_disk" "boot" {
  linode_id = linode_instance.test.id

  label = "Ubuntu 22.04 LTS Disk"
  size  = 50688
  // image removed here
}

resource "linode_instance_config" "cfg" {
  linode_id = linode_instance.test.id
  label     = "My Ubuntu 22.04 LTS Disk Profile"

  device {
    device_name = "sda"
    disk_id     = linode_instance_disk.boot.id
  }
}
OpenTofu used the selected providers to generate the following execution plan. Resource
actions are indicated with the following symbols:
  ~ update in-place (current -> planned)
-/+ destroy and then create replacement

OpenTofu will perform the following actions:

  # linode_instance_config.cfg will be updated in-place
  ~ resource "linode_instance_config" "cfg" {
        id           = "94245142"
      ~ kernel       = "linode/grub2" -> "linode/latest-64bit"
        # (7 unchanged attributes hidden)

      - device {
          - device_name = "sda" -> null
          - disk_id     = 172334734 -> null
          - volume_id   = 0 -> null
        }
      - device {
          - device_name = "sdb" -> null
          - disk_id     = 172334736 -> null
          - volume_id   = 0 -> null
        }
      + device {
          + device_name = "sda"
          + disk_id     = (known after apply)
        }

        # (2 unchanged blocks hidden)
    }

  # linode_instance_disk.boot must be replaced
-/+ resource "linode_instance_disk" "boot" {
      ~ created         = "2026-01-28T21:55:11Z" -> (known after apply)
      ~ disk_encryption = "enabled" -> (known after apply)
      ~ filesystem      = "ext4" -> (known after apply)
      ~ id              = "172334734" -> (known after apply)
      - image           = "linode/ubuntu22.04" -> null # forces replacement
      ~ status          = "ready" -> (known after apply)
      ~ updated         = "2026-01-28T21:56:19Z" -> (known after apply)
        # (3 unchanged attributes hidden)
    }

Plan: 1 to add, 1 to change, 1 to destroy.

──────────────────────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so OpenTofu can't guarantee to take
exactly these actions if you run "tofu apply" now.

@zliang-akamai zliang-akamai self-requested a review January 28, 2026 22:04
Copy link
Member

@zliang-akamai zliang-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ezilber-akamai ezilber-akamai merged commit 6be0ffc into linode:dev Feb 5, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix for any bug fixes in the changelog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants