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?

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.