Skip to content

Commit bd89e3d

Browse files
austinvalleSBGoodsstephybun
authored
Add [email protected] documentation (#824)
* copy 1.15.x to new folder * Framework: Add documentation for actions in plugin framework (#848) * small changes to existing pages * start with a one pager * final updates to action page * update validation page * update general schema pages * update attribute docs to be less specific about each schema * update block types to be less specific * updated type docs to be less specific * split into two pages * Apply suggestions from code review Co-authored-by: Selena Goods <[email protected]> --------- Co-authored-by: Selena Goods <[email protected]> * updates to remove unlinked (#953) * Framework: add documentation for list resources (#898) * copy 1.15.x to new folder * Framework: Add documentation for actions in plugin framework (#848) * small changes to existing pages * start with a one pager * final updates to action page * update validation page * update general schema pages * update attribute docs to be less specific about each schema * update block types to be less specific * updated type docs to be less specific * split into two pages * Apply suggestions from code review Co-authored-by: Selena Goods <[email protected]> --------- Co-authored-by: Selena Goods <[email protected]> * add docs for list resources * update nav info * yaml spacing * Apply suggestions from code review --------- Co-authored-by: Austin Valle <[email protected]> Co-authored-by: Selena Goods <[email protected]> --------- Co-authored-by: Selena Goods <[email protected]> Co-authored-by: stephybun <[email protected]>
1 parent 249f90f commit bd89e3d

File tree

163 files changed

+24635
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+24635
-0
lines changed

content/terraform-plugin-framework/v1.16.x/data/plugin-framework-nav-data.json

Lines changed: 698 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
page_title: Acceptance tests
3+
description: >-
4+
Learn how to write acceptance tests for providers built on the framework.
5+
Acceptance tests help ensure your provider works as expected by imitating
6+
Terraform operations.
7+
---
8+
9+
# Acceptance tests
10+
11+
Implement provider resource and data source acceptance tests with the [terraform-plugin-testing module](/terraform/plugin/testing). These tests are designed to execute Terraform commands against real Terraform configurations, simulating practitioner experiences with creating, refreshing, updating, and deleting infrastructure.
12+
13+
This page only describes requirements of using the testing module with a framework provider. Refer to the [testing module documentation](/terraform/plugin/testing) for additional information on all available functionality in tests.
14+
15+
## Requirements
16+
17+
The testing module must know how to reference your provider code before Terraform commands and configurations can succeed. This is achieved by pointing the testing module at a [provider server](/terraform/plugin/framework/provider-servers) which wraps your [provider](/terraform/plugin/framework/providers).
18+
19+
Use one of the [`resource.TestCase` type](/terraform/plugin/testing/acceptance-tests/testcase) [`ProtoV6ProviderFactories` field](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/helper/resource#TestCase.ProtoV6ProviderFactories) for [protocol version 6](/terraform/plugin/terraform-plugin-protocol#protocol-version-6) or [`ProtoV5ProviderFactories` field](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/helper/resource#TestCase.ProtoV5ProviderFactories) for [protocol version 5](/terraform/plugin/terraform-plugin-protocol#protocol-version-5). It is only necessary to test with the single protocol version matching the production provider server, typically defined in the `main.go` file of the provider codebase.
20+
21+
### Protocol Version 6
22+
23+
Use the [`providerserver.NewProtocol6WithError`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/providerserver#NewProtocol6WithError) helper function to implement the provider server in the [`ProtoV6ProviderFactories` field](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/helper/resource#TestCase.ProtoV6ProviderFactories).
24+
25+
```go
26+
resource.Test(t, resource.TestCase{
27+
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error) {
28+
// newProvider is an example function that returns a provider.Provider
29+
"examplecloud": providerserver.NewProtocol6WithError(newProvider()),
30+
},
31+
Steps: []resource.TestStep{/* ... */},
32+
})
33+
```
34+
35+
### Protocol Version 5
36+
37+
Use the [`providerserver.NewProtocol5WithError`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/providerserver#NewProtocol5WithError) helper function to implement the provider server in the [`ProtoV5ProviderFactories` field](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-testing/helper/resource#TestCase.ProtoV5ProviderFactories).
38+
39+
```go
40+
resource.Test(t, resource.TestCase{
41+
ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error) {
42+
// newProvider is an example function that returns a provider.Provider
43+
"examplecloud": providerserver.NewProtocol5WithError(newProvider()),
44+
},
45+
Steps: []resource.TestStep{/* ... */},
46+
})
47+
```
48+
49+
## Troubleshooting
50+
51+
### No id found in attributes
52+
53+
<Highlight>
54+
55+
terraform-plugin-testing version 1.5.0 and later no longer require managed resources and data resources to implement the `id` attribute.
56+
57+
</Highlight>
58+
59+
In SDKv2, resources and data sources automatically included an implicit, root level `id` attribute. In the framework, the `id` attribute is not implicitly added.
60+
61+
When testing resources and data sources without the `id` attribute, the acceptance testing framework will return errors such as:
62+
63+
```text
64+
testing_new_config.go:111: no "id" found in attributes
65+
testing_new.go:53: no "id" found in attributes
66+
```
67+
68+
To avoid this, add a root level `id` attribute to resource and data source schemas. Ensure the attribute value is appropriately [written to state](/terraform/plugin/framework/writing-state). Conventionally, `id` is a computed attribute that contains the identifier for the resource.
69+
70+
For example, in the `Schema` method implementation of a [`datasource.DataSource`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/datasource#DataSource) or [`resource.Resource`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#Resource):
71+
72+
```go
73+
func (r *ThingResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
74+
resp.Schema = schema.Schema{
75+
// ... potentially other schema configuration ...
76+
Attributes: map[string]schema.Attribute{
77+
// ... potentially other schema attributes ...
78+
"id": schema.StringAttribute{
79+
Computed: true,
80+
},
81+
},
82+
}
83+
}
84+
```

0 commit comments

Comments
 (0)