Resources API¶
Base classes and utilities for creating Terraform resources with full CRUD lifecycle management.
🤖 AI-Generated Content
This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.
Overview¶
Resources in Pyvider represent manageable infrastructure components that Terraform can plan and apply through Pyvider's async lifecycle.
Key Components¶
BaseResource- Base class for all resources@register_resource- Decorator for resource registration- Resource Context - Per-operation context with provider access
- Private State - Encrypted storage for sensitive data
- Lifecycle Protocols - Standard CRUD interfaces
Lifecycle Methods¶
Resources interact with Terraform via a plan/apply cycle:
- read(ctx: ResourceContext) — refresh the latest state (called by Terraform refresh and after apply)
- plan(ctx) — framework-provided method that calls _create/_update/_delete_plan hooks to build a planned state
- apply(ctx) — framework-provided method that calls _create_apply/_update_apply/_delete_apply hooks to enact the plan
Resource authors typically override:
- _create(ctx, base_plan) / _update(ctx, base_plan) / _delete_plan(ctx) to shape the plan output
- _create_apply(ctx) / _update_apply(ctx) / _delete_apply(ctx) to perform real API calls and return final state/private state tuples
See src/pyvider/resources/base.py for the exact signatures.
Usage Examples¶
Basic Resource Implementation¶
| Python | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
Resource with Private State¶
Resource with Validation¶
Resource with Import Support¶
Testing Resources¶
Related Guides¶
- Creating Resources - Complete resource development guide
- Best Practices - Resource best practices
- Testing Providers - Testing resources
- Error Handling - Resource error handling
- Security Best Practices - Secure resources