framework

package
v1.83.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2026 License: MPL-2.0 Imports: 14 Imported by: 0

README

tencentcloud/framework

Home of the terraform-plugin-framework Provider entry point. Business references (resources, data sources, functions, ephemeral resources, list resources and actions) are co-located with the SDKv2 implementations under tencentcloud/services/<product>/ — there is no separate framework subtree for business code.

Current state: the framework Provider is wired into mux but no business references are registered yet. The six factory slices in registry.go are all empty. Add new references following the workflow in Adding a new framework reference.

Directory layout

tencentcloud/
├── framework/                # framework entry only — no business code lives here
│   ├── provider.go           # framework Provider implementation (Schema / Configure / Resources / DataSources / Functions / EphemeralResources / ListResources / Actions)
│   ├── registry.go           # SDKv2-style central manifest: six append-only factory slices
│   ├── provider.md           # framework reference index consumed by gendoc/
│   ├── provider_test.go      # in-package tests: mux startup sanity + no type-name collisions
│   ├── testhelpers_test.go   # in-package test helpers
│   ├── acctest/              # ProtoV5 test factories shared by acceptance tests
│   ├── internal/             # framework-only helpers (Go-internal-visible to framework/...)
│   └── README.md             # this file
└── services/
    ├── common/               # cross-product / provider-meta references (package common)
    ├── cvm/                  # CVM product (package cvm; SDKv2 + framework can mix)
    └── <product>/            # any other product follows the same pattern
File naming convention (mandatory)

Framework references follow the same <dtype>_tc_<name>.go template used by SDKv2 resources / data sources, with one new prefix per framework type:

Framework type File prefix Example
Resource resource_tc_ resource_tc_local_note.go
Data Source data_source_tc_ data_source_tc_provider_runtime.go
Function function_tc_ function_tc_parse_resource_id.go
Ephemeral Resource ephemeral_tc_ ephemeral_tc_temp_credential.go
List Resource list_tc_ list_tc_region.go
Action action_tc_ action_tc_cvm_reboot_instance.go

When a reference is product-specific, include the product segment (e.g. action_tc_cvm_reboot_instance); when it lives under services/common/, the product segment is omitted (e.g. resource_tc_local_note).

Each reference ships with a sibling Markdown file (<stem>.md) containing the description and Example Usage block consumed by make doc. gendoc accepts both <dtype>_tc_<resName>.md and <dtype>_tc_<product>_<resName>.md — the same naming the file uses.

Package naming convention

The Go package of every framework reference is the same as the SDKv2 package of that product:

  • services/common/package common
  • services/cvm/package cvm

There is no per-type subpackage (the older cvmactions / metaresources split has been removed): the SDKv2 and framework code share one package per service directory and import paths stay simple.

Wiring into main.go

main.go merges the SDKv2 and the framework providers into a single provider binary via tf5muxserver:

primary := tencentcloud.Provider()                  // SDKv2 entry
fw := framework.NewProvider(primary)                // entry of this package
providers := []func() tfprotov5.ProviderServer{
    primary.GRPCProvider,
    providerserver.NewProtocol5(fw),
}
muxServer, _ := tf5muxserver.NewMuxServer(ctx, providers...)

Adding a new framework reference

The central manifest tencentcloud/framework/registry.go mirrors the SDKv2 provider.go style: each framework reference type owns an append-only factory slice (resourceFactories, dataSourceFactories, functionFactories, ephemeralResourceFactories, listResourceFactories, actionFactories). The six framework Provider callbacks return these slices verbatim.

Workflow
  1. Implement the factory in the matching services/<product>/ package (e.g. services/cvm/resource_tc_cvm_my_thing.go):

    package cvm
    
    func NewMyThingResource() resource.Resource { return &myThingResource{} }
    // ... implement resource.Resource + resource.ResourceWithConfigure ...
    
  2. Register the factory by adding one line to the matching slice in framework/registry.go:

    var resourceFactories = []func() resource.Resource{
        cvm.NewMyThingResource, // <- one line, alphabetically grouped by product
    }
    

    If the product subpackage is not yet imported in registry.go, add one import line as well. provider.go does not need to change.

  3. Add the reference to the framework index in framework/provider.md so make doc picks it up. Use the same "product header / type label / type name" syntax as tencentcloud/provider.md. For example:

    Cloud Virtual Machine(CVM)
    Resource
    tencentcloud_my_thing
    
  4. Ship a sibling Markdown next to the Go file (e.g. resource_tc_cvm_my_thing.md) containing a short description and a required Example Usage HCL block.

That is the complete workflow — no edits to provider.go, no per-service register file, no init() magic.

Product-ownership rules
  • References that clearly belong to a real cloud product MUST land in the corresponding product directory (e.g. services/vpc/resource_tc_vpc_xxx.go).
  • References that are cross-product or not bound to any specific cloud product MAY land in services/common/ (for example, the provider's own runtime metadata, or local-only helper functions).

Relationship with SDKv2

  • Credentials, the SDK client, UA and retry are resolved and built only by the SDKv2 provider. This provider reuses the same *connectivity.TencentCloudClient via internal/sharedmeta.GetSharedMeta().
  • This provider's Schema must mirror SDKv2 (same names, same semantics, same nested structure); otherwise mux will reject the user's HCL fields when merging the two schemas. The mux startup invariants are exercised by make check-mux.
  • During Configure, *sharedmeta.ProviderMeta is written into all four fields resp.{ResourceData, DataSourceData, EphemeralResourceData, ActionData}.
  • Each resource / data source / action retrieves the shared client by type-asserting *sharedmeta.ProviderMeta inside its own Configure method.

Documentation

Overview

Package framework provides the terraform-plugin-framework flavour of the TencentCloud provider.

This package coexists with the SDKv2-based `tencentcloud.Provider()` inside the same provider binary via tf5muxserver. Directory layout: framework entry-points (provider, registry, tests) live under `tencentcloud/framework/`, while every business reference (resource, data source, function, ephemeral, list, action) is co-located with the SDKv2 implementations under `tencentcloud/services/<product>/`:

tencentcloud/
├── framework/                 # this package: framework entry only
│   ├── provider.go            # Provider Schema/Configure (this file)
│   ├── registry.go            # 6-type aggregator
│   ├── acctest/               # ProtoV5 test factories
│   └── internal/              # framework-only helpers
└── services/
    ├── common/                # cross-product / provider-meta references
    │   ├── data_source_tc_provider_runtime.go
    │   ├── resource_tc_local_note.go
    │   ├── function_tc_parse_resource_id.go
    │   ├── ephemeral_tc_temp_credential.go
    │   └── list_tc_region.go
    ├── cvm/                   # CVM product (SDKv2 + framework mixed)
    │   ├── resource_tc_instance.go        # SDKv2
    │   └── action_tc_cvm_reboot_instance.go  # framework
    └── <product>/             # other products follow the same pattern

Design notes:

  • Credentials, SDK client, UA and retry are constructed exclusively by the SDKv2 provider; this provider reuses the same *connectivity.TencentCloudClient via sharedmeta.GetSharedMeta().
  • Schema fields must mirror SDKv2 (same names, same semantics, same nesting). Otherwise mux will reject user-written fields when merging the two schemas.
  • Resources/DataSources/Functions/EphemeralResources/ListResources/ Actions are gathered by aggregator functions in registry.go, which imports product-level packages directly from `tencentcloud/services/`.

registry.go is the central, SDKv2-style manifest of every terraform-plugin-framework reference shipped by this provider.

Layout mirrors tencentcloud/provider.go's ResourcesMap / DataSourcesMap: each framework reference type has its own append-only block of one entry per line. To add a new reference, edit ONLY this file by adding the corresponding services subpackage import (if not already present) and a single new entry in the matching block. No edit to provider.go is required.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewProvider

func NewProvider(primary *sdk_schema.Provider) provider.ProviderWithMetaSchema

NewProvider constructs a framework provider instance to be registered as a secondary server inside mux. The primary parameter is the SDKv2 provider instance and is currently used only for metadata (such as version reflection); the framework provider does not invoke any runtime logic of the SDKv2 provider.

Types

type Provider

type Provider struct {
	Version string
	Primary *sdk_schema.Provider
}

Provider is the terraform-plugin-framework Provider implementation.

func (*Provider) Actions

func (p *Provider) Actions(_ context.Context) []func() action.Action

Actions aggregates every framework-side action. Implementations live in tencentcloud/services/<product>/ packages (for example, `services/cvm/action_tc_cvm_reboot_instance.go`) and are gathered by frameworkActions() in registry.go.

func (*Provider) Configure

Configure reuses the *connectivity.TencentCloudClient that SDKv2 has already constructed.

Key constraints:

  • Credentials are never re-parsed here; credential logic must live in the single SDKv2 providerConfigure function.
  • Inside mux, SDKv2 is Configure-d before framework (see registration order in main.go); sharedmeta.GetSharedMeta() should therefore return non-nil at this point.
  • As a defensive measure, nil only adds an Error diagnostic instead of panicking, to make troubleshooting easier.

func (*Provider) DataSources

func (p *Provider) DataSources(_ context.Context) []func() datasource.DataSource

DataSources aggregates every framework-side data source.

func (*Provider) EphemeralResources

func (p *Provider) EphemeralResources(_ context.Context) []func() ephemeral.EphemeralResource

EphemeralResources aggregates every framework-side ephemeral resource.

func (*Provider) Functions

func (p *Provider) Functions(_ context.Context) []func() function.Function

Functions aggregates every framework-side provider-defined function.

func (*Provider) GenerateResourceConfig

func (p *Provider) GenerateResourceConfig(context.Context, any) (any, error)

GenerateResourceConfig is required by the framework interface but is not currently part of any configuration-generation flow.

func (*Provider) ListResources

func (p *Provider) ListResources(_ context.Context) []func() list.ListResource

ListResources aggregates every framework-side list resource.

func (*Provider) MetaSchema

MetaSchema MUST mirror SDKv2 exactly. The SDKv2 provider in tencentcloud/provider.go does NOT define a ProviderMetaSchemaFunc, which means SDKv2 reports an empty (zero-attribute) provider meta schema to the protocol. tf5muxserver compares the meta schema across underlying providers, so framework MUST also report an empty schema. Any attribute declared here that is not declared in SDKv2 will fail provider startup with "Invalid Provider Server Combination".

func (*Provider) Metadata

Metadata exposes the provider's type name and version, used by the framework runtime for identification.

func (*Provider) Resources

func (p *Provider) Resources(_ context.Context) []func() resource.Resource

Resources aggregates every framework-side resource. The concrete entries are gathered by frameworkResources() in tencentcloud/framework/registry.go, which imports factories directly from `tencentcloud/services/<product>/` (e.g. `services/common/` for cross-product references).

func (*Provider) Schema

Schema mirrors the SDKv2 provider's field set byte-for-byte.

Key principles:

  • Field names, types, Required/Optional, Sensitive flags and Description strings MUST match SDKv2 (tencentcloud/provider.go) exactly. tf5muxserver compares the protocol-level schema across underlying providers; any divergence (including a single character in Description) will fail provider startup with "Invalid Provider Server Combination".
  • SDKv2's TypeSet/TypeList with MaxItems=1 is equivalent to a nested block at the protocol v5 layer, so we use SetNestedBlock / ListNestedBlock here, not nested attributes.
  • The framework side does not consume any of these fields at runtime; credential parsing lives exclusively in the SDKv2 providerConfigure. This Schema only exists to satisfy mux's schema-consistency invariant.
  • SDKv2 ConflictsWith / ValidateFunc / DefaultFunc are NOT serialized into the protocol schema, so they are intentionally not mirrored here. Only attributes that are part of the wire schema are mirrored.

Directories

Path Synopsis
Package frameworkacctest provides ProtoV5ProviderFactories used by framework resource / data source acceptance tests.
Package frameworkacctest provides ProtoV5ProviderFactories used by framework resource / data source acceptance tests.
internal
helper
Package helper is the shared utility package for resources/data sources on the terraform-plugin-framework side.
Package helper is the shared utility package for resources/data sources on the terraform-plugin-framework side.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL