Cloudflare Static Website
The Cloudflare Static Website template scaffolds a Pulumi project that serves your site’s files as static assets from a Cloudflare Worker, exposed on its own workers.dev subdomain. Pulumi uploads the contents of the site folder as a versioned set of Worker assets and rolls that version out to all of the Worker’s traffic with a Workers deployment. The template ships with placeholder web content so the project deploys end to end out of the box.
Using this template#
To use this template to deploy a website of your own, make sure you’ve installed Pulumi and configured your Cloudflare credentials, then create a new project using the template in the language of your choice:
mkdir my-site && cd my-sitepulumi new static-website-cloudflare-typescriptmkdir my-site && cd my-sitepulumi new static-website-cloudflare-pythonmkdir my-site && cd my-sitepulumi new static-website-cloudflare-gomkdir my-site && cd my-sitepulumi new static-website-cloudflare-csharpmkdir my-site && cd my-sitepulumi new static-website-cloudflare-yamlmkdir my-site && cd my-sitepulumi new static-website-cloudflare-hclFollow the prompts to complete the new-project wizard. When it’s done, you’ll have a complete Pulumi project that’s ready to deploy and configured with the most common settings. Feel free to inspect the code in index.tsindex.js__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yaml for a closer look.
Deploying the project#
The template needs one setting to deploy: the Cloudflare account ID to deploy into. Set it, then deploy with pulumi up:
pulumi config set accountId <your-account-id>pulumi uppulumi config set accountId <your-account-id>pulumi uppulumi config set accountId <your-account-id>pulumi uppulumi config set accountId <your-account-id>pulumi uppulumi config set accountId <your-account-id>pulumi uppulumi config set account_id <your-account-id>pulumi upWhen the deployment completes, Pulumi exports the following stack output value:
- url
The fully-qualified HTTPS URL of the deployed website on its
workers.devsubdomain.
Output values like this one are useful in many ways, most commonly as inputs for other stacks or related cloud resources. The computed URL, for example, can be used from the command line to open the newly deployed website in your favorite web browser:
open $(pulumi stack output url)Customizing the project#
Projects created with the Static Website template expose the following configuration settings:
- path
The path to the folder containing the files of the website. Defaults to
./www, which is the relative path of the folder included with the template.
- path
The path to the folder containing the files of the website. Defaults to
./www, which is the relative path of the folder included with the template.
- path
The path to the folder containing the files of the website. Defaults to
./www, which is the relative path of the folder included with the template.
- path
The path to the folder containing the files of the website. Defaults to
./www, which is the relative path of the folder included with the template.
- path
The path to the folder containing the files of the website. Defaults to
./www, which is the relative path of the folder included with the template.
- path
The path to the folder containing the files of the website. Defaults to
./www, which is the relative path of the folder included with the template.
This setting is optional and may be adjusted either by editing the stack configuration file directly (by default, Pulumi.dev.yaml) or by changing its value with pulumi config set.
Using your own web content#
If you already have a static website you’d like to deploy on Cloudflare with Pulumi, you can do so either by replacing the placeholder content in the www folder or by configuring the stack to point to another folder on your computer with the path setting:
pulumi config set path ../my-existing-website/buildpulumi upCleaning up#
You can cleanly destroy the stack and all of its infrastructure with pulumi destroy:
pulumi destroyLearn more#
- Browse other architecture templates in the Templates gallery.
- Explore the Cloudflare provider API docs in the Pulumi Registry.
- Walk through Pulumi from the ground up in Pulumi Tutorials.
- Read the latest Cloudflare posts on the Pulumi blog.