Add a site to Cloudflare with Pulumi IaC
In this tutorial, you will go through step-by-step instructions to bring an existing site to Cloudflare using Pulumi Infrastructure as Code (IaC) so that you can become familiar with the resource management lifecycle. In particular, you will create a Zone and a DNS record to resolve your newly added site. This tutorial adopts the IaC principle to complete the steps listed in the Add a Site tutorial.
Before you begin
Ensure you have:
- A Cloudflare account and API Token with permission to edit the resources in this tutorial. If you need to, sign up for a Cloudflare account before continuing.
- A Pulumi Cloud account. You can sign up for an always-free, individual tier.
- npm and the Pulumi CLI installed on your machine.
- A registered domain name. You may use
example.com
to complete the tutorial partially.
Initialize Pulumi
a. Create a directory
Use a new and empty directory for this tutorial.
b. Login
At the prompt, press Enter to log into your Pulumi Cloud account via the browser. Alternatively, you may provide a Pulumi Cloud access token.
c. Create a program
To create a program, run:
Complete the prompts with defaults where available; otherwise, provide the requested information. You will need:
- Your Cloudflare account ID.
- A registered domain. For instance,
example.com
- A valid Cloudflare API token.
d. Create a stack
To create a stack, run:
d. (Optional) Verify the stack creation
Review the value of myTestOutput
to confirm the stack creation.
Add a Zone
Update your nameservers
Once you have added a domain to Cloudflare, that domain will receive two assigned authoritative nameservers.
a. Update the program
At the end of your index.ts
file, add the following:
b. Apply the changes
c. Obtain the nameservers
Review the value of nameservers
to retrieve the assigned nameservers:
d. Update your registrar
Update the nameservers at your registrar to activate Cloudflare services for your domain. Instructions are registrar-specific. You may be able to find guidance under this consolidated list of common registrars.
e. Check your domain status
Once successfully registered, your domain status will change to active
.
Add a DNS record
Verify your setup
You will run two nslookup
commands against the Cloudflare-assigned nameservers.
To test your site, run:
Confirm your response returns IP address(es) for your site.
Clean up
Next steps
You have incrementally defined Cloudflare resources needed to add a site to Cloudflare. After each new resource, you apply the changes to your stack via the pulumi up
command. You declare the resources in TypeScript and let Pulumi handle the rest.
Follow the Hello World tutorial next to deploy your first app with Pulumi.