Overview
This guide explains how to safely rename ZEDEDA Terraform Provider objects. It gives special attention to a potentially dangerous underlying behavior of the ZEDEDA Provider: deletion of some objects after updating their name or the name of an object they are related to. If you understand how the ZEDEDA Provider behaves in this regard, you can ensure the integrity of your Terraform resources.
Note that not all objects are affected by this behavior. The only ones affected are those that are configured with ForceNew with respect to their name. Examples are shown in a following section.
For any object that is configured with ForceNew, when you rename it, the ZEDEDA Provider makes a copy of the object with the new name and deletes the original. Additionally, though, the Provider will also delete and recreate all of the original objects dependencies.
There is, however, an exception to this behavior. Any object that can't be deleted (including dependencies) will not be deleted or copied. Some objects, for example, are immutable.
Caution: The ZEDEDA Terraform Provider will only report when it deletes objects set for re-creation. It will not report when it deletes associated objects.
Warning: When the ZEDEDA Provider deletes an object, it’s permanent.
Affected objects
Only the following objects are affected by this behavior.
application
application_instance
datasource
image
network
network_instance
volume_instance
node
Affected versions
Versions 2.2.5 and later.
Prerequisites
You should be set up with ZEDEDA’s Terraform Provider.
Rename an object
To rename an object, you need to modify its configuration. The following example shows which aspects of the object’s configuration you need to change: its resource definition and its data source definition. Notice the name fields and their placeholder values, old_tf_provider. These are the values you need to change. Note also that these values must match.
resource "zedcloud_application_instance" "test_tf_provider" {
name = "old_tf_provider"
...
}
data "zedcloud_application_instance" "test_tf_provider" {
name = "old_tf_provider"
...
}
It's important to apply the configuration changes incrementally to ensure that Terraform correctly updates the state of your resources. To rename an object, we need to change its name in its resource definition first. Then, we can change its name in its data source definition. To do so, follow these steps.
- Update the name value in the resource definition.
resource "zedcloud_application_instance" "test_tf_provider" {
name = "new_tf_provider"
...
}
data "zedcloud_application_instance" "test_tf_provider" {
name = "old_tf_provider"
...
}
- In your terminal, apply your new configuration. You may see an error similar to, "The requested resource was not found on this server". Ignore it and proceed.
terraform apply
- Update the name value in the data source definition.
resource "zedcloud_application_instance" "test_tf_provider" {
name = "new_tf_provider"
...
}
data "zedcloud_application_instance" "test_tf_provider" {
name = "new_tf_provider"
...
}
- In your terminal, apply your new configuration.
terraform apply