npx skills add ...
npx skills add hashicorp/agent-skills --skill provider-actions
npx skills add hashicorp/agent-skills --skill provider-actions
Implement Terraform Provider actions using the Plugin Framework. Use when developing imperative operations that execute at lifecycle events (before/after create, update, destroy).
The same skill content is published under more than one repo. The install counts are split across them; any of these commands works.
Terraform Actions enable imperative operations during the Terraform lifecycle. Actions are experimental features that allow performing provider operations at specific lifecycle events (before/after create, update, destroy).
References:
When adding the first action to a provider that has never had one, several one-time scaffolding steps are required:
ProviderWithActions — add an Actions() method to the provider that returns []func() action.Action.ActionData in Configure — the provider's Configure method must set resp.ActionData = v alongside the existing ResourceData, DataSourceData, and EphemeralResourceData assignments.ActionWithConfigure base type — if the provider uses embedded base types (e.g. ResourceWithConfigure), create an equivalent ActionWithConfigure type implementing action.ConfigureRequest / action.ConfigureResponse.namespace) via helper functions, action-schema variants are needed since action/schema types differ from resource/schema types.Actions follow the standard service package structure:
Documentation structure:
Changelog entry:
Actions use the Terraform Plugin Framework with a standard schema pattern:
Pay special attention to the schema definition - common issues after a first draft:
Type Mismatches
types.String instead of fwtypes.String in model structstypes.StringType instead of fwtypes.StringType in schemaList/Map Element Types
Computed vs Optional
Optional: true and Computed: trueComputed unless they have defaultsValidator Imports
Region/Provider Attribute
Nested Attributes
Before submitting, verify:
go build to catch type mismatchesThe Invoke method contains the action logic:
resp.SendProgress(action.InvokeProgressEvent{...}) for real-time updatescontext.WithTimeout() for API callsresp.Diagnostics.AddError()Example error handling:
a.Meta().<Service>Client(ctx)For operations that require waiting for completion:
Actions are invoked via action_trigger lifecycle blocks in Terraform configurations. A standalone action block without a corresponding trigger is declared but never executed.
Action parameters must be wrapped in a config {} block. Trigger references use the action. prefix, and actions is a list. Events are bare identifiers, not quoted strings.
Terraform 1.14.0 Supported Events:
before_create - Before resource creationafter_create - After resource creationbefore_update - Before resource updateafter_update - After resource updateNot Supported in Terraform 1.14.0:
before_destroy - Not available (will cause validation error)after_destroy - Not available (will cause validation error)Add sweep functions to clean up test resources:
terraform_data as a No-Op Triggerterraform_data can serve as a no-op trigger resource for action tests that don't need real infrastructure. This is valuable for error-case and validation tests:
PostApplyFunc to Verify Side EffectsActions don't produce state that can be checked with resource.TestCheckResourceAttr. Use PostApplyFunc on resource.TestStep to query the API after apply and confirm the action produced the expected side effect:
Service-Specific Prerequisites
Error Pattern Matching
regexache.MustCompile(\(?s)Error Title.*key phrase`)`Test Patterns Not Applicable to Actions
Compile test to check for errors:
Run specific action tests:
Run sweep to clean up test resources:
Each action documentation file must include:
Front Matter
Header with Warnings
Example Usage
terraform_dataArgument Reference
Documentation Linting
terrafmt fmt before submissionterrafmt diffCreate a changelog entry in .changelog/ directory:
Content format:
Before submitting your action implementation:
go build -o /dev/null .go test -c -o /dev/null ./internal/service/<service>make fmtterrafmt fmt website/docs/actions/<action>.html.markdownterraform-provider-tfe (action_query_run.go, action_query_run_test.go), terraform-provider-vault (action_rotate_root.go)