Prompt file imported from Arubacloud/terraform-provider-arubacloud (
.github/prompts/new-resource.prompt.md). Copyright stays with the author.
Read ai/ARCHITECTURE.md and ai/CONVENTIONS.md before starting.
New Resource Specification
Resource name (snake_case):
Terraform type: arubacloud_{name}
SDK service accessor: client.Client.From{Service}()
SDK resource accessor: .{Resource}()
Fields:
| Attribute | Type | Required/Optional/Computed | Notes |
|---|---|---|---|
id |
string | Computed | Set from *response.Data.Metadata.ID |
uri |
string | Computed | Set from *response.Data.Metadata.URI |
project_id |
string | Required | |
Immutable fields (require replace):
Implementation Steps
-
Create
internal/provider/{name}_resource.gowith:{Type}ResourceModelstruct (all fields astypes.*withtfsdktags){Type}Resourcestruct holdingclient *ArubaCloudClient- All required interface methods:
Metadata,Schema,Configure,Create,Read,Update,Delete,ImportState
-
Schema rules:
- Every attribute must have
MarkdownDescription - Order:
id,uri(computed) → required → optional - Add
stringplanmodifier.UseStateForUnknown()on all computed fields - Add
RequiresReplace()on immutable fields - Add
stringvalidator.OneOf(...)on constrained string fields
- Every attribute must have
-
Create lifecycle:
- Read plan → build SDK request → call
Create()→CheckResponse[T]()→ extract ID →WaitForResourceActive()→ re-read viaGet()→ set state
- Read plan → build SDK request → call
-
Read lifecycle:
- Read state → call
Get()→ if 404 →resp.State.RemoveResource(ctx)→ map fields → set state
- Read state → call
-
Delete lifecycle:
- Read state → call
Delete()→CheckResponse[T]()→WaitForResourceActive()(wait for 404) or simple poll
- Read state → call
-
Register the new resource in
provider.goResources()factory slice. -
Add an example in
examples/resources/arubacloud_{name}/resource.tf. -
Run
make build→make test→make generate(updates docs).
Error Handling Pattern
providerErr := CheckResponse[sdktypes.YourResponseType](response, err)
if providerErr != nil {
resp.Diagnostics.AddError("Failed to create {Name}", providerErr.Error())
return
}