Posted on:July 1, 2024 at 02:30 AM

Using Cloudflare R2 as a Pulumi Backend

Using Cloudflare R2 as a Pulumi Backend

1. Introduction

To share Pulumi configurations within a team, it’s recommended to store Pulumi state files in block storage. In this guide, we’ll use Cloudflare R2, which offers 100GB of free storage.

2. Setup

Prerequisites

  1. Create a Cloudflare account
  2. Create a Google Cloud account
  3. Purchase a domain through Cloudflare
  4. Install required tools using Homebrew
brew install awscli
brew install --cask google-cloud-sdk

Cloudflare R2 Configuration

  1. Navigate to Cloudflare R2 Object Storage
  2. Select ‘Create Bucket’ and name it my-pulumi-backend (for storing Pulumi configurations)
  3. Check the required credentials in Manage R2 API Tokens
  4. Note the following information for S3-compatible API usage:
S3_ACCESS_KEY=87d2364ad95asdff4625eb9
S3_SECRET_KEY=d18743f3cc85asdf89877e6436
S3_BUCKET_NAME=my-pulumi-backend
S3_ENDPOINT=https://e17d7c715f89.r2.cloudflarestorage.com
S3_REGION=weur
  1. To verify with AWS CLI, configure as follows:
aws configure list
aws configure --profile r2  # Use this command to configure
AWS Access Key ID [****************5eb9]:
AWS Secret Access Key [****************6436]:
Default region name [weur]:
Default output format [json]:
  1. Add the following to your Pulumi .env file:
AWS_DEFAULT_PROFILE=r2

Pulumi Backend Configuration

pulumi login 's3://my-pulumi-backend?endpoint=e17d7c715f89.r2.cloudflarestorage.com'

Then add the following configuration to your pulumi.yaml file:

backend:
  url: s3://my-pulumi-backend?endpoint=e17d7c715f89.r2.cloudflarestorage.com

Once this setup is complete, a .pulumi folder will be created in your R2 bucket, where the state information will be stored.

For more details, please refer to:

https://www.pulumi.com/docs/iac/concepts/state-and-backends/