| name | rename-attribute |
| description | Renames a Terraform attribute safely without changing its schema or producing an
unnecessary diff, while enabling users to use both the previous and subsequent
attribute names for a deprecation period.
|
Rename Terraform Attribute
Overview
A user may ask you to rename a Terraform attribute. A Terraform attribute has
a name and a schema representing the types of data the attribute can contain.
Renaming a Terraform attribute keeps the original attribute and creates a new
attribute with the same schema, introducing a deprecation period so the user can
migrate from the old attribute to the new attribute.
Workflow
Determine Attribute Schema
Use the "Determine Attribute Schema" section.
Create New Attribute
Use the "Create New Attribute" section.
Modify New and Old Attribute Schemas
Use the "Modify New and Old Attribute Schemas" section.
Modify CRUD Methods
Use the "Modify CRUD Methods" section.
Create Plan Modifier
Use the "Create Plan Modifier" section.
Write Tests
Use the "Write Tests" section.
Determine Attribute Schema
Find the Schema method on the resource and look for the attribute the user
asked to be renamed. Take note of the schema for the attribute and whether the
attribute is Required, Optional, or Computed. This is the schema that will
need to be used for the new attribute.
Create New Attribute
Create a new attribute on the resource within the Schema method using the new
name that the user told you. The schema for this attribute must be identical to
the schema for the old attribute. The only difference should be the attribute
name.
Modify New and Old Attribute Schemas
Struct Fields
There's a struct type that represents the resource that Terraform uses to
serialize and deserialize Go types to Terraform types and vice versa. The type
is usually something with "model" in the name. You should be able to find the
field by looking for a struct field tag with the value that matches the
name of the attribute from .