A Terraform provider for Dokploy
Plugin-framework provider covering projects, environments, applications, Compose stacks, managed databases, domains, mounts, ports, redirects, basic auth, registries, SSH keys, certificates and backup destinations, over Dokploy's tRPC-over-REST API. The shim package exposes the provider to other Go modules, which is how pulumi-dokploy bridges it.
This commit is contained in:
49
internal/provider/resource_environment.go
Normal file
49
internal/provider/resource_environment.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type environmentModel struct {
|
||||
ID types.String `tfsdk:"id" dokploy:"environmentId,id"`
|
||||
Name types.String `tfsdk:"name" dokploy:"name"`
|
||||
// Not `nullable`: environment.create and environment.update are hand-written
|
||||
// Zod objects where description is `.optional()` but not `.nullable()`, so
|
||||
// an explicit null is rejected and the key must simply be omitted.
|
||||
Description types.String `tfsdk:"description" dokploy:"description"`
|
||||
ProjectID types.String `tfsdk:"project_id" dokploy:"projectId"`
|
||||
Env types.String `tfsdk:"env" dokploy:"env,update"`
|
||||
IsDefault types.Bool `tfsdk:"is_default" dokploy:"isDefault,ro"`
|
||||
CreatedAt types.String `tfsdk:"created_at" dokploy:"createdAt,ro"`
|
||||
}
|
||||
|
||||
func environmentResource() ResourceSpec {
|
||||
return ResourceSpec{
|
||||
Name: "environment",
|
||||
CreateProc: "environment.create",
|
||||
ReadProc: "environment.one",
|
||||
UpdateProc: "environment.update",
|
||||
DeleteProc: "environment.remove",
|
||||
NewModel: func() any { return &environmentModel{} },
|
||||
// `environment.create` accepts only name, description and projectId,
|
||||
// so `env` has to be written through a follow-up update.
|
||||
UpdateAfterCreate: true,
|
||||
Schema: schema.Schema{
|
||||
MarkdownDescription: "An environment inside a Dokploy project, such as `staging` or `production`. " +
|
||||
"Services belong to an environment rather than directly to a project.\n\n" +
|
||||
"Dokploy creates a default `production` environment with every project; reference it via " +
|
||||
"`dokploy_project.<name>.default_environment_id` instead of declaring it here.",
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"id": computedID("Unique environment identifier."),
|
||||
"name": requiredString("Environment name, for example `staging`."),
|
||||
"description": optionalString("Free-form description."),
|
||||
"project_id": requiredReplaceString("Project this environment belongs to."),
|
||||
"env": optionalComputedString("Environment-wide variables in `KEY=value` format, one per line. " +
|
||||
"These are merged into every service in this environment."),
|
||||
"is_default": computedBool("Whether this is the project's default environment."),
|
||||
"created_at": computedString("RFC 3339 timestamp of when the environment was created."),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user