Rename Terraform template script



  • 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?



  • 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 https://www.terraform.io/language/functions/templatefile .


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2