MCPcopy Index your code
hub / github.com/cloudflare/terraform-provider-cloudflare

github.com/cloudflare/terraform-provider-cloudflare @v5.21.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v5.21.1 ↗ · + Follow
19,434 symbols 68,441 edges 4,024 files 2,652 documented · 14%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Cloudflare Terraform Provider

The Cloudflare Terraform provider provides convenient access to the Cloudflare REST API from Terraform.

Requirements

This provider requires Terraform CLI 1.0 or later. You can install it for your system on Hashicorp's website.

Usage

Add the following to your main.tf file:

# Declare the provider and version
terraform {
  required_providers {
    cloudflare = {
      source  = "cloudflare/cloudflare"
      version = "~> 5.21.1"
    }
  }
}

# Initialize the provider
provider "cloudflare" {
  # The preferred authorization scheme for interacting with the Cloudflare API. [Create a token](https://developers.cloudflare.com/fundamentals/api/get-started/create-token/).
  api_token = "Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY" # or set CLOUDFLARE_API_TOKEN env variable
  # The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.
  api_key = "144c9defac04969c7bfad8efaa8ea194" # or set CLOUDFLARE_API_KEY env variable
  # The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.
  api_email = "user@example.com" # or set CLOUDFLARE_EMAIL env variable
  # Used when interacting with the Origin CA certificates API. [View/change your key](https://developers.cloudflare.com/fundamentals/api/get-started/ca-keys/#viewchange-your-origin-ca-keys).
  user_service_key = "v1.0-144c9defac04969c7bfad8ef-631a41d003a32d25fe878081ef365c49503f7fada600da935e2851a1c7326084b85cbf6429c4b859de8475731dc92a9c329631e6d59e6c73da7b198497172b4cefe071d90d0f5d2719" # or set CLOUDFLARE_API_USER_SERVICE_KEY env variable
  # Sets an account ID to be used with all account-scoped requests.
  account_id = "f037e56e89293a057740de681ac9accp" # or set CLOUDFLARE_ACCOUNT_ID env variable
  # Sets a zone ID to be used with all zone-scoped requests.
  zone_id = "f037e56e89293a057740de681ac9accp" # or set CLOUDFLARE_ZONE_ID env variable
}

# Configure a resource
resource "cloudflare_zone" "example_zone" {
  account = {
    id = "023e105f4ecef8ad9ca31a8372d0c353"
  }
  name = "example.com"
  type = "full"
}

Initialize your project by running terraform init in the directory.

Additional examples can be found in the ./examples folder within this repository, and you can refer to the full documentation on the Terraform Registry.

Provider Options

When you initialize the provider, the following options are supported. It is recommended to use environment variables for sensitive values like access tokens. If an environment variable is provided, then the option does not need to be set in the terraform source.

Property Environment variable Required Default value
zone_id CLOUDFLARE_ZONE_ID false
user_service_key CLOUDFLARE_API_USER_SERVICE_KEY false
api_token CLOUDFLARE_API_TOKEN false
api_key CLOUDFLARE_API_KEY false
api_email CLOUDFLARE_EMAIL false
account_id CLOUDFLARE_ACCOUNT_ID false

Semantic versioning

This package generally follows SemVer conventions, though certain backwards-incompatible changes may be released as minor versions:

  1. Changes to library internals which are technically public but not intended or documented for external use. (Please open a GitHub issue to let us know if you are relying on such internals.)
  2. Changes that we do not expect to impact the vast majority of users in practice.

We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.

We are keen for your feedback; please open an issue with questions, bugs, or suggestions.

Maintenance

This SDK is actively maintained, however, many issues are tracked outside of GitHub on internal Cloudflare systems. Members of the community are welcome to join and discuss your issues during our weekly triage meetings. For urgent issues, please contact Cloudflare support.

Contributing

See the contributing documentation.

Extension points exported contracts — how you extend this code

Marshaler (Interface)
(no doc) [7 implementers]
internal/apiform/form.go
Union (Interface)
(no doc) [4 implementers]
internal/apijsoncustom/json_test.go
CustomMarshaler (Interface)
CustomMarshaler allows types to override their JSON encoding behavior while supporting plan/state diffing for Terraform [1 …
internal/apijson/encoder.go
IsNull (Interface)
(no doc)
internal/services/zero_trust_access_policy/normalizations.go
NestedObjectMapLike (Interface)
(no doc)
internal/customfield/object_map.go
Union (Interface)
(no doc) [4 implementers]
internal/apiform/form_test.go
SetValueInterface (Interface)
(no doc)
internal/services/zero_trust_access_policy/normalizations.go
NestedObjectListLike (Interface)
(no doc)
internal/customfield/object_list.go

Core symbols most depended-on inside this repo

Error
called by 4384
internal/test_helpers/integrity.go
IsNull
called by 1760
internal/services/zero_trust_access_application/normalizations.go
GenerateRandomResourceName
called by 1649
internal/utils/random_acc_test_name.go
Middleware
called by 1452
internal/logging/logging.go
UnmarshalComputed
called by 979
internal/apijson/decoder.go
LoadTestCase
called by 979
internal/acctest/acctest.go
Report
called by 782
internal/test_helpers/integrity.go
String
called by 596
internal/services/snippet/model.go

Shape

Function 6,865
Method 6,483
Struct 6,043
Interface 19
TypeAlias 16
FuncType 8

Languages

Go100%

Modules by API surface

internal/services/zero_trust_access_application/migration/v500/model.go120 symbols
internal/services/zero_trust_access_application/resource_test.go115 symbols
internal/services/zero_trust_access_group/data_source_model.go113 symbols
internal/services/zero_trust_access_group/list_data_source_model.go112 symbols
internal/services/zero_trust_access_application/model.go105 symbols
internal/services/zero_trust_access_application/data_source_model.go103 symbols
internal/services/zero_trust_access_application/list_data_source_model.go102 symbols
internal/services/zero_trust_access_policy/model.go89 symbols
internal/services/zero_trust_access_policy/list_data_source_model.go89 symbols
internal/services/zero_trust_access_policy/data_source_model.go88 symbols
internal/services/zero_trust_access_group/model.go85 symbols
internal/services/page_rule/resource_test.go84 symbols

For agents

$ claude mcp add terraform-provider-cloudflare \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact