You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/plugin/framework/getting-started/example-provider.mdx
+14-18
Original file line number
Diff line number
Diff line change
@@ -6,39 +6,35 @@ description: >-
6
6
7
7
# Simple Example Provider
8
8
9
-
[Terraform providers](/terraform/language/providers) allow Terraform core to communicate with 3rd parties such as cloud providers, SaaS providers, and other APIs.
10
-
Communication between Terraform core and Terraform providers uses gRPC, with core operating as a gRPC client and providers operating as gRPC servers, respectively.
11
-
Terraform provider resources are used to manage infrastructure objects, such as virtual networks and compute instances.
12
-
Terraform provider data sources give a read-only view of infrastructure objects.
9
+
[Terraform providers](/terraform/language/providers) let Terraform communicate with third parties, such as cloud providers, SaaS providers, and other APIs. Terraform and Terraform providers use gRPC to communicate. Terraform operates as a gRPC client and providers operate as gRPC servers.
13
10
14
-
The purpose of this example is to show the relationship between the components that are required to build a minimal Terraform provider.
15
-
In a real provider the resource and data source would typically interact with a cloud provider via an API but in this example we are simply storing values in state.
16
-
Stripping the Terraform provider back to the bare essentials allows us to focus on the minimum requirements needed to build a functional provider.
11
+
Each provider defines resources that let Terraform manage infrastructure objects and data sources that let Terraform read data. Terraform practitioners then write configuration to define resources, such as compute storage or networking resources. Terraform then communicates this configuration to the provider, and the provider creates the infrastructure.
17
12
18
-
A Terraform plugin provider requires the following as a minimum:
13
+
This example provider shows the relationship between the required provider components. The resources and data sources in a typical provider interact with a cloud provider through an API, but the example only stores values in state.
19
14
20
-
* provider server
21
-
* provider
22
-
* resource (and/or data source)
23
-
* data source (and/or resource)
15
+
## Core Provider Components
24
16
25
-
A provider server is the gRPC server that the Terraform core gRPC client communicates with.
17
+
A Terraform plugin provider requires at least the following components:
18
+
19
+
-[provider server](#provider-server)
20
+
-[provider](#provider)
21
+
-[resource](#resource) or [data source](#data-source)
22
+
23
+
Every provider also requires a provider server, which is the gRPC server that communicates with the Terraform gRPC client.
26
24
The provider wraps the resource(s) and/or data source(s), and can be used to configure a client which communicates with a 3rd party service via an API.
27
25
Resources are used to manage infrastructure objects.
28
26
Data sources are used to read infrastructure objects.
29
27
30
28
## Provider Server
31
29
32
-
Each provider must implement a gRPC server that supports Terraform-specific connection and handshake handling on startup.
30
+
Each provider must implement a gRPC server that supports Terraform-specific connection and handshake handling on startup. A [provider server](/plugin/framework/provider-servers) is required in order for a Terraform provider to:
33
31
34
-
A [provider server](/plugin/framework/provider-servers) is required in order for a Terraform provider to:
35
32
* expose resources that can be managed by Terraform core.
36
33
* expose data sources that can be read by Terraform core.
37
34
38
35
The `main()` function is used for defining a provider server.
39
36
40
-
The `provider.New()` returns a function which returns a type that satisfies the `provider.Provider` interface.
41
-
The `provider.Provider` interface defines functions for obtaining the resource(s) and/or data source(s) from a provider.
37
+
The `provider.New()` returns a function which returns a type that satisfies the `provider.Provider` interface. The `provider.Provider` interface defines functions for obtaining the resource(s) and/or data source(s) from a provider.
42
38
43
39
```go
44
40
package main
@@ -146,7 +142,7 @@ A resource is typically used to manage infrastructure objects such as virtual ne
146
142
147
143
In this example the resource simply interacts with Terraform state.
148
144
149
-
`NewResource()` returns a function which returns a type that satisfies the `resource.Resource` interface. The `NewResource()` function is used within the `provider.Resources`function to make the resource available to the provider.
145
+
`NewResource()` returns a function which returns a type that satisfies the `resource.Resource` interface. The provider calls the `NewResource()` function within `provider.Resources` to obtain an instance of the resource.
150
146
151
147
The `exampleResource` struct implements the `resource.Resource` interface. This interface defines the following functions:
0 commit comments