/terraform-plugin-sdk

Terraform Plugin SDK enables building plugins (providers) to manage any service providers or custom in-house solutions

Primary LanguageGoMozilla Public License 2.0MPL-2.0

PkgGoDev

Terraform Plugin SDK

This SDK enables building Terraform plugin which allows Terraform's users to manage existing and popular service providers as well as custom in-house solutions. The SDK is stable and broadly used across the provider ecosystem.

For new provider development it is recommended to investigate terraform-plugin-framework, which is a reimagined provider SDK that supports additional capabilities. Refer to the Which SDK Should I Use? documentation for more information about differences between SDKs.

Terraform itself is a tool for building, changing, and versioning infrastructure safely and efficiently. You can find more about Terraform on its website and its GitHub repository.

Apply LocalStack Patches to state.go

On you local repo set upstream to hashicorp/terraform-plugin-sdk. This will allow the script to find the remote tags and apply patches to it.

git remote add upstream git@github.com:hashicorp/terraform-plugin-sdk.git

Create your python environment.

make patch-install

Create tags to origin

make patch-create-tags

The script will look for required version that are not yet patched. A diff will then show as such allowing to review the changes.

Fetched from upstream: v2.7.1
found file at helper/resource/state.go
diff --git a/helper/resource/state.go b/helper/resource/state.go
index 6eda1993..3d8d1779 100644
--- a/helper/resource/state.go
+++ b/helper/resource/state.go
@@ -52,6 +52,17 @@ type StateChangeConf struct {
 //
 // Cancellation from the passed in context will cancel the refresh loop
 func (conf *StateChangeConf) WaitForStateContext(ctx context.Context) (interface{}, error) {
+       //
+       // Begining of patch
+       // 
+       // Remove the delay before first lookup.
+       conf.Delay = 0
+       // Remove the PollInterval and MinTimeout to always use terraform's default (exponential backoff retry).
+       conf.PollInterval = 0
+       conf.MinTimeout = 0
+       //
+       // End Of Patch
+       //
        log.Printf("[DEBUG] Waiting for state to become: %s", conf.Target)
 
        notfoundTick := 0


Modification to helper/resource/state.go
If approved press <enter>. Any other value will cancel the operation.
If <enter> is pressed the changes to this file will be commited and a tag will be created and pushed.

To add new tags to patch add to the REQUIRED_TAGS list in create_all_tags.py

Terraform CLI Compatibility

Terraform 0.12.0 or later is needed for version 2.0.0 and later of the Plugin SDK.

When running provider tests, Terraform 0.12.26 or later is needed for version 2.0.0 and later of the Plugin SDK. Users can still use any version after 0.12.0.

Go Compatibility

This project follows the support policy of Go as its support policy. The two latest major releases of Go are supported by the project.

Currently, that means Go 1.21 or later must be used when including this project as a dependency.

Getting Started

See the Call APIs with Terraform Providers guide on learn.hashicorp.com for a guided tour of provider development.

Documentation

See Extending Terraform section on the website.

Scope (Providers VS Core)

Terraform Core

  • acts as gRPC client
  • interacts with the user
  • parses (HCL/JSON) configuration
  • manages state as whole, asks Provider(s) to mutate provider-specific parts of state
  • handles backends & provisioners
  • handles inputs, outputs, modules, and functions
  • discovers Provider(s) and their versions per configuration
  • manages Provider(s) lifecycle (i.e. spins up & tears down provider process)
  • passes relevant parts of parsed (valid JSON/HCL) and interpolated configuration to Provider(s)
  • decides ordering of (Create, Read, Update, Delete) operations on resources and data sources
  • ...

Terraform Provider (via this SDK)

  • acts as gRPC server
  • executes any domain-specific logic based on received parsed configuration
    • (Create, Read, Update, Delete, Import, Validate) a Resource
    • Read a Data Source
  • tests domain-specific logic via provided acceptance test framework
  • provides Core updated state of a resource or data source and/or appropriate feedback in the form of validation or other errors

Migrating to SDK v1 from built-in SDK

Migrating to the standalone SDK v1 is covered on the Plugin SDK section of the website.

Migrating to SDK v2 from SDK v1

Migrating to the v2 release of the SDK is covered in the v2 Upgrade Guide of the website.

Versioning

The Terraform Plugin SDK is a Go module versioned using semantic versioning. See SUPPORT.md for information on our support policies.

Contributing

See .github/CONTRIBUTING.md

License

Mozilla Public License v2.0