Manipulating local files with Terraform
Terraform is very popular due to its Infrastructure as Code functionality for cloud providers. But it also has many providers that allow us to manipulate the local system.
In the Querying external data with Terraform recipe, we discussed local script executions that are performed by Terraform to get data for external data sources.
In this recipe, we will study another type of local operation that involves creating and archiving local files with Terraform.
Getting ready
For this recipe, we don't need any prerequisites or base code – we will write the code from scratch.
The source code for this recipe is available at https://github.com/PacktPublishing/Terraform-Cookbook-Second-Edition/tree/main/CHAP04/files and here https://github.com/PacktPublishing/Terraform-Cookbook-Second-Edition/tree/main/CHAP04/archive.
How to do it…
Perform the following steps:
- In a new folder called
files
, create amain.tf
file. Write the following code...