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.

‘Figment’ in a Galaxy Z Fold 6 next to an 8BitDo Pro 2 controller.

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.

Article image

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.

Initializing our configuration will install any providers specified in provider section of our Terraform 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.

Run the terraform plan command

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.

Use apply command to prompt a confirmation, then type yes. The output shows the configuration to apply and the state.

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.