refactor: replace custom HTTP client with Go SDK#4
Conversation
Replace the Terraform provider's custom HTTP client layer (client.go, client_typed.go) and oapi-codegen generated client (internal/phalaapi/) with the Phala Cloud Go SDK. This eliminates ~37k lines of duplicated API client code and ensures both projects evolve together. Key changes: - All API calls now use phala.Client methods (ProvisionCVM, GetCVMInfo, PatchCVM, DeleteCVM, etc.) instead of raw PostJSON/GetJSON/PatchJSON - cvmAPIResponse replaced with phala.CVMInfo from SDK - authMeResponse replaced with phala.CurrentUser from SDK - Data sources use typed SDK responses (AvailableNodes, CVMAttestation) - Removed oapi-codegen dependency and OpenAPI specs - Bumped Go version to 1.25.0 - Added local replace directive for Go SDK (dev only)
…gration Enhance Go SDK types to support Terraform provider's needs and update the terraform submodule to use the Go SDK instead of its custom HTTP client layer. Go SDK changes: - CVMInfo: add InProgress, Endpoints, PublicURLs, DiskSize, EncryptedEnvPubkey - SSHKey: add Fingerprint, KeyType, Source, UpdatedAt - UserInfo/CreditsInfo: use pointer types for nullable field handling - ProvisionCVMRequest: add SSHAuthorizedKeys, CustomAppID, Nonce, StorageFS - CommitCVMProvisionRequest: add EncryptedEnv, EnvKeys - ProvisionComposeUpdateRequest: add Name, visibility flags, UpdateEnvVars Terraform submodule updated to refactor/use-go-sdk branch (Phala-Network/terraform-provider-phala#4).
The Go SDK module path (github.com/Phala-Network/phala-cloud/sdks/go) doesn't match the repo directory structure (go/ not sdks/go/), so go mod download can't resolve it. Use a local replace directive and checkout the SDK in CI workflows.
Add diagnosticFromAPIError() helper that extracts structured error details (error_code, suggestions, links) from Go SDK's APIError into Terraform-friendly diagnostic messages. Update ProvisionCVM, commitAndCreate, and env update error paths in resource_app.go.
- CI: checkout refactor/terraform-use-go-sdk branch of phala-cloud for SDK type enhancements - buildProvisionReq: add missing public_logs, public_sysinfo, public_tcbinfo, secure_time to ComposeFile during provisioning - diagnosticFromAPIError: remove dependency on IsStructured/FormatError methods not yet on SDK main
- buildProvisionReq: set Region on ProvisionCVMRequest instead of discarding it, so CVMs deploy to the user-specified region - populateState: only update Listed from API when explicitly true, preventing spurious RequiresReplace drift when API omits the field
|
Addressed the review comments: buildProvisionReq missing compose fields (sentry comment #1): Fixed in 992daca + acd8552. Added Resource nil dereference (sentry comment #2): Not a real issue — Listed drift (sentry comment #3): Fixed in acd8552. Only update Region silently discarded: Fixed in acd8552. Added |
- Use ReplicateAppCVM (POST /apps/{appID}/cvms/{vmUUID}/replicas)
instead of ReplicateCVM to maintain correct app association
- Fix trailing newline in provider.go (gofmt)
- Handle CreditsInfo fields changed to *StringOrNumber in SDK
|
Addressed the 3 new review comments: ReplicateCVM endpoint (comment #4): Fixed in b7b4581. Added Resource nil check on DiskInGB (comment #5): Not a real issue — Listed only updates on true (comment #6): By design. |
The refactor/terraform-use-go-sdk branch was merged into Phala-Network/phala-cloud main and deleted, causing the sparse checkout step to fail with a 404.
Summary
client.go,client_typed.go) and oapi-codegen generated client (internal/phalaapi/) with the Phala Cloud Go SDKProvisionCVM,GetCVMInfo,PatchCVM, etc.) instead of rawPostJSON/GetJSON/PatchJSONoapi-codegen/runtimedependencyTest plan
go build ./...passesgo vet ./...passesgo test ./...passes (all existing tests updated to use SDK types)terraform plan/terraform applyagainst staging environment