<p>Yes you can move it in state.</p>
<p>Something like:</p>
<pre><code>terraform state mv template_file.server1 template_file.new_name
</code></pre>
<p>Once you move it in the terraform state, then you can rename it in the file.</p>
<pre><code>data &quot;template_file&quot; &quot;new_name&quot; {
    template = file(&quot;${path.module}/script1.ps1&quot;)
    vars = {}
}
</code></pre>
<p>If you run <code>terraform plan</code> you shouldnt see any changes.</p>
<p>You will also need to update any references to the old name to point to the new name.</p>
<p>If you are using a version of terraform greater than 0.12 you might want to remove the data source template_file completly and replace it with a call to the <a href="https://www.terraform.io/language/functions/templatefile" rel="nofollow noreferrer">templatefile function</a>.</p>

CC BY-SA 4.0
2022-08-11T22:29:08.583Z
2022-08-11T22:34:49.017Z
2022-08-11T22:34:49.017Z
Levi
<p>In the example below if I were to rename &quot;script1.ps1&quot; to a new name this would normally result in the destruction and recreation of server1.</p>
<pre><code>data &quot;template_file&quot; &quot;server1&quot; {
    template = file(&quot;${path.module}/script1.ps1&quot;)
    vars = {}
}
</code></pre>
<p>Is it possible to update the script name without recreating the server?</p>

<terraform>
Rename Terraform template script
Wesley Rolnick
# Rename Terraform template script

(Asked by: username_0 on 2022-08-11)

In the example below if I were to rename "script1.ps1" to a new name this would normally result in the destruction and recreation of server1.
data "template_file" "server1" {
    template = file("${path.module}/script1.ps1")
    vars = {}
}

Is it possible to update the script name without recreating the server?

**Tags:** terraform


---

## 1 answers

### Answer by username_1 on 2022-08-11. Score: 3 | Accepted answer

Yes you can move it in state.
Something like:
terraform state mv template_file.server1 template_file.new_name

Once you move it in the terraform state, then you can rename it in the file.
data "template_file" "new_name" {
    template = file("${path.module}/script1.ps1")
    vars = {}
}

If you run terraform plan you shouldnt see any changes.
You will also need to update any references to the old name to point to the new name.
If you are using a version of terraform greater than 0.12 you might want to remove the data source template_file completly and replace it with a call to the templatefile function.


---

