Add a site·续
ctx.Export("zoneId", zone.ID()) ctx.Export("nameservers", zone.NameServers) ctx.Export("status", zone.Status) return nil }) }
**Filename: `src/main/java/myproject/App.java`**
```java
package myproject;
import com.pulumi.Pulumi;
import com.pulumi.Context;
import com.pulumi.cloudflare.ZoneArgs;
import com.pulumi.cloudflare.Zone;
public class App {
public static void main(String[] args) {
Pulumi.run(ctx -> {
var config = ctx.config();
String accountId = config.require("accountId");
String domain = config.require("domain");
var zone = new Zone("my-zone", ZoneArgs.builder()
.zone(domain)
.accountId(accountId)
.plan("free")
.jumpStart(true)
.build());
ctx.export("zoneId", zone.id());
ctx.export("nameservers", zone.nameServers());
ctx.export("status", zone.status());
});
}
}
Filename: Program.cs
using System.Threading.Tasks;
using System.Collections.Immutable;
using Pulumi;
using Pulumi.Cloudflare;
class Program
{
static Task<int> Main() => Deployment.RunAsync<MyStack>();
class MyStack : Stack
{
public MyStack()
{
var config = new Pulumi.Config();
var accountId = config.Require("accountId");
var domain = config.Require("domain");
var zone = new Zone("my-zone", new ZoneArgs
{
ZoneName = domain,
AccountId = accountId,
Plan = "free",
JumpStart = true
});
this.ZoneId = zone.Id;
this.Nameservers = zone.NameServers;
this.Status = zone.Status;
}
[Output]
public Output<string> ZoneId { get; set; }
public Output<ImmutableArray<string>> Nameservers { get; set; }
public Output<string> Status { get; set; }
}
}
Filename: Pulumi.yaml
name: addsite-cloudflare
runtime: yaml
resources:
myZone:
type: cloudflare:Zone
properties:
zone: ${domain}
accountId: ${accountId}
plan: "free"
jumpStart: true
outputs:
zoneId: ${myZone.id}
nameservers: ${exampleZone.nameServers}
status: ${exampleZone.status}
Notice that the code also outputs several properties from the Zone resource, such as the zoneId, nameservers, and status, so that they can easily be accessed in subsequent steps.
b. Add a DNS Record
You will now add a DNS Record resource ↗︎ to test previously configured Zone.
Add the following code snippet to your entrypoint file after the Zone resource definition:
Filename: index.js
const record = new cloudflare.Record("my-record", {
zoneId: zone.id,
name: domain,
content: "192.0.2.1",
type: "A",
proxied: true,
});
Filename: index.ts
const record = new cloudflare.Record("my-record", {
zoneId: zone.id,
name: domain,
content: "192.0.2.1",
type: "A",
proxied: true,
});
Filename: __main__.py
record = cloudflare.Record("my-record",
zone_id=zone.id,
name=domain,
content="192.0.2.1",
type="A",
proxied=True
)
Filename: main.go
_, err = cloudflare.NewRecord(ctx, "my-record", &cloudflare.RecordArgs{
ZoneId: zone.ID(),
Name: pulumi.String(domain),
Content: pulumi.String("192.0.2.1"),
Type: pulumi.String("A"),
Proxied: pulumi.Bool(true),
})
if err != nil {
return err
}
Filename: src/main/java/myproject/App.java
// Add imports
import com.pulumi.cloudflare.Record;
import com.pulumi.cloudflare.RecordArgs;
// Below the Zone resource, add
new Record("my-record", RecordArgs.builder()
.zoneId(zone.id())
.name(domain)
.content("192.0.2.1")
.type("A")
.proxied(true)
.build());
Filename: Program.cs
new Record("my-record", new RecordArgs
{
ZoneId = zone.Id,
Name = domain,
Content = "192.0.2.1",
Type = "A",
Proxied = true
});
Filename: Pulumi.yaml
myRecord:
type: cloudflare:Record
properties:
zoneId: ${myZone.id}
name: ${domain}
content: 192.0.2.1
type: A
proxied: true
3. Deploy your changes
Now that you have defined your resources, you can deploy the changes using the Pulumi CLI so that they are reflected in your Cloudflare account.
To deploy the changes, run:
pulumi up --yes
wait for the dev stack to become ready
4. Configure your DNS provider
Note
This process makes Cloudflare your authoritative DNS provider, allowing your DNS queries and web traffic to be served from and protected by the Cloudflare network.
Learn more about pending domains
Note
If your site is example.com, skip ahead to Test your site.
a. Obtain your nameservers
Once you have added a domain to Cloudflare, that domain will receive two assigned authoritative nameservers.
To retrieve the assigned nameservers, run:
pulumi stack output
b. Update your registrar
Update the nameservers at your registrar to activate Cloudflare services for your domain. The instructions are registrar-specific. You may be able to find guidance under this consolidated list of common registrars.
Caution
Registrars take up to 24 hours to process nameserver changes.
c. Check your domain status
Once successfully registered, your domain status will change to active.
pulumi stack output
5. Test your site
You will run two nslookup commands against the Cloudflare-assigned nameservers.
To test your site, run:
DOMAIN=$(pulumi config get domain)
NS1=$(pulumi stack output nameservers | jq '.[0]' -r)
NS2=$(pulumi stack output nameservers | jq '.[1]' -r)
nslookup $DOMAIN $NS1
nslookup $DOMAIN $NS2
For .NET, use Nameservers as the Output.
Confirm your response returns the IP address(es) for your site.
Note
You will not receive a valid response if you use example.com as your site.
6. Clean up
In this last step, you will remove the resources and stack used throughout the tutorial.
a. Delete the resources
pulumi destroy --yes
b. Remove the stack
pulumi stack rm dev
Next steps
You have incrementally defined Cloudflare resources needed to add a site to Cloudflare. You declare the resources in your programming language of choice and let Pulumi handle the rest.
To deploy a serverless app with Pulumi, follow the Deploy a Worker tutorial.
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/pulumi/tutorial/add-site/#page","headline":"Add a site","description":"This tutorial uses Pulumi infrastructure as code (IaC) to familiarize yourself with the resource management lifecycle.","url":"https://developers.cloudflare.com/pulumi/tutorial/add-site/","inLanguage":"en","image":"https://developers.cloudflare.com/pulumi/tutorial/add-site/og.png?v=5f944440c9fc37a7","dateModified":"2026-04-21","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"},"keywords":["JavaScript","TypeScript","Python","Go","Java",".NET","YAML"]}
description: Pulumi and Wrangler can be used to create different types of resources. title: Create different resources using Pulumi and Wrangler image: https://developers.cloudflare.com/pulumi/tutorial/dynamic-provider-and-wrangler/og.png?v=b42812ead2889779
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/pulumi/llms.txt
Use this file to discover all available pages before exploring further.
Docs