What happens when the "image" attribute is changed in Terraform?
I have a linode instance managed by Terraform and I'd like to rebuild it using a newer image. I never did it with Terraform, so I suppose that I should just change the image attribute of the root device defined by a linode_instance_disk, and "apply" it.
Would it rebuild this linode instance (and thus keeping its ID and IP addresses) or would it destroy the current instance and create a new one, assigning new IP addresses?
2 Replies
✓ Best Answer
In my testing, I observed that when updating the image
attribute from linode/ubuntu20.04
to linode/ubuntu22.04
, it led to the removal of the old Linode instance and the provisioning of a new one, resulting in a change of IP addresses.
When trying to make the same image change using the inode_instance_disk resource, I encountered a few noteworthy complexities. During testing, I faced challenges in attempting to rebuild the existing disk with a different image. It appeared that Terraform was inclined to create an entirely new disk rather than resizing the existing one as expected. This, in turn, triggered a recurring "You do not have enough unallocated storage to create this Disk." error. To circumvent this issue, I resorted to manually resizing the disk to a smaller size using Cloud Manager, which then allowed Terraform to create a new disk with the desired new image. Once I performed this manual step, I was able to proceed with the terraform apply
command to successfully create the new disk with the latest image. I then manually modified the Linode's configuration profile to boot off the new image, which it did so flawlessly.
TL;DR, Modifying the image
attribute through the linode_instance
resource results in an entirely new Linode being created, thus, assigning new IP addresses. Modifying the image
through the linode_instance_disk
resource only affects that disk partition and not the entire compute instance, retaining IP addresses in my testing.
Hope that helps!
--Eric
Hi @eruzanski!
Thank you for your answer!
I was refactoring my Terraform project in order to have my linode defined by the new resources, such as the linode_instance_disk, and using its image attribute was on my plans.
Your message was very welcome and the experience you shared made me more confident to perform the change.
As you mentioned, I faced the same "You do not have enough unallocated storage to create this Disk." as well, but since the refactoring included the exclusion of other disks, a second terraform apply did the job.
Best regards!