Files
pulumi-dokploy/provider/resources.go
Max Vojtkov bb3c15135b Bridge terraform-provider-dokploy into a Pulumi provider
18 resources and 5 data sources mapped into the dokploy:index module, with
SDKs generated for TypeScript, Python, Go and .NET.
2026-08-08 15:28:16 +03:00

166 lines
5.4 KiB
Go

// Package dokploy bridges the Dokploy Terraform provider into a Pulumi
// provider. The Terraform provider itself lives in
// github.com/maxvojtkov/terraform-provider-dokploy; everything in this file is
// mapping — Terraform type names to Pulumi tokens, and Terraform provider
// configuration to Pulumi configuration.
package dokploy
import (
_ "embed"
pfbridge "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfbridge"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"
tfshim "github.com/maxvojtkov/terraform-provider-dokploy/shim"
)
// bridgeMetadata carries auto-aliasing state between tfgen runs so that token
// renames stay backwards compatible. tfgen rewrites it; the checked-in `{}`
// placeholder keeps the package compiling before the first generation.
//
//go:embed cmd/pulumi-resource-dokploy/bridge-metadata.json
var bridgeMetadata []byte
// mainPkg is the single module every resource and data source lands in, giving
// tokens of the form `dokploy:index:Project`.
const mainPkg = "index"
func res(name string) *tfbridge.ResourceInfo {
return &tfbridge.ResourceInfo{Tok: tfbridge.MakeResource("dokploy", mainPkg, name)}
}
func ds(name string) *tfbridge.DataSourceInfo {
return &tfbridge.DataSourceInfo{Tok: tfbridge.MakeDataSource("dokploy", mainPkg, name)}
}
// Provider returns the bridged Pulumi provider definition for Dokploy.
func Provider(version string) tfbridge.ProviderInfo {
if version == "" {
version = "0.0.0-dev"
}
prov := tfbridge.ProviderInfo{
P: pfbridge.ShimProvider(tfshim.NewProvider(version)),
Name: "dokploy",
DisplayName: "Dokploy",
Publisher: "maxvojtkov",
Description: "A Pulumi package for creating and managing Dokploy resources",
Keywords: []string{
"pulumi", "dokploy", "paas", "docker", "deployment",
"category/cloud", "category/infrastructure",
},
License: "MPL-2.0",
Homepage: "https://github.com/maxvojtkov/pulumi-dokploy",
Repository: "https://github.com/maxvojtkov/pulumi-dokploy",
GitHubOrg: "maxvojtkov",
Version: version,
// This is not a Pulumi-published provider, so the plugin binary is
// resolved from GitHub releases rather than the Pulumi CDN.
PluginDownloadURL: "github://api.github.com/maxvojtkov/pulumi-dokploy",
TFProviderVersion: version,
MetadataInfo: tfbridge.NewProviderMetadata(bridgeMetadata),
// The upstream provider is plugin-framework based, so opt in to the
// bridge's accurate preview and raw state handling.
EnableAccurateBridgePreview: true,
EnableAccuratePFBridgePreview: true,
EnableRawStateDelta: true,
Config: map[string]*tfbridge.SchemaInfo{
"host": {
Default: &tfbridge.DefaultInfo{EnvVars: []string{"DOKPLOY_HOST"}},
},
"api_key": {
Secret: tfbridge.True(),
Default: &tfbridge.DefaultInfo{EnvVars: []string{"DOKPLOY_API_KEY"}},
},
"timeout_seconds": {
Default: &tfbridge.DefaultInfo{EnvVars: []string{"DOKPLOY_TIMEOUT_SECONDS"}},
},
},
Resources: map[string]*tfbridge.ResourceInfo{
// Core hierarchy.
"dokploy_project": res("Project"),
"dokploy_environment": res("Environment"),
"dokploy_application": res("Application"),
"dokploy_compose": res("Compose"),
// Databases.
"dokploy_postgres": res("Postgres"),
"dokploy_mysql": res("MySql"),
"dokploy_mariadb": res("MariaDb"),
"dokploy_mongo": res("Mongo"),
"dokploy_redis": res("Redis"),
// Networking and service attachments.
"dokploy_domain": res("Domain"),
"dokploy_mount": res("Mount"),
"dokploy_port": res("Port"),
"dokploy_redirect": res("Redirect"),
"dokploy_security": res("Security"),
// Account-level settings.
"dokploy_registry": res("Registry"),
"dokploy_ssh_key": res("SshKey"),
"dokploy_certificate": res("Certificate"),
"dokploy_destination": res("Destination"),
},
DataSources: map[string]*tfbridge.DataSourceInfo{
"dokploy_project": ds("getProject"),
"dokploy_projects": ds("getProjects"),
"dokploy_environment": ds("getEnvironment"),
"dokploy_application": ds("getApplication"),
"dokploy_servers": ds("getServers"),
},
JavaScript: &tfbridge.JavaScriptInfo{
PackageName: "@maxvojtkov/pulumi-dokploy",
Dependencies: map[string]string{"@pulumi/pulumi": "^3.0.0"},
DevDependencies: map[string]string{"@types/node": "^18", "typescript": "^4.6.0"},
RespectSchemaVersion: true,
},
Python: pythonInfo(),
Golang: &tfbridge.GolangInfo{
ImportBasePath: "github.com/maxvojtkov/pulumi-dokploy/sdk/go/dokploy",
GenerateResourceContainerTypes: true,
RespectSchemaVersion: true,
},
CSharp: &tfbridge.CSharpInfo{
RootNamespace: "Maxvojtkov",
PackageReferences: map[string]string{"Pulumi": "3.*"},
RespectSchemaVersion: true,
},
}
// Every Dokploy resource carries a user-visible `name`; let Pulumi
// auto-generate one when the program does not supply it.
prov.SetAutonaming(255, "-")
// Keeps tokens stable if a future release renames or re-modules anything.
if err := prov.ApplyAutoAliases(); err != nil {
panic(err)
}
return prov
}
// pythonInfo exists because PyProject is an anonymous struct field and cannot
// be set inside a composite literal.
func pythonInfo() *tfbridge.PythonInfo {
info := &tfbridge.PythonInfo{
PackageName: "pulumi_dokploy",
Requires: map[string]string{"pulumi": ">=3.0.0,<4.0.0"},
RespectSchemaVersion: true,
}
info.PyProject.Enabled = true
return info
}