Removing template_file from terraform state

I’ve run into this issue a few times so recording here for future reference. template_file has been deprecated in terraform but I occasionally perform a terraform init before realising that there is a template_file command in the code. I get the error:

Error: Incompatible provider version

Provider registry.terraform.io/hashicorp/template v2.2.0 does not have a package available for your current platform, darwin_arm64.

So I need to remove the template_file resource from state to continue. Listing the state:

terraform state list

Shows (among other things):

module.ec2.data.aws_iam_policy_document.my_role_document
module.ec2.data.template_file.user_data
module.ec2.aws_autoscaling_group.asg

So I remove the middle one with:

terraform state rm module.ec2.data.template_file.user_data

Then convert the template_file resource to a templatefile resource, and try the init again:

terraform init

Worked for me, YMMV

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>