SYMPLIFY LEARNING

Provision a Palo Alto Networks firewall in Terraform

I often need a Palo Alto firewall to test new features or just to try out a lab exercise. But a hardware appliance is not always available. Running a virtual firewall in a home lab environment using GNS3 or Eve-ng is useful. But typically, I need to be connected to the home network to use it.

Due to both restrictions mentioned above, my preference is often to spin up a Palo Alto VM-series firewall in AWS when I need a test instance for a short period of time. Once I finish using it, I shut it down.

But provisioning a Palo Alto VM firewall manually via the AWS console is also not ideal. First of all, it takes time to create all the different components manually through the console. Secondly, it is prone to error.

To get around these issues, my preference has always been to use Terraform to provision my Palo Alto firewalls. With my ready-made Terraform script, all I need to do is run ‘terraform apply’ when I want to provision a firewall for a test, and run ‘terraform destroy’ when I’m done with my testing.

In this post, I share the terraform script that I use for provisioning my Palo Alto VM series firewall

Provision a VPC

My first step is to provision the VPC where the firewall will reside. Within the VPC, I create a subnet, route table and internet gateway. The internet gateway provides internet access outside the VPC, allowing me access the firewall via HTTPs or SSH from the list of IPs I specify in my security group. The code for the VPC is shown below:

Provision my EC2 instance

With my VPC now provisioned, I provision my EC2 instance. Besides provisioning the EC2 instance, I also use the code to create my SSH key pair, and security group.

It is not best practice to provision your keypair in a way that stores it in your terraform state file. It has been used for demonstrative purposes in this case.

The code below is used to provision the EC2 instance, SSH key pair and security group

Now, with these blocks of code, I’m able to provision my VPC and test firewall within a few minutes when ever I need a test Palo Alto firewall instance. Once I’m done, I can also terminate the instance within a matter of seconds.