tfpdk

command module
v0.0.0-...-ca22424 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 20, 2022 License: MPL-2.0 Imports: 4 Imported by: 0

README

tfpdk

Terraform Provider Development Kit

DISCLAIMER: The author primarily works on the AzureRM Provider so this tool is heavily biased towards the code styles and requirements of that provider currently. Future development will look to genericise the output (eventually 😜)

NOTE: Expects to be run from the root of a validly named Terraform provider e.g. ./terraform-provider-myprovider

NOTE: Relies on a locally installed terraform binary and appropriately configured dev overrides file. This allows the Terraform binary to skip the init step by informing it where your compiled provider binary can be found. (you still currently need a local .tf file with your provider configured though, sorry!)

Run from the root of the provider project.

TODO

  • untyped resource template
  • go fmt outputs
  • Add new resources / data sources to appropriate registration
  • typed and untyped Data Sources
  • init a new provider - git clone scaffold?
  • optionally populate the Typed SDK into the init step?
  • Dynamically read provider name for item generation
  • Populate IDValidationFunc() in template for IDs (Pandora)
  • Clients?
  • Autocomplete CLI?
  • Spike doc generation
  • Extend doc gen to deal with Blocks
  • migrate to plugin sdk something else to read schema directly for doc gen as Terraform's JSON output lacks necessary detail. (e.g. timeouts, ForceNew flags etc)
  • update commands and templates to allow non-hashicorp providers and sources other than github (e.g. import paths)

Commands

Usage: tfpdk [--version] [--help] <command> [<args>]

Available commands are:
config            Generate a local config file for common options.  
datasource        creates boiler-plate Data Sources.  
document          generates documentation from a resource.  
init              initialises a new provider based on the scaffold project.  
resource          creates boiler-plate resources.  
servicepackage    Creates a directory for a new Service Package and scaffolds out the basics to use it.  

Usage Examples

Create a Typed Data Source for an existing Resource where the Resource's model is appropriate for use in the Data Source
tfpdk datasource -name ShinyNewService -servicepackage SomeCloudService -typed -useresourcemodel

Will create the following path {providername}/internal/services/SomeCloudService/shiny_new_service_data_source.go

Create an un-typed (traditional) resource
tfpdk resource -name ShinyNewService -servicepackage SomeCloudService

Will create the following path {providername}/internal/services/SomeCloudService/shiny_new_service_resource.go and update registration.go with the new resource in the SupportedResources() func e.g.

func (r Registration) SupportedResources() map[string]*pluginsdk.Resource {
	return map[string]*pluginsdk.Resource{
		"azurerm_shiny_new_service": resourceShinyNewService(),
	}
}
Create a typed updatable resource
tfpdk resource -name ShinyNewService -servicepackage SomeCloudService -has-update -typed

Will create the following path {providername}/internal/services/SomeCloudService/shiny_new_service_resource.go and update registration.go with the new resource in the Resources() func, e.g.

func (r Registration) Resources() []sdk.Resource {
	return []sdk.Resource{
		ShinyNewServiceResource{},
	}
}
Document your new resource (relies on the Description fields in your schema, so populate those for best effect)
tfpdk document -type resource -name ShinyNewService -id "00000000-0000-0000-0000-000000000000"
Generate a Local config to set options and paths
tfpdk config

will create .tfpdk.hcl in the root of the provider, which can be updated to configure provider specifics that may differ from the defaults. (by "defaults", I mean what we use on AzureRM), example output:

provider_name                   = "azurerm"
service_packages_path           = "internal/services"
provider_github_org             = "hashicorp"
docs_path                       = "docs"
resource_docs_directory_name    = "r"
data_source_docs_directory_name = "d"
use_typed_sdk                   = false

Note: Command line options override values from the config file.

Command Documentation

tfpdk [command]

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL