Skip to content

Commit 9d5e2f3

Browse files
committed
Sync open source content 🐝 (from 30fe27dae1ed893e2a95c0899389f98c047ce8ba)
1 parent 57dece1 commit 9d5e2f3

File tree

5 files changed

+121
-64
lines changed

5 files changed

+121
-64
lines changed

docs/terraform/advanced-features.mdx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ title: "Advanced Features"
33
description: "Learn about advanced customization options for Terraform providers."
44
---
55

6-
7-
86
# Advanced Features
97

108
## Speciality Annotations
@@ -80,3 +78,14 @@ components:
8078
nullable: true
8179
x-speakeasy-terraform-plan-only: true
8280
```
81+
82+
## Deduplicate Terraform Types
83+
84+
The `terraform` types folder includes a representation of your data models that is appropriate for the `terraform-plugin-framework` type system. However, if you have multiple types with the same _signature_ (e.g. the same set of child property _types_), there might be a lot of these types that are effectively duplicated. To minimize the git repository / binary size, it might make sense to deduplicate these by re-using types with the same _signature_ across different resources. If you would like to enable this, set the following configuration option:
85+
86+
This option is `false` by default.
87+
88+
```yaml
89+
terraform:
90+
enableTypeDeduplication: true
91+
```

docs/terraform/index.mdx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,47 @@ title: "Customize Terraform Provider"
33
description: "Learn how to customize your Terraform provider using Speakeasy extensions and configurations."
44
---
55

6-
7-
86
# Customize Your Terraform Provider
97

108
Speakeasy provides various extensions and configurations to customize your Terraform provider. These customizations allow you to:
119

12-
- Map API entities to Terraform resources
13-
- Specify CRUD operations
10+
- Map API entities and operations to Terraform resources
11+
- Enable provider-level configurations and environment values
1412
- Customize validation and plan modification
15-
- Configure environment values
1613
- And more
1714

1815
Select a topic from the navigation to learn more about specific customization options.
1916

2017
## Available Customization Options
2118

2219
### [Entity Mapping](/docs/terraform/entity-mapping)
20+
2321
Learn how to map your API entities to Terraform resources and specify CRUD operations.
2422

23+
### [Provider Configuration](/docs/terraform/provider-configuration)
24+
25+
Configure environment values and manage custom resources.
26+
27+
### [Resource Configuration](/docs/terraform/resource-configuration)
28+
29+
Configure resource descriptions and managed resource versioning.
30+
2531
### [Property Customization](/docs/terraform/property-customization)
32+
2633
Customize how API properties are mapped to Terraform attributes and manage property behavior.
2734

2835
### [Validation and Dependencies](/docs/terraform/validation-dependencies)
36+
2937
Add custom validation logic and manage attribute dependencies.
3038

3139
### [Plan Modification](/docs/terraform/plan-modification)
32-
Customize Terraform plan behavior and resource versioning.
3340

34-
### [Configuration](/docs/terraform/configuration)
35-
Configure environment values and manage custom resources.
41+
Customize Terraform plan behavior and resource versioning.
3642

3743
### [Advanced Features](/docs/terraform/advanced-features)
44+
3845
Access advanced customization options for fine-grained control.
3946

4047
### [Schema Keywords](/docs/terraform/schema-keywords)
48+
4149
Learn about supported OpenAPI schema keywords and their behavior.

docs/terraform/plan-modification.mdx

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
22
title: "Plan Modification"
3-
description: "Learn how to customize Terraform plan behavior and resource versioning."
3+
description: "Learn how to customize Terraform plan behavior."
44
---
55

6-
7-
86
# Plan Modification
97

10-
## Add Custom Plan Modification Logic
8+
## Custom Attribute Plan Modification
9+
10+
Attribute plan modifiers enable advanced default value, resource replacement, and difference suppression logic in managed resources. Due to the Terraform SDK implementation, attribute-level plan modifiers do not have access to provider-level configuration or the API client, however that SDK does support custom resource-level plan modification with implementing the [`resource.ResourceWithModifyPlan` interface](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource#ResourceWithModifyPlan).
1111

12-
Use the `x-speakeasy-plan-modifiers` extension to add custom plan modification logic to Terraform plan operations. Plan modifiers enable advanced default value, resource replacement, and difference suppression logic.
12+
Use the `x-speakeasy-plan-modifiers` extension to add custom attribute-level plan modification logic to Terraform plan operations.
1313

1414
```yaml
1515
components:
@@ -27,6 +27,14 @@ components:
2727
2828
In this scenario, when Speakeasy next generates the Terraform provider, it will bootstrap a custom plan modifier file located at `internal/planmodifiers/int64planmodifier/age_modifier.go`, and import the schema configuration wherever `x-speakeasy-plan-modifiers: AgeModifier` is referenced. Edit the plan modifier file to contain the required logic.
2929

30+
The `x-speakeasy-plan-modifiers` extension supports an array of names as well, such as:
31+
32+
```yaml
33+
x-speakeasy-plan-modifiers:
34+
- FirstPlanModifier
35+
- SecondPlanModifier
36+
```
37+
3038
### Implementation Notes
3139

3240
1. A plan modifier is a type conformant to the `terraform-plugin-framework` expected interface. A unique plan modifier will be bootstrapped in the appropriate subfolder for the Terraform type it is applied to: `boolplanmodifiers`, `float64planmodifiers`, `int64planmodifiers`, `listplanmodifiers`, `mapplanmodifiers`, `numberplanmodifiers`, `objectplanmodifiers`, `setplanmodifiers`, or `stringplanmodifiers`. Speakeasy will always create and use a file as `snake_case.go` for a given `x-speakeasy-plan-modifiers` value.
@@ -35,16 +43,6 @@ In this scenario, when Speakeasy next generates the Terraform provider, it will
3543

3644
3. While working with a plan modifier, you have the ability to perform various tasks, including initiating network requests. However, it's important to ensure that plan modifiers do not result in any unintended side effects. Please refer to [the HashiCorp guidance on plan modifier development](https://developer.hashicorp.com/terraform/plugin/framework/resources/plan-modification) or reach out in our Slack if you have questions.
3745

38-
4. It is possible to have an array of plan modifiers, for example, `x-speakeasy-plan-modifiers: [FirstModifier, SecondModifier]`.
39-
40-
5. A modifier can only be applied to a resource attribute. The annotation will be ignored for data sources. Modifiers cannot be applied at the same level as the `x-speakeasy-entity` annotation because that becomes the "root" of the Terraform resource.
41-
42-
6. Speakeasy regenerations do not delete user-written code. If the modifier is no longer in use, it will be ignored (no longer referenced) but the source file will remain. You might want to delete such an orphaned modifier file for repository hygiene.
43-
44-
## Specify Resource Version
45-
46-
The `x-speakeasy-entity-version` extension specifies the version of a given resource and should *only* be used if you need to write a state migrator, for instance, if you are changing the type of a field.
47-
48-
Terraform resource versions are zero-indexed and default to `0`. For your first breaking change requiring a state migrator, set `x-speakeasy-entity-version: 1`. Each state migrator function must migrate from the previous version of the state.
46+
4. A modifier can only be applied to a resource attribute. The annotation will be ignored for data sources. Modifiers cannot be applied at the same level as the `x-speakeasy-entity` annotation because that becomes the "root" of the Terraform resource.
4947

50-
If this is set, a boilerplate state upgrader will be written and hooked into `internal/stateupgraders/your_resource_v1.go`. Please refer to the [Terraform documentation](https://developer.hashicorp.com/terraform/plugin/framework/resources/state-upgrade) for guidance on writing a state migrator.
48+
5. Speakeasy regenerations do not delete user-written code. If the modifier is no longer in use, it will be ignored (no longer referenced) but the source file will remain. You might want to delete such an orphaned modifier file for repository hygiene.

docs/terraform/configuration.mdx renamed to docs/terraform/provider-configuration.mdx

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,52 @@
11
---
2-
title: "Configuration"
3-
description: "Learn how to configure environment values and manage custom resources in the Terraform provider."
2+
title: "Provider Configuration"
3+
description: "Learn how to customize the generated Terraform Provider, such as supporting environment variables and custom resources."
44
---
55

6-
# Configuration
6+
# Provider Configuration
77

8-
## Configuring Environment Values
8+
## Security
99

10-
Use the `environmentVariables` configuration in the `gen.yaml` to set up default values for provider variables to be pulled in from an environment variable. This is useful for mapping known environment values that will hold an API key into the provider.
10+
The generated Terraform Provider will automatically implement all global security as defined in the OpenAPI Specification via the root level `security` property and its associated `securitySchemes` components. Multiple security options are supported.
11+
12+
In this example, the provider will be generated with bearer authenticiation token requirement using an `access_token` provider-level attribute:
13+
14+
```yaml
15+
components:
16+
securitySchemes:
17+
accessToken:
18+
type: http
19+
scheme: bearer
20+
security:
21+
- accessToken: []
22+
```
23+
24+
Refer to the [Configuring Environment Variables section](#configuring-environment-variables) to optionally enable fallback environment variable configuration of the value.
25+
26+
Operation-level security is not supported nor recommended. Instead, it is generally more desirable to implement separate providers per security layer. Terraform practitioners are conventionally used to the layering of provider implementations for this use case and Terraform itself is designed around those separation of concerns. Refer to the [HashiCorp provider design principles documentation](https://developer.hashicorp.com/terraform/plugin/best-practices/hashicorp-provider-design-principles) for more context.
27+
28+
## Globals
29+
30+
Enable provider-level configuration of common properties across many resources via the [`x-speakeasy-globals` extension](/docs/customize/globals). This customization allows Terraform practitioners to configure a value via:
31+
32+
* Provider-level only: Default value applied to any resources that use the global
33+
* Resource-level only: Explicit value applied to only those resource instance(s)
34+
* Provider-level with resource-level override: Default value applied to any resources that use the global with any explicit resource-level configuration overriding the provider-level value
35+
36+
In this example, the provider will accept an `organization_id` configuration as a global:
37+
38+
```yaml
39+
x-speakeasy-globals:
40+
parameters:
41+
- name: organizationId
42+
in: path
43+
schema:
44+
type: string
45+
```
46+
47+
## Configuring Environment Variables
48+
49+
Use the `environmentVariables` configuration in the `gen.yaml` to set up an environment variable fallback for provider attribute data configuration. For example, accepting an access token value via environment variable, rather than requiring explicit `provider` block attribute configuration from Terraform practitioners.
1150

1251
```yaml
1352
terraform:
@@ -99,35 +138,3 @@ The `additionalEphemeralResources` key follows the same syntax, but will insert
99138
The `additionalDataSources` key follows the same syntax, but will insert data resources into the provider using `datasource` (instead of `resource`) as the value inserted into the list.
100139

101140
To learn more about how to write a Terraform resource, please consult the [official Terraform documentation](https://developer.hashicorp.com/terraform/plugin/framework).
102-
103-
## Modifying Resource and Data Source Descriptions
104-
105-
The `x-speakeasy-entity-description` extension allows modification of the description of a Terraform resource or data source. 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.
106-
107-
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).
108-
109-
```yaml
110-
components:
111-
schemas:
112-
Order:
113-
description: An order helps you make coffee
114-
x-speakeasy-entity: Order
115-
x-speakeasy-entity-description: |
116-
The order resource allows you to declaratively construct an order for coffee.
117-
118-
resource "speakeasy_order" "example" {
119-
name = "Filter Blend"
120-
price = 11.5
121-
}
122-
```
123-
124-
## Deduplicate Terraform Types
125-
126-
The `terraform` types folder includes a representation of your data models that is appropriate for the `terraform-plugin-framework` type system. However, if you have multiple types with the same _signature_ (e.g. the same set of child property _types_), there might be a lot of these types that are effectively duplicated. To minimize the git repository / binary size, it might make sense to deduplicate these by re-using types with the same _signature_ across different resources. If you would like to enable this, set the following configuration option:
127-
128-
This option is `false` by default.
129-
130-
```yaml
131-
terraform:
132-
enableTypeDeduplication: true
133-
```
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: "Resource Configuration"
3+
description: "Learn how to customize a generated Terraform Provider resource, such as custom descriptions."
4+
---
5+
6+
# Resource Configuration
7+
8+
## Resource Description
9+
10+
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.
11+
12+
```yaml
13+
components:
14+
schemas:
15+
Order:
16+
description: An order helps you make coffee
17+
x-speakeasy-entity: Order
18+
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+
}
25+
```
26+
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).
28+
29+
## Resource Version
30+
31+
The `x-speakeasy-entity-version` extension specifies the version of a given resource and should *only* be used if you need to write a state migrator, for instance, if you are changing the type of a field.
32+
33+
Terraform resource versions are zero-indexed and default to `0`. For your first breaking change requiring a state migrator, set `x-speakeasy-entity-version: 1`. Each state migrator function must migrate from the previous version of the state.
34+
35+
If this is set, a boilerplate state upgrader will be written and hooked into `internal/stateupgraders/your_resource_v1.go`. Please refer to the [Terraform documentation](https://developer.hashicorp.com/terraform/plugin/framework/resources/state-upgrade) for guidance on writing a state migrator.

0 commit comments

Comments
 (0)