Terraform archived template provider and what now?

What has happened actually?

Terraform used to have a template provider in past. It was deprecated with Terraform 0.12 and archived on the 9th of October 2020.
Although it was more than 3 years ago, some of you might still be using it!

It provided the following data sources:
template_file
template_cloudinit_config
And they were used a lot in the past.

template_file was used for prototyping files, e.g. with variables passed from the Terraform code to these files.

template_cloudinit_config was used to generate the Cloud-init configuration consumable by other resources, e.g. aws_instance as user_data / user_data_base64 or other resources that can be configured with Cloud-init.

There's quite a chance you have used it in past or will use it in the future, e.g. following some tutorials available on the Internet.

So did I, as I was unaware of the issue - and I would probably still be, but my workmate faced an issue that the binary for template provider is not available for Mac M1 and newer ARM-based Macs.
And there's a chance that you have also followed some old tutorials with the old code and are facing the same issues on your shiny new computer!
Or you are good, but your teammate has the issue!

But there's a solution for that - with newer Terraform we can use cloudinit provider that comes with cloudinit_config data type that can utilize templatefile() function inside.
I have prepared an example on how to transform from the deprecated code to the modern one, as I haven't found a clear, simple example on how to do that.

The code

This is an example of how did the code look like with the deprecated template provider:

data "template_file" "example" {
  template = file("${path.module}/templates/example.yml")

  vars = {
    EXAMPLE_VAR = var.example_var
  }
}

data "template_cloudinit_config" "config" {
  gzip          = true
  base64_encode = true

  part {
    filename     = "example.yml"
    content_type = "text/cloud-config"
    content      = data.template_file.example.rendered
  }
}

Here's how the code would look like after refactoring to the cloudinit provider.

data "cloudinit_config" "config" {
  gzip          = true
  base64_encode = true

  part {
    filename     = "example.yml"
    content_type = "text/cloud-config"
    content = templatefile("${path.module}/templates/example.yml", {
      EXAMPLE_VAR = var.example_var
    })
  }
}

I have tested the refactored code so you don't have to make it out on your own!

And yes, I also needed the refactored code for the infrastructure I manage.