{"modulePath":"github.com/GoCodeAlone/workflow-plugin-digitalocean","version":"v1.4.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package internal\n\nPackage internal — typed pb.IaCProvider\\*Server implementation.\n\nPer the strict-contracts force-cutover plan (Task 9): docs/plans/2026-05-10-strict-contracts-force-cutover.md, rev5.\n\ndoIaCServer is the SERVER side of the typed IaC contract. It satisfies pb.IaCProviderRequiredServer plus the six optional pb.IaCProvider\\*Server interfaces by delegating each typed RPC to the matching Go-interface method on the underlying \\*DOProvider. Marshalling between pb messages and the Go interfaces.\\* types lives in marshalling helpers below; the shape mirrors the inverse direction implemented by cmd/wfctl/iac\\_typed\\_adapter.go in workflow itself, so a single canonical pb\\\u003c-\u003eGo mapping holds across both ends of the gRPC bridge.\n\nHard invariants (per cycle 4 force-cutover §Acceptance):\n\n  - NO structpb.Struct, NO Any.UnmarshalTo on the wire — provider- specific config / outputs cross as JSON bytes (config\\_json, outputs\\_json).\n  - REQUIRED service methods MUST be implemented; the SDK type-assert in sdk.RegisterAllIaCProviderServices fails at plugin startup otherwise.\n  - OPTIONAL services are auto-registered when satisfied at the Go interface level — no manual Register\\* call required.\n\nPackage internal — typed pb.ResourceDriverServer implementation (Task 11 of the strict-contracts force-cutover plan, docs/plans/2026-05-10-strict-contracts-force-cutover.md, rev5).\n\nThe pb.ResourceDriverServer surface is a single gRPC service that dispatches per-resource-type CRUD by carrying resource\\_type on every RPC. This file extends \\*doIaCServer (declared in iacserver.go) with the 9 RPC methods Required by the interface; routing happens by looking up the per-type interfaces.ResourceDriver via \\*DOProvider.ResourceDriver(resourceType) and forwarding the call.\n\nOnce \\*doIaCServer satisfies pb.ResourceDriverServer at the Go type level, sdk.RegisterAllIaCProviderServices auto-registers it (iacserver.go: type-assertion gate). No manual Register\\* call needed.\n\nPackage internal — typed pb.IaCStateBackendServer implementation.\n\nPer decisions/0035 (one type carries both concerns), doIaCServer ALSO serves the typed IaC state-backend contract: it persists IaC state via a SpacesIaCStateStore (ported from workflow core) and answers ListBackendNames with the single backend name \"spaces\".\n\nHard invariants (strict-contracts force-cutover):\n\n  - NO structpb.Struct on the wire — the free-form Outputs / Config map\\[string]any fields of IaCState cross as JSON bytes (outputs\\_json, config\\_json), converted locally via encoding/json below.\n  - The store is lazily constructed: the host delivers the iac.state module config via the Configure RPC (decisions/0036); until then GetState/etc. return a clear FailedPrecondition error rather than panicking.\n\n## Constants\n\n```go\nconst (\n\n\t// EnvDebugAPI is the environment variable that enables API call logging.\n\t// Set to any non-empty value (e.g. WFCTL_DEBUG_API=1) to activate.\n\tEnvDebugAPI = \"WFCTL_DEBUG_API\"\n)\n```\n\n## Variables\n\n```go\nvar ErrApplyV1Removed = errors.New(\"DOProvider.Apply: v1 dispatch removed since DO v1.4.0 (workflow#695 Phase 2.5 + Phase 3); upgrade wfctl to v0.55.0+ for v2 dispatch via wfctlhelpers.ApplyPlanWithHooks + IaCProviderFinalizer.FinalizeApply\")\n```\nErrApplyV1Removed is the sentinel returned by DOProvider.Apply when called post-Phase-3 cleanup. Callers can errors.Is for diagnostic classification.\n\n```go\nvar Version = \"dev\"\n```\nVersion is set at build time via -ldflags \"-X github.com/GoCodeAlone/workflow-plugin-digitalocean/internal.Version=X.Y.Z\". Lived in plugin.go before the strict-contracts cutover; moved here when the legacy doPlugin / NewDOPlugin entrypoint was deleted (Task 9).\n\n## Functions\n\n```go\nfunc NewIaCServer() *doIaCServer\n```\nNewIaCServer is the package entrypoint used by cmd/plugin/main.go. It constructs a fresh \\*DOProvider and wraps it in the typed pb.IaCProvider\\* server surface. The returned value is suitable to pass to sdk.ServeIaCPlugin; the SDK auto-registers every typed gRPC service the server satisfies via Go type-assertion at plugin startup.\n\n## Types\n\n```go\ntype DOProvider struct {\n\t// contains filtered or unexported fields\n}\n```\nDOProvider implements interfaces.IaCProvider for DigitalOcean.\n\n```go\nfunc NewDOProvider() *DOProvider\n```\nNewDOProvider creates an uninitialised DOProvider.\n\n```go\nfunc (p *DOProvider) Apply(_ context.Context, _ *interfaces.IaCPlan) (*interfaces.ApplyResult, error)\n```\nApply returns ErrApplyV1Removed unconditionally. v1 dispatch was removed in DO v1.4.0 (workflow#695 Phase 3 cleanup). wfctl bypasses this method when ComputePlanVersion=\"v2\" is declared in Capabilities; deferred-flush behavior moved to doIaCServer.FinalizeApply via IaCProviderFinalizer RPC. Reaching this method indicates a misconfigured caller (in-process embedder using a pre-Phase-2.5 wfctl tag, OR gRPC consumer that opted out of v2 dispatch). Stub preserves interfaces.IaCProvider contract per ADR 0024; interface segregation deferred to separate refactor design.\n\n```go\nfunc (p *DOProvider) AppsClient() steps.IaCLogsClient\n```\nAppsClient returns the godo Apps service for use by pipeline steps. Returns nil when the provider has not yet been initialized (Initialize not called).\n\n```go\nfunc (p *DOProvider) AppsScaleClient() steps.AppsScaleClient\n```\nAppsScaleClient returns the godo Apps service as steps.AppsScaleClient for use by step.iac\\_scale. Returns nil when Initialize has not been called.\n\n```go\nfunc (p *DOProvider) BootstrapStateBackend(ctx context.Context, cfg map[string]any) (*interfaces.BootstrapResult, error)\n```\nBootstrapStateBackend ensures the DO Spaces state bucket exists. It is idempotent: if the bucket already exists it returns the metadata without error. Providers that do not manage a state backend should return (nil, nil).\n\nRequired cfg keys: \"bucket\", and credentials supplied as either camelCase (\"accessKey\"/\"secretKey\", e.g. BMW infra.yaml) or snake\\_case (\"access\\_key\"/\"secret\\_key\"); camelCase is checked first. Optional cfg keys: \"region\" (falls back to the provider's configured region, then \"nyc3\" as the ultimate default).\n\nReturns a BootstrapResult with:\n\n  - Bucket, Region, Endpoint fields populated\n  - EnvVars: WFCTL\\_STATE\\_BUCKET and SPACES\\_BUCKET set to the bucket name\n\n```go\nfunc (p *DOProvider) Capabilities() []interfaces.IaCCapabilityDeclaration\n```\nCapabilities returns the resource types this provider supports.\n\n```go\nfunc (p *DOProvider) Close() error\n```\nClose is a no-op; the godo client has no persistent connection to close.\n\n```go\nfunc (p *DOProvider) Destroy(ctx context.Context, resources []interfaces.ResourceRef) (*interfaces.DestroyResult, error)\n```\nDestroy deletes the given resources.\n\n```go\nfunc (p *DOProvider) DetectDrift(ctx context.Context, resources []interfaces.ResourceRef) ([]interfaces.DriftResult, error)\n```\nDetectDrift checks for ghost resources (state entries whose cloud counterpart no longer exists) and classifies each ref as Ghost, InSync, or Unknown.\n\n  - errors.Is(err, interfaces.ErrResourceNotFound) → DriftClassGhost (Drifted=true; state has the resource but cloud returns 404). Caller may prune state via wfctl infra apply --refresh.\n  - any other Read error → propagate (transient API failure; do NOT classify as drift).\n  - Read succeeds → DriftClassInSync (Drifted=false).\n  - driver registry lookup fails → DriftClassUnknown (Drifted=true; operator must investigate).\n\nConfig-drift detection (DriftClassConfig) requires the desired spec and is available via DetectDriftWithSpecs, which is called by invokeProviderDetectDrift when the workflow caller injects specs from state's recorded outputs.\n\nProduction-safety invariant: only genuine 404s (wrapped with interfaces.ErrResourceNotFound) trigger the ghost path. Rate-limit, auth, or network errors propagate unchanged so callers cannot accidentally prune state on transient failures.\n\n```go\nfunc (p *DOProvider) DetectDriftWithSpecs(ctx context.Context, resources []interfaces.ResourceRef, specs map[string]interfaces.ResourceSpec) ([]interfaces.DriftResult, error)\n```\nDetectDriftWithSpecs is the spec-injection variant of DetectDrift. It runs the same ghost/transient/unknown classification as DetectDrift, and when the caller supplies a desired ResourceSpec for a ref (keyed by ref.Name), it additionally calls driver.Diff to detect config-level drift (DriftClassConfig).\n\nClassification rules (per ref):\n\n  - driver lookup fails → DriftClassUnknown (Drifted=true).\n  - Read returns ErrResourceNotFound → DriftClassGhost (Drifted=true); spec is ignored because the resource does not exist in the cloud.\n  - Read returns any other error → propagate; discard accumulated results.\n  - Read succeeds and no spec provided → DriftClassInSync (Drifted=false).\n  - Read succeeds and spec provided:\n  - Diff error → propagate; discard accumulated results.\n  - Diff reports NeedsUpdate → DriftClassConfig (Drifted=true); Fields lists the changed config paths.\n  - Diff reports no changes → DriftClassInSync (Drifted=false).\n\nA nil or empty specs map is equivalent to calling DetectDrift.\n\n```go\nfunc (p *DOProvider) EnumerateAll(ctx context.Context, resourceType string) ([]*interfaces.ResourceOutput, error)\n```\nEnumerateAll lists every resource of resourceType in the DO account, regardless of tag. Used for resource types that don't support tags (e.g. spaces\\_key, where the DO API has no tag surface). Paginates transparently using godo.Response.Links so callers don't have to.\n\nReturns \\[]\\*ResourceOutput per the workflow EnumeratorAll contract (interfaces/iac\\_provider.go) — full metadata is populated so downstream callers (wfctl infra audit-keys, prune, rotate-and-prune) can filter without re-reading each resource individually.\n\nImplements interfaces.EnumeratorAll (workflow v0.26.0+; opt-in interface, type-asserted by the host's IaCProvider proxy).\n\n```go\nfunc (p *DOProvider) EnumerateByTag(ctx context.Context, tag string) ([]interfaces.ResourceRef, error)\n```\nEnumerateByTag implements the opt-in interfaces.Enumerator interface.\n\nLists DO resources tagged with the given tag and returns them as interfaces.ResourceRef values keyed on the same (Name, Type, ProviderID) tuple that the corresponding ResourceDriver(type).Delete consumes. Used by \\`wfctl infra cleanup --tag \\\u003cname\u003e\\` to drive tag-scoped teardown.\n\nImplementation strategy:\n\n  - Tags.Get is queried first as a probe: if the tag itself does not exist in the DO account (404), the result is an empty slice (not an error). This matches operator expectation that running cleanup against a tag that has never been used reports \"no resources\" rather than failing. A 200 here indicates the tag is known to DO, but the per-resource queries below are what actually populate the result slice — Tags.Get's own response only carries counts + last-tagged metadata, not a full list of tagged resources.\n  - Droplets uses the native ListByTag endpoint.\n  - Volumes and Databases do not expose a tag-filter parameter, so the full list is fetched and filtered client-side on the Tags slice.\n  - Other DO resource types (load balancers, k8s clusters, app platform, etc.) either do not support tags or have not yet been wired here. The cleanup subcommand documents per-provider coverage in workflow/docs/WFCTL.md \\`#### infra cleanup\\`.\n\nThe contract for the returned ResourceRef.ProviderID matches what each ResourceDriver expects on Delete: a string-formatted droplet ID for droplets, the volume ID for volumes, and the database cluster UUID for databases. Name is the user-facing resource name. Type is the canonical \\`infra.\\\u003ckind\u003e\\` matching DOProvider's driver registration.\n\n```go\nfunc (p *DOProvider) Import(ctx context.Context, cloudID string, resourceType string) (*interfaces.ResourceState, error)\n```\nImport brings an existing cloud resource under management.\n\n```go\nfunc (p *DOProvider) Initialize(ctx context.Context, config map[string]any) error\n```\nInitialize configures the godo client using the provided config map. Required: \"token\". Optional: \"region\" (default \"nyc3\"), \"spaces\\_access\\_key\", \"spaces\\_secret\\_key\".\n\nThe provided ctx is threaded into oauth2.NewClient so callers that inject a custom \\*http.Client via oauth2.HTTPClient (tests, custom transports, proxy configurations) flow through to the godo client. Per-request cancellation remains controlled by the ctx passed to each subsequent driver call — godo wraps each request in ctx via http.Request.WithContext.\n\naddresses workflow-plugin-digitalocean#62: prior implementation hardcoded context.Background(), silently dropping any HTTPClient injection.\n\n```go\nfunc (p *DOProvider) Name() string\n```\n\n```go\nfunc (p *DOProvider) Plan(ctx context.Context, desired []interfaces.ResourceSpec, current []interfaces.ResourceState) (*interfaces.IaCPlan, error)\n```\nPlan computes the set of actions needed to reach the desired state by delegating to the canonical platform.ComputePlan helper. The helper dispatches per-resource Diff in parallel, classifies replace vs update (including the ForceNew → replace promotion), emits creates/deletes in dependency-correct order, and consults the diff cache.\n\nThe 2-statement form (call + pointer-bridge return) is mandated by the W-Refactor / iac-codemod analyzer (cmd/iac-codemod AssertPlanDelegatesToHelper); see workflow CHANGELOG entry referencing platform.ComputePlan as the canonical target for v2 IaC providers.\n\naddresses workflow-plugin-digitalocean#63: the prior hand-rolled body duplicated ComputePlan's classification logic and silently dropped the ForceNew → replace upgrade path (only NeedsReplace was honored).\n\n```go\nfunc (p *DOProvider) RepairDirtyMigration(ctx context.Context, req interfaces.MigrationRepairRequest) (*interfaces.MigrationRepairResult, error)\n```\n\n```go\nfunc (p *DOProvider) ResolveSizing(resourceType string, size interfaces.Size, hints *interfaces.ResourceHints) (*interfaces.ProviderSizing, error)\n```\nResolveSizing maps abstract size tiers to DigitalOcean SKUs.\n\n```go\nfunc (p *DOProvider) ResourceDriver(resourceType string) (interfaces.ResourceDriver, error)\n```\nResourceDriver returns the driver for the given resource type.\n\n```go\nfunc (p *DOProvider) RevokeProviderCredential(ctx context.Context, source string, credentialID string) error\n```\nRevokeProviderCredential satisfies interfaces.ProviderCredentialRevoker for source \"digitalocean.spaces\". credentialID is the access\\_key\\_id of the OLD DO Spaces key to revoke. Used by \\`wfctl infra bootstrap --force-rotate\\` to invalidate the old key after minting its replacement (see ADR 0012).\n\nHTTP response handling:\n\n  - 204 No Content → success\n  - 404 Not Found  → treated as success (key already gone)\n  - 401/403        → auth error, propagated as fatal\n  - 5xx            → transient error, propagated to caller (caller logs + continues)\n\n```go\nfunc (p *DOProvider) Status(ctx context.Context, resources []interfaces.ResourceRef) ([]interfaces.ResourceStatus, error)\n```\nStatus returns the live status of the given resources.\n\n```go\nfunc (p *DOProvider) SupportedCanonicalKeys() []string\n```\nSupportedCanonicalKeys returns the canonical IaC config keys that this DO provider currently maps. Keys in doUnsupportedCanonicalKeys are excluded until their Task implementation lands (see comments there).\n\n```go\nfunc (p *DOProvider) ValidatePlan(plan *interfaces.IaCPlan) []interfaces.PlanDiagnostic\n```\nValidatePlan implements interfaces.ProviderValidator (W-4): a read-only, no-remote-call cross-resource constraint check that runs at \\`wfctl infra align\\` time before any cloud API call. Diagnostics surface as PlanDiagnosticError|Warning|Info with severity-driven exit-code mapping (Error always fails align; Warning fails only under --strict; Info never affects exit).\n\nPR P-DO TP3 — first DO region-constraint pass:\n\n 1. App Platform \\`infra.container\\_service\\` MUST use one of DO App Platform's supported region GROUPS (nyc, ams, fra, sfo, sgp, syd, tor, blr, lon). If \\`region\\` is set to a Droplet/VPC zone slug (nyc1, nyc3, sfo2, sfo3 …) it is rejected — App Platform configures by group, not zone.\n\n 2. Droplet/VPC/Volume zone-bound resources MUST use a zone slug (nyc1, nyc2, nyc3, sfo2, sfo3, ams2, ams3, fra1, sgp1, lon1, tor1, blr1, syd1) — bare group slugs (nyc, sfo) are rejected for these types because the DO API for these resources requires a specific zone.\n\n 3. App Platform with \\`vpc\\_ref\\` (referencing a VPC by name in the same plan) — the referenced VPC's region zone MUST belong to the App Platform's region group (e.g., AppPlatform region nyc → VPC in nyc1 OR nyc3; AppPlatform region sfo → VPC in sfo2 OR sfo3). Mismatch is the recurring \"App Platform in nyc cannot reach VPC in sfo3\" production bug (root-cause issue D from the conformance design).\n\nFuture extensions (deferred follow-ups): database/cache zone slugs, load balancer zone matching against attached droplets, registry regional restrictions.\n\n```go\nfunc (p *DOProvider) Version() string\n```\n\n","path":"github.com/GoCodeAlone/workflow-plugin-digitalocean/internal","name":"internal","synopsis":"Package internal — typed pb.IaCProvider*Server implementation.","isRedistributable":true}
