CloudFlare offers DNS services, security, and edge computing services that pair perfectly with the Terraform tool.
Installing Terraform
Terraform can be used either on Windows or on Linux.
Windows Installation
First, you will need todownload the Terraform executable for Windows.
Once downloaded, place the executable in a Windows path location.
This can be used to modify the systemPATHby changingUsertoMachine.
You will need Administrative rights to do this.
Linux Installation
Much like Windows, you willdownload the latest release of Terraform.
Create a new directory to hold the configuration.
We first need to create our configuration file.
We are opting to not hardcode our credentials into the configuration file.
Instead, a file will pass in those credentials that are excluded from version control.
Speaking of which, Git is highly recommended to keep track of the changes.
Now that we have both of our files configured, it is time to initialize our configuration.
This will install any providers that have been specified in theprovidersection of our Terraform configuration file.
Add the following line into thecloudflare.auto.tfvarsfile.
Next, we need to define the records that we are going to add to CloudFlare.
To do this, we are going to use thecloudflare_recordresource to create the records.
The key in will becloudflare_record, and for the name we will usea_mydomain_comandcname_www.
These names are arbitrary though, and they can be whatever you would like.
One caveat about the names.
Applying the Terraform Changes
Once you are confident in your configuration, simply use theapplycommand.
This will prompt for a confirmation, where you should probably typeyes.
The output will show the configuration to apply and the state.
Conclusion
Combining CloudFlare and Terraform is a potent combination.