Deprecated Terraform provider template causes `Incompatible provider version` error
Did you recently switch to a Mac with Apple Silicon (ARM processor architecture)? The chances are high that you will see an
Error: Incompatible provider version when running
terraform init the next time. That’s because Hashicorp does not provide the
template provider for the ARM platform. Luckily, there is an easy way to fix the issue.
I got the following error when running
terraform init on my new MacBook Pro for the first time.
I understood from the error message that the
template provider with version
v2.2.0 is not available for the ARM architecture.
So, I looked into my Terraform configuration. The
aws_instance gets rendered by the data source
template_file data source reads the template file
userdata.sh.tpl and replaces the placeholders with the variables (see
The template file
userdata.sh.tpl contains a shell script.
template provider which implements the data source
template_file is deprecated. Therefore, Hashicorp does not provide a version supporting the ARM platform.
Looking for a new challenge?
Therefore, I looked for a way to replace the data source
template_file and found the
templatefile function. The following snippet shows my Terraform config after substituting
That wasn’t too hard.
But, when I tried to run
terraform init again, I still got the same error message as before.
Error: Incompatible provider version
It turns out that I had to remove the data source from my Terraform state. To do so, I used the following command.
terraform state rm data.template_file.userdata
After that, I ran
terraform init and
terraform apply without issues on my MacBook Pro.