Skip to content

Commit e60fcf0

Browse files
committed
Sync open source content 🐝 (from aec61aed1f85c922410ed687e8862d21056e46bf)
1 parent 07a97fc commit e60fcf0

1 file changed

Lines changed: 68 additions & 8 deletions

File tree

docs/terraform/resource-configuration.mdx

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,88 @@ title: "Resource Configuration"
33
description: "Learn how to customize a generated Terraform Provider resource, such as custom descriptions."
44
---
55

6+
import { Table } from "@/mdx/components";
7+
68
# Resource Configuration
79

8-
## Resource Description
10+
## Resource Documentation
11+
12+
Speakeasy automatically generates provider and resource documentation that is compliant with the [public Terraform Registry requirements](https://developer.hashicorp.com/terraform/registry/providers/docs) via the HashiCorp-maintained [`terraform-plugin-docs`](https://github.com/hashicorp/terraform-plugin-docs) tool. Speakeasy runs `terraform-plugin-docs` at the end of successful generations or manually run via `go generate ./...`.
13+
14+
The public Terraform Registry and `terraform-plugin-docs` tool both follow specific file layout conventions.
15+
16+
For resources, the following file conventions are used:
17+
18+
<Table
19+
data={[
20+
{
21+
fileConvention: "docs/data-sources/{name}.md",
22+
example: "docs/data-sources/order.md",
23+
description: "Data resource documentation rendered in public Terraform Registry.",
24+
generatedBy: "terraform-plugin-docs",
25+
},
26+
{
27+
fileConvention: "docs/resources/{name}.md",
28+
example: "docs/resources/order.md",
29+
description: "Managed resource documentation rendered in public Terraform Registry.",
30+
generatedBy: "terraform-plugin-docs",
31+
},
32+
{
33+
fileConvention: "examples/data-sources/{type}/data-source.tf",
34+
example: "examples/data-sources/example_order/data-source.tf",
35+
description: "Data resource example configuration added to documentation page.",
36+
generatedBy: "Speakeasy",
37+
},
38+
{
39+
fileConvention: "examples/resources/{type}/import.sh",
40+
example: "examples/resources/example_order/import.sh",
41+
description: "Managed resource terraform import CLI command added to documentation page.",
42+
generatedBy: "Speakeasy",
43+
},
44+
{
45+
fileConvention: "examples/resources/{type}/resource.tf",
46+
example: "examples/resources/example_order/resource.tf",
47+
description: "Managed resource example configuration added to documentation page.",
48+
generatedBy: "Speakeasy",
49+
},
50+
]}
51+
columns={[
52+
{ key: "fileConvention", header: "File Convention" },
53+
{ key: "example", header: "Example" },
54+
{ key: "description", header: "Description" },
55+
{ key: "generatedBy", header: "Generated By" },
56+
]}
57+
/>
58+
59+
The `terraform-plugin-docs` tool also supports its own advanced use case customization, such as custom templates. Refer to the [`terraform-plugin-docs` documentation](https://github.com/hashicorp/terraform-plugin-docs) for more information about those capabilities.
60+
61+
### Resource Description
962

1063
The `x-speakeasy-entity-description` extension allows modification of the description of a Terraform data or managed resource. This is useful when augmenting the documentation in an OpenAPI specification with documentation for specific resources. This documentation is expected to be in Markdown format. Use this extension alongside the `x-speakeasy-entity` extension.
1164

65+
In this example, an order managed resource will have `Manage a coffee order.` written as the description in the resource code for any consuming tools, including documentation written by `terraform-plugin-docs` into `docs/resources/order.md`:
66+
1267
```yaml
1368
components:
1469
schemas:
1570
Order:
1671
description: An order helps you make coffee
1772
x-speakeasy-entity: Order
1873
x-speakeasy-entity-description: |
19-
The order resource allows you to declaratively construct an order for coffee.
20-
21-
resource "speakeasy_order" "example" {
22-
name = "Filter Blend"
23-
price = 11.5
24-
}
74+
Manage a coffee order.
2575
```
2676
27-
Alternatively, a template folder can be written to customize any or all aspects of generated documentation in alignment with [terraform-plugin-docs](https://github.com/hashicorp/terraform-plugin-docs).
77+
### Resource Example
78+
79+
Example resource configuration is based on the OpenAPI Specification for API operation request and response data schemas. Speakeasy only generates example configuration for configurable properties. Example configuration values use the property `example` field when available or fallback to a generated value of the expected type following any `enum` or validation fields.
80+
81+
Fully customize the example resource configuration by using Speakeasy [code customization capabilities](/docs/customize/code/monkey-patching).
82+
83+
For example, to manually manage and update the example configuration for a managed resource:
84+
85+
* Edit root directory `.genignore` file with an entry for `examples/resources/{type}/resource.tf`
86+
* Edit `examples/resources/{type}/resource.tf` as necessary
87+
* Run `go generate ./...` or Speakeasy generation to update `docs/resources/{name}.md`
2888

2989
## Resource Version
3090

0 commit comments

Comments
 (0)