speakeasy icon indicating copy to clipboard operation
speakeasy copied to clipboard

[SPE-3152] Automatically generate `import.sh` file to include documentation instructions for adding `id` field via the `import` block in Terraform

Open ThomasRooney opened this issue 2 years ago • 0 comments

@ThomasRooney said:

The docs only get automatically added in when there's an import.sh added to examples/resources/*/import.sh with instructions.

Though it's a good idea for speakeasy's generator to automatically make this file. It's a gap I didn't really notice before (or forgot about). Making a note to do that for end-users.

Generally the id field is used. It's referenced in the ImportState part off the resource.

func (r **YourResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp **resource.ImportStateResponse) {
	resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...)
}

And a user adds it in via the import block https://developer.hashicorp.com/terraform/language/import/generating-configuration#1-add-the-import-block

Import - Generating Configuration | Terraform | HashiCorp Developer

From SyncLinear.com | SPE-3152

ThomasRooney avatar Mar 25 '24 19:03 ThomasRooney