diff --git a/internal/services/workers_script/model.go b/internal/services/workers_script/model.go index d05be5eacb..966fe1ee8f 100644 --- a/internal/services/workers_script/model.go +++ b/internal/services/workers_script/model.go @@ -8,7 +8,6 @@ import ( "github.com/cloudflare/terraform-provider-cloudflare/internal/apijson" "github.com/cloudflare/terraform-provider-cloudflare/internal/customfield" - "github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/jinzhu/copier" ) @@ -18,17 +17,17 @@ type WorkersScriptResultEnvelope struct { } type WorkersScriptModel struct { - ID types.String `tfsdk:"id" json:"-,computed"` - ScriptName types.String `tfsdk:"script_name" path:"script_name,required"` - AccountID types.String `tfsdk:"account_id" path:"account_id,required"` - Message types.String `tfsdk:"message" json:"message,optional"` - Content types.String `tfsdk:"content" json:"content,required"` - CreatedOn timetypes.RFC3339 `tfsdk:"created_on" json:"created_on,computed" format:"date-time"` - Etag types.String `tfsdk:"etag" json:"etag,computed"` - HasAssets types.Bool `tfsdk:"has_assets" json:"has_assets,computed"` - HasModules types.Bool `tfsdk:"has_modules" json:"has_modules,computed"` - ModifiedOn timetypes.RFC3339 `tfsdk:"modified_on" json:"modified_on,computed" format:"date-time"` - StartupTimeMs types.Int64 `tfsdk:"startup_time_ms" json:"startup_time_ms,computed"` + ID types.String `tfsdk:"id" json:"-,computed"` + ScriptName types.String `tfsdk:"script_name" path:"script_name,required"` + AccountID types.String `tfsdk:"account_id" path:"account_id,required"` + // Message types.String `tfsdk:"message" json:"message,optional"` + Content types.String `tfsdk:"content" json:"content,required"` + // CreatedOn timetypes.RFC3339 `tfsdk:"created_on" json:"created_on,computed" format:"date-time"` + // Etag types.String `tfsdk:"etag" json:"etag,computed"` + // HasAssets types.Bool `tfsdk:"has_assets" json:"has_assets,computed"` + // HasModules types.Bool `tfsdk:"has_modules" json:"has_modules,computed"` + // ModifiedOn timetypes.RFC3339 `tfsdk:"modified_on" json:"modified_on,computed" format:"date-time"` + // StartupTimeMs types.Int64 `tfsdk:"startup_time_ms" json:"startup_time_ms,computed"` WorkersScriptMetadataModel } @@ -63,21 +62,21 @@ func (r WorkersScriptModel) MarshalMultipart() (data []byte, contentType string, } type WorkersScriptMetadataModel struct { - Assets customfield.NestedObject[WorkersScriptMetadataAssetsModel] `tfsdk:"assets" json:"assets,computed_optional"` - Bindings customfield.NestedObjectList[WorkersScriptMetadataBindingsModel] `tfsdk:"bindings" json:"bindings,computed_optional"` - BodyPart types.String `tfsdk:"body_part" json:"body_part,optional"` - CompatibilityDate types.String `tfsdk:"compatibility_date" json:"compatibility_date,optional"` - CompatibilityFlags *[]types.String `tfsdk:"compatibility_flags" json:"compatibility_flags,optional"` - KeepAssets types.Bool `tfsdk:"keep_assets" json:"keep_assets,optional"` - KeepBindings *[]types.String `tfsdk:"keep_bindings" json:"keep_bindings,optional"` - Logpush types.Bool `tfsdk:"logpush" json:"logpush,optional"` - MainModule types.String `tfsdk:"main_module" json:"main_module,optional"` - Migrations customfield.NestedObject[WorkersScriptMetadataMigrationsModel] `tfsdk:"migrations" json:"migrations,computed_optional"` - Observability customfield.NestedObject[WorkersScriptMetadataObservabilityModel] `tfsdk:"observability" json:"observability,computed_optional"` - Placement customfield.NestedObject[WorkersScriptMetadataPlacementModel] `tfsdk:"placement" json:"placement,computed_optional"` - Tags *[]types.String `tfsdk:"tags" json:"tags,optional"` - TailConsumers customfield.NestedObjectList[WorkersScriptMetadataTailConsumersModel] `tfsdk:"tail_consumers" json:"tail_consumers,computed_optional"` - UsageModel types.String `tfsdk:"usage_model" json:"usage_model,optional"` + Assets customfield.NestedObject[WorkersScriptMetadataAssetsModel] `tfsdk:"assets" json:"assets,computed_optional"` + Bindings customfield.NestedObjectList[WorkersScriptMetadataBindingsModel] `tfsdk:"bindings" json:"bindings,computed_optional"` + BodyPart types.String `tfsdk:"body_part" json:"body_part,optional"` + CompatibilityDate types.String `tfsdk:"compatibility_date" json:"compatibility_date,optional"` + CompatibilityFlags *[]types.String `tfsdk:"compatibility_flags" json:"compatibility_flags,optional"` + KeepAssets types.Bool `tfsdk:"keep_assets" json:"keep_assets,optional"` + KeepBindings *[]types.String `tfsdk:"keep_bindings" json:"keep_bindings,optional"` + Logpush types.Bool `tfsdk:"logpush" json:"logpush,optional"` + MainModule types.String `tfsdk:"main_module" json:"main_module,optional"` + Migrations customfield.NestedObject[WorkersScriptMetadataMigrationsModel] `tfsdk:"migrations" json:"migrations,computed_optional"` + Observability customfield.NestedObject[WorkersScriptMetadataObservabilityModel] `tfsdk:"observability" json:"observability,computed_optional"` + Placement customfield.NestedObject[WorkersScriptMetadataPlacementModel] `tfsdk:"placement" json:"placement,computed_optional"` + // Tags *[]types.String `tfsdk:"tags" json:"tags,optional"` + TailConsumers customfield.NestedObjectList[WorkersScriptMetadataTailConsumersModel] `tfsdk:"tail_consumers" json:"tail_consumers,computed_optional"` + UsageModel types.String `tfsdk:"usage_model" json:"usage_model,optional"` } type WorkersScriptMetadataAssetsModel struct { @@ -162,6 +161,11 @@ type WorkersScriptMetadataMigrationsStepsTransferredClassesModel struct { To types.String `tfsdk:"to" json:"to,optional"` } +type WorkersScriptMetadataObservabilityModel struct { + Enabled types.Bool `tfsdk:"enabled" json:"enabled,required"` + HeadSamplingRate types.Float64 `tfsdk:"head_sampling_rate" json:"head_sampling_rate,optional"` +} + type WorkersScriptMetadataPlacementModel struct { Mode types.String `tfsdk:"mode" json:"mode,optional"` Status types.String `tfsdk:"status" json:"status,computed"` diff --git a/internal/services/workers_script/schema.go b/internal/services/workers_script/schema.go index 87a2d58991..f2494d13b9 100644 --- a/internal/services/workers_script/schema.go +++ b/internal/services/workers_script/schema.go @@ -5,6 +5,7 @@ package workers_script import ( "context" + "github.com/cloudflare/terraform-provider-cloudflare/internal/customfield" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" @@ -39,391 +40,371 @@ func ResourceSchema(ctx context.Context) schema.Schema { Description: "Module or Service Worker contents of the Worker.", Required: true, }, - "metadata": schema.SingleNestedAttribute{ - Description: "JSON encoded metadata about the uploaded parts and Worker configuration.", - Required: true, + "assets": schema.SingleNestedAttribute{ + Description: "Configuration for assets within a Worker", + Optional: true, + CustomType: customfield.NewNestedObjectType[WorkersScriptMetadataAssetsModel](ctx), Attributes: map[string]schema.Attribute{ - "assets": schema.SingleNestedAttribute{ - Description: "Configuration for assets within a Worker", + "config": schema.SingleNestedAttribute{ + Description: "Configuration for assets within a Worker.", Optional: true, Attributes: map[string]schema.Attribute{ - "config": schema.SingleNestedAttribute{ - Description: "Configuration for assets within a Worker.", + "html_handling": schema.StringAttribute{ + Description: "Determines the redirects and rewrites of requests for HTML content.", Optional: true, - Attributes: map[string]schema.Attribute{ - "html_handling": schema.StringAttribute{ - Description: "Determines the redirects and rewrites of requests for HTML content.", - Optional: true, - Validators: []validator.String{ - stringvalidator.OneOfCaseInsensitive( - "auto-trailing-slash", - "force-trailing-slash", - "drop-trailing-slash", - "none", - ), - }, - }, - "not_found_handling": schema.StringAttribute{ - Description: "Determines the response when a request does not match a static asset, and there is no Worker script.", - Optional: true, - Validators: []validator.String{ - stringvalidator.OneOfCaseInsensitive( - "none", - "404-page", - "single-page-application", - ), - }, - }, - "serve_directly": schema.BoolAttribute{ - Description: "When true and the incoming request matches an asset, that will be served instead of invoking the Worker script. When false, requests will always invoke the Worker script.", - Computed: true, - Optional: true, - Default: booldefault.StaticBool(true), - }, + Validators: []validator.String{ + stringvalidator.OneOfCaseInsensitive( + "auto-trailing-slash", + "force-trailing-slash", + "drop-trailing-slash", + "none", + ), }, }, - "jwt": schema.StringAttribute{ - Description: "Token provided upon successful upload of all files from a registered manifest.", + "not_found_handling": schema.StringAttribute{ + Description: "Determines the response when a request does not match a static asset, and there is no Worker script.", + Optional: true, + Validators: []validator.String{ + stringvalidator.OneOfCaseInsensitive( + "none", + "404-page", + "single-page-application", + ), + }, + }, + "serve_directly": schema.BoolAttribute{ + Description: "When true and the incoming request matches an asset, that will be served instead of invoking the Worker script. When false, requests will always invoke the Worker script.", + Computed: true, Optional: true, + Default: booldefault.StaticBool(true), }, }, }, - "bindings": schema.ListNestedAttribute{ - Description: "List of bindings attached to a Worker. You can find more about bindings on our docs: https://developers.cloudflare.com/workers/configuration/multipart-upload-metadata/#bindings.", + "jwt": schema.StringAttribute{ + Description: "Token provided upon successful upload of all files from a registered manifest.", Optional: true, - NestedObject: schema.NestedAttributeObject{ + }, + }, + }, + "bindings": schema.ListNestedAttribute{ + Description: "List of bindings attached to a Worker. You can find more about bindings on our docs: https://developers.cloudflare.com/workers/configuration/multipart-upload-metadata/#bindings.", + Optional: true, + Computed: true, + CustomType: customfield.NewNestedObjectListType[WorkersScriptMetadataBindingsModel](ctx), + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "name": schema.StringAttribute{ + Description: "A JavaScript variable name for the binding.", + Required: true, + }, + "type": schema.StringAttribute{ + Description: "The kind of resource that the binding provides.", + Required: true, + }, + "dataset": schema.StringAttribute{ + Description: "The dataset name to bind to.", + Optional: true, + }, + "id": schema.StringAttribute{ + Description: "Identifier of the D1 database to bind to.", + Optional: true, + }, + "namespace": schema.StringAttribute{ + Description: "Namespace to bind to.", + Optional: true, + }, + "outbound": schema.SingleNestedAttribute{ + Description: "Outbound worker.", + Optional: true, Attributes: map[string]schema.Attribute{ - "name": schema.StringAttribute{ - Description: "A JavaScript variable name for the binding.", - Required: true, - }, - "type": schema.StringAttribute{ - Description: "The kind of resource that the binding provides.", - Required: true, - }, - "dataset": schema.StringAttribute{ - Description: "The dataset name to bind to.", + "params": schema.ListAttribute{ + Description: "Pass information from the Dispatch Worker to the Outbound Worker through the parameters.", Optional: true, + ElementType: types.StringType, }, - "id": schema.StringAttribute{ - Description: "Identifier of the D1 database to bind to.", - Optional: true, - }, - "namespace": schema.StringAttribute{ - Description: "Namespace to bind to.", - Optional: true, - }, - "outbound": schema.SingleNestedAttribute{ + "worker": schema.SingleNestedAttribute{ Description: "Outbound worker.", Optional: true, Attributes: map[string]schema.Attribute{ - "params": schema.ListAttribute{ - Description: "Pass information from the Dispatch Worker to the Outbound Worker through the parameters.", + "environment": schema.StringAttribute{ + Description: "Environment of the outbound worker.", Optional: true, - ElementType: types.StringType, }, - "worker": schema.SingleNestedAttribute{ - Description: "Outbound worker.", + "service": schema.StringAttribute{ + Description: "Name of the outbound worker.", Optional: true, - Attributes: map[string]schema.Attribute{ - "environment": schema.StringAttribute{ - Description: "Environment of the outbound worker.", - Optional: true, - }, - "service": schema.StringAttribute{ - Description: "Name of the outbound worker.", - Optional: true, - }, - }, }, }, }, - "class_name": schema.StringAttribute{ - Description: "The exported class name of the Durable Object.", - Optional: true, - }, - "environment": schema.StringAttribute{ - Description: "The environment of the script_name to bind to.", - Optional: true, - }, - "namespace_id": schema.StringAttribute{ - Description: "Namespace identifier tag.", - Optional: true, - }, - "script_name": schema.StringAttribute{ - Description: "The script where the Durable Object is defined, if it is external to this Worker.", - Optional: true, - }, - "json": schema.StringAttribute{ - Description: "JSON data to use.", - Optional: true, - }, - "certificate_id": schema.StringAttribute{ - Description: "Identifier of the certificate to bind to.", - Optional: true, - }, - "text": schema.StringAttribute{ - Description: "The text value to use.", - Optional: true, - }, - "queue_name": schema.StringAttribute{ - Description: "Name of the Queue to bind to.", - Optional: true, - }, - "bucket_name": schema.StringAttribute{ - Description: "R2 bucket to bind to.", - Optional: true, - }, - "service": schema.StringAttribute{ - Description: "Name of Worker to bind to.", - Optional: true, - }, - "index_name": schema.StringAttribute{ - Description: "Name of the Vectorize index to bind to.", - Optional: true, - }, }, }, + "class_name": schema.StringAttribute{ + Description: "The exported class name of the Durable Object.", + Optional: true, + }, + "environment": schema.StringAttribute{ + Description: "The environment of the script_name to bind to.", + Optional: true, + }, + "namespace_id": schema.StringAttribute{ + Description: "Namespace identifier tag.", + Optional: true, + }, + "script_name": schema.StringAttribute{ + Description: "The script where the Durable Object is defined, if it is external to this Worker.", + Optional: true, + }, + "json": schema.StringAttribute{ + Description: "JSON data to use.", + Optional: true, + }, + "certificate_id": schema.StringAttribute{ + Description: "Identifier of the certificate to bind to.", + Optional: true, + }, + "text": schema.StringAttribute{ + Description: "The text value to use.", + Optional: true, + }, + "queue_name": schema.StringAttribute{ + Description: "Name of the Queue to bind to.", + Optional: true, + }, + "bucket_name": schema.StringAttribute{ + Description: "R2 bucket to bind to.", + Optional: true, + }, + "service": schema.StringAttribute{ + Description: "Name of Worker to bind to.", + Optional: true, + }, + "index_name": schema.StringAttribute{ + Description: "Name of the Vectorize index to bind to.", + Optional: true, + }, }, - "body_part": schema.StringAttribute{ - Description: "Name of the part in the multipart request that contains the script (e.g. the file adding a listener to the `fetch` event). Indicates a `service worker syntax` Worker.", - Optional: true, - }, - "compatibility_date": schema.StringAttribute{ - Description: "Date indicating targeted support in the Workers runtime. Backwards incompatible fixes to the runtime following this date will not affect this Worker.", - Optional: true, - }, - "compatibility_flags": schema.ListAttribute{ - Description: "Flags that enable or disable certain features in the Workers runtime. Used to enable upcoming features or opt in or out of specific changes not included in a `compatibility_date`.", + }, + }, + "body_part": schema.StringAttribute{ + Description: "Name of the part in the multipart request that contains the script (e.g. the file adding a listener to the `fetch` event). Indicates a `service worker syntax` Worker.", + Optional: true, + }, + "compatibility_date": schema.StringAttribute{ + Description: "Date indicating targeted support in the Workers runtime. Backwards incompatible fixes to the runtime following this date will not affect this Worker.", + Optional: true, + }, + "compatibility_flags": schema.ListAttribute{ + Description: "Flags that enable or disable certain features in the Workers runtime. Used to enable upcoming features or opt in or out of specific changes not included in a `compatibility_date`.", + Optional: true, + ElementType: types.StringType, + }, + "keep_assets": schema.BoolAttribute{ + Description: "Retain assets which exist for a previously uploaded Worker version; used in lieu of providing a completion token.", + Optional: true, + }, + "keep_bindings": schema.ListAttribute{ + Description: "List of binding types to keep from previous_upload.", + Optional: true, + ElementType: types.StringType, + }, + "logpush": schema.BoolAttribute{ + Description: "Whether Logpush is turned on for the Worker.", + Optional: true, + }, + "main_module": schema.StringAttribute{ + Description: "Name of the part in the multipart request that contains the main module (e.g. the file exporting a `fetch` handler). Indicates a `module syntax` Worker.", + Optional: true, + }, + "migrations": schema.SingleNestedAttribute{ + Description: "Migrations to apply for Durable Objects associated with this Worker.", + Optional: true, + Computed: true, + CustomType: customfield.NewNestedObjectType[WorkersScriptMetadataMigrationsModel](ctx), + Attributes: map[string]schema.Attribute{ + "deleted_classes": schema.ListAttribute{ + Description: "A list of classes to delete Durable Object namespaces from.", Optional: true, ElementType: types.StringType, }, - "keep_assets": schema.BoolAttribute{ - Description: "Retain assets which exist for a previously uploaded Worker version; used in lieu of providing a completion token.", + "new_classes": schema.ListAttribute{ + Description: "A list of classes to create Durable Object namespaces from.", Optional: true, + ElementType: types.StringType, }, - "keep_bindings": schema.ListAttribute{ - Description: "List of binding types to keep from previous_upload.", + "new_sqlite_classes": schema.ListAttribute{ + Description: "A list of classes to create Durable Object namespaces with SQLite from.", Optional: true, ElementType: types.StringType, }, - "logpush": schema.BoolAttribute{ - Description: "Whether Logpush is turned on for the Worker.", + "new_tag": schema.StringAttribute{ + Description: "Tag to set as the latest migration tag.", Optional: true, }, - "main_module": schema.StringAttribute{ - Description: "Name of the part in the multipart request that contains the main module (e.g. the file exporting a `fetch` handler). Indicates a `module syntax` Worker.", + "old_tag": schema.StringAttribute{ + Description: "Tag used to verify against the latest migration tag for this Worker. If they don't match, the upload is rejected.", Optional: true, }, - "migrations": schema.SingleNestedAttribute{ - Description: "Migrations to apply for Durable Objects associated with this Worker.", + "renamed_classes": schema.ListNestedAttribute{ + Description: "A list of classes with Durable Object namespaces that were renamed.", Optional: true, - Attributes: map[string]schema.Attribute{ - "deleted_classes": schema.ListAttribute{ - Description: "A list of classes to delete Durable Object namespaces from.", - Optional: true, - ElementType: types.StringType, - }, - "new_classes": schema.ListAttribute{ - Description: "A list of classes to create Durable Object namespaces from.", - Optional: true, - ElementType: types.StringType, - }, - "new_sqlite_classes": schema.ListAttribute{ - Description: "A list of classes to create Durable Object namespaces with SQLite from.", - Optional: true, - ElementType: types.StringType, - }, - "new_tag": schema.StringAttribute{ - Description: "Tag to set as the latest migration tag.", - Optional: true, - }, - "old_tag": schema.StringAttribute{ - Description: "Tag used to verify against the latest migration tag for this Worker. If they don't match, the upload is rejected.", - Optional: true, - }, - "renamed_classes": schema.ListNestedAttribute{ - Description: "A list of classes with Durable Object namespaces that were renamed.", - Optional: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "from": schema.StringAttribute{ - Optional: true, - }, - "to": schema.StringAttribute{ - Optional: true, - }, - }, - }, - }, - "transferred_classes": schema.ListNestedAttribute{ - Description: "A list of transfers for Durable Object namespaces from a different Worker and class to a class defined in this Worker.", - Optional: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "from": schema.StringAttribute{ - Optional: true, - }, - "from_script": schema.StringAttribute{ - Optional: true, - }, - "to": schema.StringAttribute{ - Optional: true, - }, - }, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "from": schema.StringAttribute{ + Optional: true, }, - }, - "steps": schema.ListNestedAttribute{ - Description: "Migrations to apply in order.", - Optional: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "deleted_classes": schema.ListAttribute{ - Description: "A list of classes to delete Durable Object namespaces from.", - Optional: true, - ElementType: types.StringType, - }, - "new_classes": schema.ListAttribute{ - Description: "A list of classes to create Durable Object namespaces from.", - Optional: true, - ElementType: types.StringType, - }, - "new_sqlite_classes": schema.ListAttribute{ - Description: "A list of classes to create Durable Object namespaces with SQLite from.", - Optional: true, - ElementType: types.StringType, - }, - "renamed_classes": schema.ListNestedAttribute{ - Description: "A list of classes with Durable Object namespaces that were renamed.", - Optional: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "from": schema.StringAttribute{ - Optional: true, - }, - "to": schema.StringAttribute{ - Optional: true, - }, - }, - }, - }, - "transferred_classes": schema.ListNestedAttribute{ - Description: "A list of transfers for Durable Object namespaces from a different Worker and class to a class defined in this Worker.", - Optional: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "from": schema.StringAttribute{ - Optional: true, - }, - "from_script": schema.StringAttribute{ - Optional: true, - }, - "to": schema.StringAttribute{ - Optional: true, - }, - }, - }, - }, - }, + "to": schema.StringAttribute{ + Optional: true, }, }, }, }, - "observability": schema.SingleNestedAttribute{ - Description: "Observability settings for the Worker.", - Optional: true, - Attributes: map[string]schema.Attribute{ - "enabled": schema.BoolAttribute{ - Description: "Whether observability is enabled for the Worker.", - Required: true, - }, - "head_sampling_rate": schema.Float64Attribute{ - Description: "The sampling rate for incoming requests. From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1.", - Optional: true, - }, - }, - }, - "placement": schema.SingleNestedAttribute{ - Description: "Configuration for [Smart Placement](https://developers.cloudflare.com/workers/configuration/smart-placement).", + "transferred_classes": schema.ListNestedAttribute{ + Description: "A list of transfers for Durable Object namespaces from a different Worker and class to a class defined in this Worker.", Optional: true, - Attributes: map[string]schema.Attribute{ - "mode": schema.StringAttribute{ - Description: "Enables [Smart Placement](https://developers.cloudflare.com/workers/configuration/smart-placement).", - Optional: true, - Validators: []validator.String{ - stringvalidator.OneOfCaseInsensitive( - "auto-trailing-slash", - "force-trailing-slash", - "drop-trailing-slash", - "none", - ), + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "from": schema.StringAttribute{ + Optional: true, }, - }, - "not_found_handling": schema.StringAttribute{ - Description: "Determines the response when a request does not match a static asset, and there is no Worker script.", - Optional: true, - Validators: []validator.String{ - stringvalidator.OneOfCaseInsensitive( - "none", - "404-page", - "single-page-application", - ), + "from_script": schema.StringAttribute{ + Optional: true, }, - }, - "serve_directly": schema.BoolAttribute{ - Description: "When true and the incoming request matches an asset, that will be served instead of invoking the Worker script. When false, requests will always invoke the Worker script.", - Computed: true, - Optional: true, - Default: booldefault.StaticBool(true), - }, - "status": schema.StringAttribute{ - Description: "Status of [Smart Placement](https://developers.cloudflare.com/workers/configuration/smart-placement).", - Computed: true, - Validators: []validator.String{ - stringvalidator.OneOfCaseInsensitive( - "SUCCESS", - "NO_VALID_HOSTS", - "NO_VALID_BINDINGS", - "UNSUPPORTED_APPLICATION", - "INSUFFICIENT_INVOCATIONS", - "INSUFFICIENT_SUBREQUESTS", - ), + "to": schema.StringAttribute{ + Optional: true, }, }, }, }, - "jwt": schema.StringAttribute{ - Description: "Token provided upon successful upload of all files from a registered manifest.", - Optional: true, - ElementType: types.StringType, - }, - "tail_consumers": schema.ListNestedAttribute{ - Description: "List of Workers that will consume logs from the attached Worker.", + "steps": schema.ListNestedAttribute{ + Description: "Migrations to apply in order.", Optional: true, NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ - "service": schema.StringAttribute{ - Description: "Name of Worker that is to be the consumer.", - Required: true, + "deleted_classes": schema.ListAttribute{ + Description: "A list of classes to delete Durable Object namespaces from.", + Optional: true, + ElementType: types.StringType, }, - "environment": schema.StringAttribute{ - Description: "Optional environment if the Worker utilizes one.", + "new_classes": schema.ListAttribute{ + Description: "A list of classes to create Durable Object namespaces from.", Optional: true, + ElementType: types.StringType, }, - "namespace": schema.StringAttribute{ - Description: "Optional dispatch namespace the script belongs to.", + "new_sqlite_classes": schema.ListAttribute{ + Description: "A list of classes to create Durable Object namespaces with SQLite from.", Optional: true, + ElementType: types.StringType, + }, + "renamed_classes": schema.ListNestedAttribute{ + Description: "A list of classes with Durable Object namespaces that were renamed.", + Optional: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "from": schema.StringAttribute{ + Optional: true, + }, + "to": schema.StringAttribute{ + Optional: true, + }, + }, + }, + }, + "transferred_classes": schema.ListNestedAttribute{ + Description: "A list of transfers for Durable Object namespaces from a different Worker and class to a class defined in this Worker.", + Optional: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "from": schema.StringAttribute{ + Optional: true, + }, + "from_script": schema.StringAttribute{ + Optional: true, + }, + "to": schema.StringAttribute{ + Optional: true, + }, + }, + }, }, }, }, }, - "usage_model": schema.StringAttribute{ - Description: "Usage model for the Worker invocations.", + }, + }, + "observability": schema.SingleNestedAttribute{ + Description: "Observability settings for the Worker.", + Optional: true, + Computed: true, + CustomType: customfield.NewNestedObjectType[WorkersScriptMetadataObservabilityModel](ctx), + Attributes: map[string]schema.Attribute{ + "enabled": schema.BoolAttribute{ + Description: "Whether observability is enabled for the Worker.", + Required: true, + }, + "head_sampling_rate": schema.Float64Attribute{ + Description: "The sampling rate for incoming requests. From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1.", + Optional: true, + }, + }, + }, + "placement": schema.SingleNestedAttribute{ + Description: "Configuration for [Smart Placement](https://developers.cloudflare.com/workers/configuration/smart-placement).", + Optional: true, + Computed: true, + CustomType: customfield.NewNestedObjectType[WorkersScriptMetadataPlacementModel](ctx), + Attributes: map[string]schema.Attribute{ + "mode": schema.StringAttribute{ + Description: "Enables [Smart Placement](https://developers.cloudflare.com/workers/configuration/smart-placement).", Optional: true, Validators: []validator.String{ - stringvalidator.OneOfCaseInsensitive("standard"), + stringvalidator.OneOfCaseInsensitive( + "smart", + ), }, }, + "status": schema.StringAttribute{ + Description: "Status of [Smart Placement](https://developers.cloudflare.com/workers/configuration/smart-placement).", + Computed: true, + Validators: []validator.String{ + stringvalidator.OneOfCaseInsensitive( + "SUCCESS", + "NO_VALID_HOSTS", + "NO_VALID_BINDINGS", + "UNSUPPORTED_APPLICATION", + "INSUFFICIENT_INVOCATIONS", + "INSUFFICIENT_SUBREQUESTS", + ), + }, + }, + }, + }, + "tail_consumers": schema.ListNestedAttribute{ + Description: "List of Workers that will consume logs from the attached Worker.", + Optional: true, + Computed: true, + CustomType: customfield.NewNestedObjectListType[WorkersScriptMetadataTailConsumersModel](ctx), + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "service": schema.StringAttribute{ + Description: "Name of Worker that is to be the consumer.", + Required: true, + }, + "environment": schema.StringAttribute{ + Description: "Optional environment if the Worker utilizes one.", + Optional: true, + }, + "namespace": schema.StringAttribute{ + Description: "Optional dispatch namespace the script belongs to.", + Optional: true, + }, + }, + }, + }, + "usage_model": schema.StringAttribute{ + Description: "Usage model for the Worker invocations.", + Optional: true, + Validators: []validator.String{ + stringvalidator.OneOfCaseInsensitive("standard"), }, }, }, diff --git a/internal/services/workers_script/testdata/module.tf b/internal/services/workers_script/testdata/module.tf index 1514f47081..216a6a8bf3 100644 --- a/internal/services/workers_script/testdata/module.tf +++ b/internal/services/workers_script/testdata/module.tf @@ -1,18 +1,12 @@ -# resource "cloudflare_r2_bucket" "%[1]s" { -# account_id = "%[3]s" -# name = "%[1]s" -# location = "apac" -# storage_class = "Standard" -# } +resource "cloudflare_workers_kv_namespace" "%[1]s" { + account_id = "%[3]s" + title = "%[1]s" +} -# resource "cloudflare_logpush_job" "%[1]s" { -# enabled = true -# account_id = "%[3]s" -# name = "%[1]s" -# logpull_options = "fields=Event,EventTimestampMs,Outcome,Exceptions,Logs,ScriptName" -# destination_conf = "r2://${cloudflare_r2_bucket.%[1]s.name}/date={DATE}?account-id=%[3]s&access-key-id=%[6]s&secret-access-key=%[7]s" -# dataset = "workers_trace_events" -# } +resource "cloudflare_queue" "%[1]s" { + account_id = "%[3]s" + queue_name = "%[1]s" +} resource "cloudflare_workers_script" "%[1]s" { account_id = "%[3]s" @@ -24,4 +18,16 @@ resource "cloudflare_workers_script" "%[1]s" { placement = { mode = "smart" } + bindings = [ + { + name = "MY_KV_NAMESPACE" + type = "kv_namespace" + namespace_id = cloudflare_workers_kv_namespace.%[1]s.id + }, + { + name = "MY_QUEUE" + type = "queue" + queue_name = cloudflare_queue.%[1]s.queue_name + } + ] } diff --git a/internal/services/workers_script/testdata/service_worker_update_binding.tf b/internal/services/workers_script/testdata/service_worker_update_binding.tf index 6e0d5e8887..c69c536a94 100644 --- a/internal/services/workers_script/testdata/service_worker_update_binding.tf +++ b/internal/services/workers_script/testdata/service_worker_update_binding.tf @@ -1,59 +1,28 @@ +resource "cloudflare_workers_kv_namespace" "%[1]s" { + account_id = "%[4]s" + title = "%[1]s" +} -# resource "cloudflare_workers_kv_namespace" "%[1]s" { -# account_id = "%[4]s" -# title = "%[1]s" -# } - -# resource "cloudflare_queue" "%[1]s" { -# account_id = "%[4]s" -# name = "%[1]s" -# } - -# resource "cloudflare_workers_script" "%[1]s-service" { -# account_id = "%[4]s" -# script_name = "%[1]s-service" -# any_part_name = ["%[2]s"] -# } +resource "cloudflare_queue" "%[1]s" { + account_id = "%[4]s" + queue_name = "%[1]s" +} resource "cloudflare_workers_script" "%[1]s" { account_id = "%[4]s" script_name = "%[1]s" content = "%[2]s" - # kv_namespace_binding =[ { - # name = "MY_KV_NAMESPACE" - # namespace_id = cloudflare_workers_kv_namespace.%[1]s.id - # } - - # plain_text_binding { - # name = "MY_PLAIN_TEXT" - # text = "%[1]s" - # }] - - # secret_text_binding =[ { - # name = "MY_SECRET_TEXT" - # text = "%[1]s" - # }] - - # webassembly_binding =[ { - # name = "MY_WASM" - # module = "%[3]s" - # }] - - # r2_bucket_binding =[ { - # name = "MY_BUCKET" - # bucket_name = "%[1]s" - # }] - - # service_binding =[ { - # name = "MY_SERVICE_BINDING" - # service = cloudflare_workers_script.%[1]s-service.name - # environment = "production" - # } - - # queue_binding =[ { - # binding = "MY_QUEUE" - # queue = cloudflare_queue.%[1]s.name - # } - # }] + bindings = [ + { + name = "MY_KV_NAMESPACE" + type = "kv_namespace" + namespace_id = cloudflare_workers_kv_namespace.%[1]s.id + }, + { + name = "MY_QUEUE" + type = "queue" + queue_name = cloudflare_queue.%[1]s.queue_name + } + ] }