Skip to content

Commit 46c9ee1

Browse files
authored
all: Go package documentation updates post datasource, provider, and resource package migration (#436)
Reference: #432
1 parent 51b944f commit 46c9ee1

File tree

7 files changed

+91
-7
lines changed

7 files changed

+91
-7
lines changed

datasource/data_source.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ package datasource
22

33
import "context"
44

5-
// DataSource represents a data source instance. This is the core interface that
6-
// all data sources must implement.
5+
// DataSource represents an instance of a data source type. This is the core
6+
// interface that all data sources must implement.
7+
//
8+
// Data sources can optionally implement these additional concepts:
9+
//
10+
// - Validation: Schema-based via tfsdk.Attribute or entire configuration
11+
// via DataSourceWithConfigValidators or DataSourceWithValidateConfig.
12+
//
713
type DataSource interface {
814
// Read is called when the provider must read data source values in
915
// order to update state. Config values should be read from the

datasource/doc.go

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
11
// Package datasource contains all interfaces, request types, and response
22
// types for a data source implementation.
3+
//
4+
// In Terraform, a data source is a concept which enables provider developers
5+
// to offer practitioners a read-only source of information, which is saved
6+
// into the Terraform state and can be referenced by other parts of a
7+
// configuration. Data sources are defined by a data source type/name, such as
8+
// "example_thing", a schema representing the structure and data types of
9+
// configuration and state, and read logic.
10+
//
11+
// The main starting point for implementations in this package is the
12+
// DataSource type which represents an instance of a data source type that has
13+
// its own configuration, read logic, and state. A DataSource is instantiated
14+
// from a provider.DataSourceType type NewDataSource method, which also defines
15+
// the data source schema. The provider.DataSourceType types are referenced by
16+
// a provider.Provider type GetDataSources method, which enables the data
17+
// source for practitioner and testing usage.
318
package datasource

provider/doc.go

+19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
11
// Package provider contains all interfaces, request types, and response
22
// types for a provider implementation.
3+
//
4+
// In Terraform, a provider is a concept which enables provider developers
5+
// to offer practitioners data sources and managed resources. Those concepts
6+
// are described in more detail in their respective datasource and resource
7+
// packages.
8+
//
9+
// Providers generally store any infrastructure clients or shared data that is
10+
// applicable across data sources and managed resources. Providers are
11+
// generally configured early in Terraform operations, such as plan and apply,
12+
// before data source and managed resource logic is called. However, this early
13+
// provider configuration is not guaranteed in the case there are unknown
14+
// Terraform configuration values, so additional logic checks may be required
15+
// throughout an implementation to handle this case. Providers may contain a
16+
// schema representing the structure and data types of Terraform-based
17+
// configuration.
18+
//
19+
// The main starting point for implementations in this package is the
20+
// Provider type which represents an instance of a provider that has
21+
// its own configuration.
322
package provider

provider/provider.go

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ import (
88
)
99

1010
// Provider is the core interface that all Terraform providers must implement.
11+
//
12+
// Providers can optionally implement these additional concepts:
13+
//
14+
// - Validation: Schema-based via tfsdk.Attribute or entire configuration
15+
// via ProviderWithConfigValidators or ProviderWithValidateConfig.
16+
// - Meta Schema: ProviderWithMetaSchema
17+
//
1118
type Provider interface {
1219
// GetSchema returns the schema for this provider's configuration. If
1320
// this provider has no configuration, return an empty schema.Schema.

providerserver/doc.go

+10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
// Package providerserver implements functionality for serving a provider,
22
// such as directly starting a server in a production binary and conversion
33
// functions for testing.
4+
//
5+
// For production usage, call the Serve function from binary startup, such as
6+
// from the provider codebase main package. If multiplexing the provider server
7+
// via terraform-plugin-mux functionality, use the NewProtocol* functions and
8+
// call the Serve function from that Go module. For testing usage, call the
9+
// NewProtocol* functions.
10+
//
11+
// All functionality in this package requires the provider.Provider type, which
12+
// contains the provider implementation including all managed resources and
13+
// data sources.
414
package providerserver

resource/doc.go

+19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
11
// Package resource contains all interfaces, request types, and response types
22
// for a managed resource implementation.
3+
//
4+
// In Terraform, a managed resource is a concept which enables provider
5+
// developers to offer practitioners full lifecycle management (create, read,
6+
// update, and delete) of a infrastructure component. Managed resources can
7+
// also stand in for one-time infrastructure operations that require tracking,
8+
// by implementing create logic, while omitting update and delete logic.
9+
//
10+
// Resources are saved into the Terraform state and can be referenced by other
11+
// parts of a configuration. Resources are defined by a resource type/name,
12+
// such as "example_thing", a schema representing the structure and data types
13+
// of configuration, plan, and state, and lifecycle logic.
14+
//
15+
// The main starting point for implementations in this package is the
16+
// Resource type which represents an instance of a resource type that has
17+
// its own configuration, plan, state, and lifecycle logic. A Resource is
18+
// instantiated from a provider.ResourceType type NewResource method, which
19+
// also defines the resource schema. The provider.ResourceType types are
20+
// referenced by a provider.Provider type GetResources method, which enables
21+
// the resource for practitioner and testing usage.
322
package resource

resource/resource.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@ import (
44
"context"
55
)
66

7-
// Resource represents a resource instance. This is the core interface that all
8-
// resources must implement.
7+
// Resource represents an instance of a managed resource type. This is the core
8+
// interface that all resources must implement.
99
//
10-
// It is also conventional for resources to implement the
11-
// ResourceWithImportState interface, which enables practitioners to import
12-
// existing infrastructure into Terraform.
10+
// Resources can optionally implement these additional concepts:
11+
//
12+
// - Import: ResourceWithImportState
13+
// - Validation: Schema-based via tfsdk.Attribute or entire configuration
14+
// via ResourceWithConfigValidators or ResourceWithValidateConfig.
15+
// - Plan Modification: Schema-based via tfsdk.Attribute or entire plan
16+
// via ResourceWithModifyPlan.
17+
// - State Upgrades: ResourceWithUpgradeState
18+
//
19+
// Although not required, it is conventional for resources to implement the
20+
// ResourceWithImportState interface.
1321
type Resource interface {
1422
// Create is called when the provider must create a new resource. Config
1523
// and planned state values should be read from the

0 commit comments

Comments
 (0)