Skip to content

Conversation

@sudomateo
Copy link
Collaborator

@sudomateo sudomateo commented Dec 24, 2025

Added a rename-attribute AI agent skill to, hopefully, allow an AI agent to do future renames of Terraform attributes.

Amp-Thread: https://ampcode.com/threads/T-019b4ea0-eacf-759c-8f7e-0746094eea36

Added a `rename-attribute` AI agent skill to, hopefully, allow an AI
agent to do future renames of Terraform attributes.

Amp-Thread: https://ampcode.com/threads/T-019b4ea0-eacf-759c-8f7e-0746094eea36
@sudomateo
Copy link
Collaborator Author

Currently testing this on a commit that does not already have the changes in #578. See the attached Amp thread for more information.

Here's the diff it produced so far.

diff --git a/internal/provider/resource_instance.go b/internal/provider/resource_instance.go
index d9c344db26..6ad726f282 100644
--- a/internal/provider/resource_instance.go
+++ b/internal/provider/resource_instance.go
@@ -54,7 +54,8 @@
        Description        types.String                      `tfsdk:"description"`
        DiskAttachments    types.Set                         `tfsdk:"disk_attachments"`
        ExternalIPs        []instanceResourceExternalIPModel `tfsdk:"external_ips"`
-       HostName           types.String                      `tfsdk:"host_name"`
+       Hostname           types.String                      `tfsdk:"hostname"`
+       HostNameDeprecated types.String                      `tfsdk:"host_name"`
        ID                 types.String                      `tfsdk:"id"`
        Memory             types.Int64                       `tfsdk:"memory"`
        Name               types.String                      `tfsdk:"name"`
@@ -137,12 +138,32 @@
                                        stringplanmodifier.RequiresReplace(),
                                },
                        },
+                       "hostname": schema.StringAttribute{
+                               Optional:    true,
+                               Computed:    true,
+                               Description: "Host name of the instance.",
+                               PlanModifiers: []planmodifier.String{
+                                       stringplanmodifier.RequiresReplace(),
+                               },
+                               Validators: []validator.String{
+                                       stringvalidator.ExactlyOneOf(
+                                               path.MatchRoot("host_name"),
+                                       ),
+                               },
+                       },
                        "host_name": schema.StringAttribute{
-                               Required:    true,
-                               Description: "Host name of the instance.",
+                               Optional:           true,
+                               Computed:           true,
+                               Description:        "Deprecated: Use hostname instead.",
+                               DeprecationMessage: "Use hostname instead.",
                                PlanModifiers: []planmodifier.String{
                                        stringplanmodifier.RequiresReplace(),
                                },
+                               Validators: []validator.String{
+                                       stringvalidator.ExactlyOneOf(
+                                               path.MatchRoot("hostname"),
+                                       ),
+                               },
                        },
                        "memory": schema.Int64Attribute{
                                Required:    true,
@@ -362,12 +383,19 @@
        ctx, cancel := context.WithTimeout(ctx, createTimeout)
        defer cancel()

+       var hostname string
+       if !plan.Hostname.IsNull() && !plan.Hostname.IsUnknown() {
+               hostname = plan.Hostname.ValueString()
+       } else {
+               hostname = plan.HostNameDeprecated.ValueString()
+       }
+
        params := oxide.InstanceCreateParams{
                Project: oxide.NameOrId(plan.ProjectID.ValueString()),
                Body: &oxide.InstanceCreate{
                        Description: plan.Description.ValueString(),
                        Name:        oxide.Name(plan.Name.ValueString()),
-                       Hostname:    oxide.Hostname(plan.HostName.ValueString()),
+                       Hostname:    oxide.Hostname(hostname),
                        Memory:      oxide.ByteCount(plan.Memory.ValueInt64()),
                        Ncpus:       oxide.InstanceCpuCount(plan.NCPUs.ValueInt64()),
                        Start:       plan.StartOnCreate.ValueBoolPointer(),
@@ -468,6 +496,8 @@
        plan.ID = types.StringValue(instance.Id)
        plan.TimeCreated = types.StringValue(instance.TimeCreated.String())
        plan.TimeModified = types.StringValue(instance.TimeModified.String())
+       plan.Hostname = types.StringValue(string(instance.Hostname))
+       plan.HostNameDeprecated = types.StringValue(string(instance.Hostname))

        // Populate NIC information
        for i := range plan.NetworkInterfaces {
@@ -548,7 +578,8 @@
                state.AutoRestartPolicy = types.StringValue(string(instance.AutoRestartPolicy))
        }
        state.Description = types.StringValue(instance.Description)
-       state.HostName = types.StringValue(string(instance.Hostname))
+       state.Hostname = types.StringValue(string(instance.Hostname))
+       state.HostNameDeprecated = types.StringValue(string(instance.Hostname))
        state.ID = types.StringValue(instance.Id)
        state.Memory = types.Int64Value(int64(instance.Memory))
        state.Name = types.StringValue(string(instance.Name))
@@ -809,6 +840,8 @@
        plan.ProjectID = types.StringValue(instance.ProjectId)
        plan.TimeCreated = types.StringValue(instance.TimeCreated.String())
        plan.TimeModified = types.StringValue(instance.TimeModified.String())
+       plan.Hostname = types.StringValue(string(instance.Hostname))
+       plan.HostNameDeprecated = types.StringValue(string(instance.Hostname))

        // We use the plan here instead of the state to capture the desired IP pool ID
        // value for the ephemeral external IP rather than the previous value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants