tf-doc-extractor is a command-line tool that generates Terraform examples from acceptance tests and import functions.
To install tf-doc-extractor, use the following command:
go install github.com/FrangipaneTeam/tf-doc-extractor@latestAdd the go:generate directive above your Terraform import function.
filenameis the current fileexample-diris the location of the Terraform example directory
//go:generate go run github.com/FrangipaneTeam/tf-doc-extractor@latest -filename $GOFILE -example-dir ../../../examples -resource
func (r *orgUserResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("user_name"), req, resp)
}Running go generate will create a file import.sh in ../../../examples/resources/cloudavenue_org_user with this content :
# use the user_name to import the resource
terraform import cloudavenue_org_user.example user_nameAdd the go:generate directive above your Terraform example in the test file. For example, with a test file named internal/tests/public_ip_datasource_test.go :
//go:generate go run github.com/FrangipaneTeam/tf-doc-extractor@latest -filename $GOFILE -example-dir ../../examples -test
const testAccPublicIPDataSourceConfig = `
data "cloudavenue_public_ip" "test" {}
`Running go generate will create a file resource.tf or data-source.tf in ../../examples/data-sources/cloudavenue_public_ip.
Pull requests are welcome! If you find a bug or would like to request a new feature, please open an issue.
Before submitting a pull request, please ensure that your changes are properly tested and that the documentation has been updated.