Customize Terraform Properties
Remap API Property to Terraform Attribute Name
The x-speakeasy-name-override
annotation adjusts the Terraform attribute name within a resource while remapping all the API data handling internally. This is useful, for example, to standardize differing API property names across operations to a single attribute name.
The annotation also has other SDK customization capabilities, however, those are generally unnecessary for Terraform providers as the generated Go SDK is internal to the provider code.
Align API Parameter With Terraform Property
The x-speakeasy-match
annotation adjusts the API parameter name to align with a Terraform state property. If mismatches occur, a generation error will highlight appropriate root-level properties for accurate mapping.
Property Defaults
Setting a property default value that matches your API responses when unconfigured will enhance the Terraform plan to include the known value, rather than propagate the value as unknown (known after apply)
during creation and updates.
Speakeasy generation automatically adds a Terraform schema attribute default with OAS default
value, for each of the following OAS types:
OAS Schema Type | OAS default Support |
---|---|
array | Partial ([] only) |
boolean | Yes |
map | No |
number | Yes |
object | Partial (null only) |
oneOf | No |
string | Yes |
Custom Defaults
For unsupported or advanced use cases, the Terraform SDK supports calling schema-defined custom default logic resource/schema/defaults
package interface in any code location and use the OAS x-speakeasy-terraform-custom-default
extension to reference that implementation in the schema definition.
In this example, a custom string default implementation is created in internal/customdefaults/example.go
:
With the following OAS configuration on the target property:
The imports
configuration is optional if the custom code is within the internal/provider
package and does not require additional imports.
Hide Sensitive Properties
Properties marked as x-speakeasy-param-sensitive
will be concealed from the console output of Terraform. This helps to ensure the confidentiality of sensitive data within Terraform operations.
Deprecation
Add OAS deprecated: true
within a property to automatically return a warning diagnostic with a generic deprecation message when the property is configured in Terraform. Customize the messaging with the OAS x-speakeasy-deprecation-message
extension.
Info
Terraform always returns deprecation warnings for configured properties, but
has limitations for displaying these warnings with response-only properties
that are referenced elsewhere in the configuration. Terraform Feature
Request
In this example, Terraform will display a warning diagnostic with Custom deprecation message
if the property is configured:
Exclude Property From Terraform State
When x-speakeasy-terraform-ignore: true
, this extension ensures the specified property and any interactions involving it are omitted from Terraform’s state management.
Info
This extension completely suppresses the property from the Terraform state. If
you want to suppress a specific operation, use x-speakeasy-ignore: true
to
omit the operation from the annotated CRUD method. For example, if a field is
present in both the CREATE
and READ
response bodies, omitting it from the
READ
response body will turn off drift detection for that field. The field
will remain in the CREATE
response body and the Terraform state.
Custom Types
Set the x-speakeasy-terraform-custom-type
extension to switch a property from the terraform-plugin-framework base type (e.g. types.String
) to a custom type
The following terraform-plugin-framework base types are supported for custom types:
Bool
Float32
Float64
Int32
Int64
List
Map
Set
String
In this example, the ipv4_address
string property will use the custom iptypes.IPv4Address
type:
Allow JSON String Attributes
Set the x-speakeasy-type-override
extension to any
to convert the associated attribute to a JSON string. This allows for inline the specification of the attribute’s value, accommodating attributes with variable or dynamic structures.
Suppress Unnecessary Plan Changes
Setting the x-speakeasy-param-suppress-computed-diff
to true suppresses unnecessary Terraform plan changes for computed attributes that are not definitively known until after application. This is useful in scenarios where computed attributes frequently cause spurious plan changes.
Warning
Applying this modifier when x-speakeasy-entity-operation: my_resource#read
is not defined may result in drift between the Terraform plan and remote state
should updates to attributes happen outside of Terraform changes. Please only
apply this when necessary.
Last updated on