Tutorial Tutorial Tutorial Developer Platform Developer Platform Developer Platform ~10 phút ~10 min ~10 នាទី Đồng bộ 2026-06-10 Synced 2026-06-10 ធ្វើសមកាល 2026-06-10

Tạo các tài nguyên khác nhau bằng cách sử dụng Pulumi và Wrangler Create different resources using Pulumi and Wrangler ការបង្កើតសារធាតុផ្សេងគ្នាដោយប្រើ Pulumi និង Wrangler

Hướng dẫn chi tiết đồng bộ từ docs Cloudflare — mỗi section có backlink tới đúng vị trí trên trang gốc. Detailed guide synced from Cloudflare docs — each section links to the matching anchor on the official page. មគ្គុទ្ទេសក៍លម្អិតធ្វើសមកាលពី docs Cloudflare — ផ្នែកនីមួយៗមានតំណទៅទីតាំងត្រូវគ្នានៅទំព័រផ្លូវការ។

← Danh mục ← Catalog ← បញ្ជី

Giải thích nhanh Quick context បរិបទរហ័ស

Thuộc Developer Platform — thực hành triển khai code, API và dữ liệu trên edge/serverless. Tutorial «Tạo different resources using Pulumi và Wrangler» giúp bạn làm quen luồng triển khai thật — phù hợp đọc trước khi mở tài liệu gốc tiếng Anh. Đọc phần tóm tắt và lưu ý trước — sau đó mở docs gốc để copy lệnh và cấu hình chi tiết.

Pulumi and Wrangler can be used to create different types of resources.

Pulumi និង Wrangler អាចត្រូវបានប្រើដើម្បីបង្កើតប្រភេទផ្សេងគ្នានេះ។

Lưu ý Note ចំណាំ

Lưu ý trước khi làm Notes before you start ចំណាំមុនពេលចាប់ផ្តើម

  • Đây là bản tóm tắt trên Orange Cloud Learning Hub — không thay thế tài liệu chính thức.
  • Luôn mở liên kết «Tài liệu gốc» bên dưới khi cần lệnh CLI, snippet code và ảnh minh họa đầy đủ.
  • Cần tài khoản Cloudflare, Wrangler CLI và (thường) hoàn thành hướng dẫn Get started của Workers/Pages.
  • Kiểm tra token/API và state backend trước khi chạy trên môi trường production.
  • Docs Cloudflare cập nhật thường xuyên — đối chiếu ngày «Rà soát lần cuối» trên trang gốc khi triển khai production.
  • This is a summary on Orange Cloud Learning Hub — it does not replace the official documentation.
  • Open the Official docs link below for CLI commands, code snippets, and full screenshots.
  • Requires a Cloudflare account, Wrangler CLI, and (typically) completing the Workers/Pages Get started guide.
  • Verify API tokens and the state backend before running against production.
  • Cloudflare docs change frequently — verify the Last reviewed date on the official page before production use.
  • នេះគឺជាការបញ្ជាក់អំពី Orange Cloud Learning Hub — វាគឺជាការផ្លាស់ប្តូរនៃឯកសារផ្លូវការ។
  • ចុចតំណភ្ជាប់ Docs Official នៅខាងក្រោមសម្រាប់ការបញ្ជា CLI, សៀវភៅកូដនិងរូបថតពេញលេញ។
  • តម្រូវឱ្យមានគណនី Cloudflare, Wrangler CLI និង (ប្រហែលជា) ការបញ្ចប់គណនី Workers/Pages Get started ។
  • សូមពិនិត្យមើល API tokens និងការបង្វិលប្រព័ន្ធប្រតិបត្តិការមុនពេលធ្វើការប្រឆាំងនឹងការផលិត។
  • Cloudflare បានផ្លាស់ប្តូរជាធម្មតានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅ។

Tài liệu gốc — rà soát lần cuối: over 1 year ago Official docs — last reviewed: over 1 year ago ឯកសារផ្លូវការ — ពិនិត្យចុងក្រោយ: over 1 year ago

Overview Overview Overview

Phần «Tổng quan» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Overview" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «Overview» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Ví dụ này tạo một vùng và các tài nguyên khác bằng cách sử dụng hai chiến lược khác nhau:
This example creates a zone and other resources using two different strategies:
ឧទាហរណ៍នេះបានបង្កើតតំបន់និងឧបករណ៍ផ្សេងទៀតដោយប្រើប្រព័ន្ធផ្សេងគ្នានិងប្រព័ន្ធផ្សេងគ្នានេះ។
  • Sử dụng Pulumi cho một số tài nguyên được hỗ trợ bởi nhà cung cấp Cloudflare Pulumi.
  • Sử dụng Wrangler để tạo các loại tài nguyên khác.
  • Use Pulumi for some resources supported by the Cloudflare Pulumi provider.
  • Use Wrangler to create other types of resources.
  • ប្រើ Pulumi សម្រាប់ចំណុចមួយចំនួនដែលគាំទ្រដោយក្រុមហ៊ុនផ្គត់ផ្គង់ Pulumi Cloudflare ។
  • ប្រើ Wrangler ដើម្បីបង្កើតប្រភេទសម្បត្តិផ្សេងទៀត។
Mã ví dụ bao gồm việc tạo các tài nguyên như Workers, Zero Trust Ứng dụng, Zero Trust Chính sách, và D1 cơ sở dữ liệu.
The example code covers the creation of resources such as Workers, Zero Trust Applications, Zero Trust Policies, and D1 databases.
លេខកូដឧទាហរណ៍រួមបញ្ចូលទាំងការបង្កើតឧបករណ៍ដូចជា Workers, Zero Trust Applications, Zero Trust Policy និង D1 databases ។

Wrangler sử dụng Wrangler usage Wrangler ការប្រើប្រាស់

Phần «Wrangler usage» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Wrangler usage" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «Wrangler ការប្រើប្រាស់» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Mã trong ví dụ này cho thấy cách bạn có thể tạo Workers bằng cách gọi Wrangler trực tiếp thay vì sử dụng tài nguyên được hỗ trợ trực tiếp bởi nhà cung cấp Cloudflare Pulumi. Ưu điểm của việc sử dụng phương pháp này là bạn có thể sử dụng nó cho bất kỳ nhiệm vụ nào liên quan đến triển khai, chẳng hạn như thực hiện di chuyển D1. Khi bạn chạy kịch bản cơ sở hạ tầng dưới dạng mã (IaC), Wrangler tạo hoặc cập nhật Workers và D1, bao gồm thực hiện di chuyển cơ sở dữ liệu.
The code in this example shows how you can create Workers by calling Wrangler directly instead of using the resource directly supported by the Cloudflare Pulumi provider. The advantage of using this method is that you can use it for any deployment-related task such as executing D1 migrations. When you run the infrastructure as code (IaC) script, Wrangler creates or updates Workers and D1, which includes performing database migrations.
លេខកូដនៅក្នុងឧទាហរណ៍នេះបង្ហាញពីរបៀបដែលអ្នកអាចបង្កើត Workers ដោយទូរស័ព្ទ Wrangler ដោយផ្ទាល់ដោយគ្មានការប្រើប្រាស់ចំណាយដែលគាំទ្រដោយផ្ទាល់ដោយអ្នកផ្គត់ផ្គង់ Cloudflare Pulumi ។ លក្ខណៈពិសេសនៃការប្រើប្រាស់វិធីនេះគឺថាអ្នកអាចប្រើវាសម្រាប់សកម្មភាពណាមួយដែលមានទាក់ទងនឹងការដំឡើងដូចជាការធ្វើដំណើរការ D1 ។ នៅពេលដែលអ្នកដំណើរការឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្ជាឧបករណ៍បញ្
Trong ví dụ hiện tại, trạng thái di chuyển D1 trong Pulumi chỉ thay đổi khi hash của thư mục migrations thay đổi, trong trường hợp đó lệnh Pulumi sẽ được thực hiện.
In the current example, the D1 migrations state in Pulumi only changes when the hash of the migrations directory changes, in which case the Pulumi command will be executed.
នៅក្នុងឧទាហរណ៍បច្ចុប្បន្ននេះ D1 ការផ្លាស់ប្តូរស្ថានភាពនៅក្នុង Pulumi ត្រូវបានផ្លាស់ប្តូរតែបន្ទាប់ពីការផ្លាស់ប្តូរ hash នៃអេឡិចត្រូនិ migrations ។ ក្នុងករណីនេះការបញ្ជា Pulumi នឹងត្រូវបានអនុវត្ត។

Nhà cung cấp tài nguyên động cho Vectorize Dynamic resource provider for Vectorize អ្នកផ្គត់ផ្គង់ឧបករណ៍ឌីមីសម្រាប់ Vectorize

Phần «Dynamic resource provider for Vectorize» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Dynamic resource provider for Vectorize" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «អ្នកផ្គត់ផ្គង់ឧបករណ៍ឌីមីសម្រាប់ Vectorize» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Ví dụ này cũng cung cấp một ví dụ về nhà cung cấp tài nguyên động cho một tài nguyên không được hỗ trợ trực tiếp bởi nhà cung cấp Cloudflare Pulumi (trong trường hợp này, Vectorize).
The example also provides an example of a dynamic resource provider for a resource that is not directly supported by the Cloudflare Pulumi provider (in this case, Vectorize).
ឧទាហរណ៍នេះក៏ផ្តល់នូវឧទាហរណ៍នៃអ្នកផ្គត់ផ្គង់ប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធប្រតិបត្តិការប្រព័ន្ធ

Ví dụ code Example code លេខកូដ

Phần «Example code» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Example code" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «លេខកូដ» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
JavaScript Đánh giá
JavaScript
កុំព្យូទ័រ
text
"use strict";


const pulumi = require("@pulumi/pulumi");

const cloudflare = require("@pulumi/cloudflare");

const command = require("@pulumi/command");

const path = require("path");

const axios = require("axios");

const https = require("https");

const crypto = require("crypto");

const fs = require("fs");


// Load configuration

const config = new pulumi.Config();

const domainName = config.require("domainName");

const accountId = config.require("accountId");

const apiToken = config.requireSecret("apiToken");


// Function to compute hash of a file

function computeFileHashSync(filePath) {

  const fileBuffer = fs.readFileSync(filePath);

  const hash = crypto.createHash("sha256");

  hash.update(fileBuffer);

  return hash.digest("hex");

}


// Function to compute the hash of a directory

async function hashDirectory(dirPath) {

  const files = await fs.promises.readdir(dirPath);

  const fileHashes = [];

  for (const file of files) {

    const filePath = path.join(dirPath, file);

    const fileStat = await fs.promises.stat(filePath);

    if (fileStat.isFile()) {

      const fileData = await fs.promises.readFile(filePath);

      const hash = crypto.createHash("sha256").update(fileData).digest("hex");

      fileHashes.push(hash);

    }

  }

  // Combine all file hashes and hash the result to get a unique hash for the directory

  const combinedHash = crypto

    .createHash("sha256")

    .update(fileHashes.join(""))

    .digest("hex");

  return combinedHash;

}


// Instantiate Cloudflare provider

// https://www.pulumi.com/registry/packages/cloudflare/

//-----------------------------------------------------------------------------

const cloudflareProvider = new cloudflare.Provider("cloudflare", {

  apiToken: apiToken,

});


// Create a Cloudflare Zone

// https://www.pulumi.com/registry/packages/cloudflare/api-docs/zone/

//-----------------------------------------------------------------------------

const myZone = new cloudflare.Zone(

  "myZone",

  {

    zone: domainName,

    plan: "enterprise",

    accountId: accountId,

  },

  { provider: cloudflareProvider },

);


// Create a Cloudflare Queue (used as a binding in Worker)

// https://www.pulumi.com/registry/packages/cloudflare/api-docs/queue/

//-----------------------------------------------------------------------------

const myqueue = new cloudflare.Queue(

  "myqueue",

  {

    zoneId: myZone.id,

    name: "myqueue",

    description: "Queue for my messages",

    accountId: accountId,

  },

  { provider: cloudflareProvider },

);


// Create a Cloudflare Queue (used as a binding in Worker)

// https://www.pulumi.com/registry/packages/cloudflare/api-docs/queue/

//-----------------------------------------------------------------------------

const myqueuedeadletter = new cloudflare.Queue(

  "myqueuedeadletter",

  {

    zoneId: myZone.id,

    name: "myqueuedeadletter",

    description: "Queue for messages that were not processed correctly",

    accountId: accountId,

  },

  { provider: cloudflareProvider },

);


// Create a D1 Database

// https://www.pulumi.com/registry/packages/cloudflare/api-docs/d1database/

//-----------------------------------------------------------------------------

const myD1Database = new cloudflare.D1Database(

  "myD1Database",

  {

    accountId: accountId,

    name: "mydb",

  },

  { provider: cloudflareProvider },

);


// Deploy Changes to D1 Schema

// - Cloudflare Wrangler stores a list of migrations in the D1 database.

// - To check which migrations were run, go to the Cloudflare dashboard

//   and run "SELECT * FROM d1_migrations" on the console of the D1 database.

//-----------------------------------------------------------------------------

const d1Dir = "../../mydb/";

const d1Migration = new command.local.Command(

  "d1Migration",

  {

    dir: d1Dir,

    create: `npx wrangler d1 migrations apply mydb --remote`,

    triggers: [hashDirectory(`${d1Dir}migrations`)],

  },

Access Xuất khẩu Pulumi Access Pulumi exports Access ការនាំចេញ Pulumi

Phần «Access Pulumi exports» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Access Pulumi exports" section below — open the official docs link for full screenshots and configuration tabs.

អានផ្នែក «Access ការនាំចេញ Pulumi» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។

Mở section docs gốc ↗ Open source section ↗ បើកផ្នែក docs ផ្លូវការ ↗
Sau khi bạn chạy kịch bản Pulumi của bạn với pulumi up, tài nguyên của bạn sẽ được tạo hoặc cập nhật.
Once you run your Pulumi script with pulumi up, your resources will be created or updated.
បន្ទាប់ពីអ្នកដំណើរការប្រព័ន្ធប្រតិបត្តិការ Pulumi របស់អ្នកជាមួយ pulumi up អ្នកនឹងត្រូវបានបង្កើតឬបច្ចុប្បន្នភាពប្រសិទ្ធិភាពរបស់អ្នក។
Ví dụ kịch bản ở trên cũng xuất các đầu ra mà bạn có thể access từ các công cụ khác. Điều này hữu ích, ví dụ, khi tích hợp kịch bản Pulumi vào một đường ống triển khai.
The example script above also exports outputs that you can access from other tools. This is useful for example when integrating the Pulumi script into a deployment pipeline.
ប្រព័ន្ធ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ ប្រតិបត្តិការ នេះជាប្រយោជន៍សម្រាប់ការរួមបញ្ចូលប្រព័ន្ធប្រតិបត្តិការ Pulumi នៅក្នុងបំពង់ដំណើរការ។
Bạn có thể sử dụng một lệnh tương tự như sau:
You could use a command similar to the following:
អ្នកអាចប្រើជំហានដូចខាងក្រោមនេះ:
Cửa sổ Terminal
Terminal window
បង្វិល Terminal
text
pulumi stack output myServiceTokenClientSecret --show-secrets
json
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"@id":"/directory/","name":"Directory"}},{"@type":"ListItem","position":2,"item":{"@id":"/pulumi/","name":"Pulumi"}},{"@type":"ListItem","position":3,"item":{"@id":"/pulumi/tutorial/","name":"Tutorials"}},{"@type":"ListItem","position":4,"item":{"@id":"/pulumi/tutorial/dynamic-provider-and-wrangler/","name":"Create different resources using Pulumi and Wrangler"}}]}

Xem bản đầy đủ trên developers.cloudflare.com (ảnh, tab cấu hình). View the full guide on developers.cloudflare.com (images, config tabs). មើលមគ្គុទ្ទេសក៍ពេញលើ developers.cloudflare.com (រូបភាព, tab កំណត់)។

Tài liệu gốc ↗ Official docs ↗ ឯកសារផ្លូវការ ↗