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.
Terraform Error: Incompatible provider version
I got the following error when running terraform init
on my new MacBook Pro for the first time.
terraform init |
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 user_data
for aws_instance
gets rendered by the data source template_file
. The template_file
data source reads the template file userdata.sh.tpl
and replaces the placeholders with the variables (see vars
).
terraform { |
The template file userdata.sh.tpl
contains a shell script.
!/bin/bash |
But, the template
provider which implements the data source template_file
is deprecated. Therefore, Hashicorp does not provide a version supporting the ARM platform.
Terraform: Replace deprecated template_file with templatefile()
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 template_file
with templatefile
.
terraform { |
That wasn’t too hard.
Terraform Error: Incompatible provider version persists
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.
Further reading
- Article Terraform, can you keep a secret?
- Article Security Iceberg: AWS Security Hub the right way
- Article How to set up Jenkins on AWS?
- Tag terraform