-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
function: Initial provider defined functions implementation (#889)
Reference: hashicorp/terraform-plugin-go#351 The next versions of the plugin protocol (5.5/6.5) include support for provider defined functions. This change includes initial implementation of that support including: - Temporarily pointing at terraform-plugin-go with provider function support (will be pointed at final terraform-plugin-go release before merge) - New `function` package with all exposed Go types for provider developers to implement provider functions - New `diag` package support for diagnostics with optional function argument information - Implementation of new `GetFunctions` and `CallFunction` RPCs in the internal framework server, protocol 5/6 servers, and data handling between all layers - Initial website documentation This functionality will be released as technical preview without compatibility promises until Terraform 1.8 is generally available. Go and website documentation include additional callouts about the compatibility of this functionality. Co-authored-by: Austin Valle <[email protected]>
- Loading branch information
1 parent
ce8a02d
commit 791e37b
Showing
157 changed files
with
15,542 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: ENHANCEMENTS | ||
body: 'diag: Added `NewArgumentErrorDiagnostic()` and `NewArgumentWarningDiagnostic()` | ||
functions, which create diagnostics with the function argument position set' | ||
time: 2023-12-11T12:50:57.570179-05:00 | ||
custom: | ||
Issue: "889" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: ENHANCEMENTS | ||
body: 'provider: Added `ProviderWithFunctions` interface for implementing provider | ||
defined functions' | ||
time: 2023-12-11T12:51:51.441373-05:00 | ||
custom: | ||
Issue: "889" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: ENHANCEMENTS | ||
body: 'diag: Added `(Diagnostics).AddArgumentError()` and `(Diagnostics).AddArgumentWarning()` | ||
methods for appending function argument diagnostics' | ||
time: 2023-12-11T12:58:43.277177-05:00 | ||
custom: | ||
Issue: "889" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
kind: FEATURES | ||
body: 'function: New package for implementing provider defined functions' | ||
time: 2023-12-11T12:51:22.409392-05:00 | ||
custom: | ||
Issue: "889" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: NOTES | ||
body: Provider-defined function support is in technical preview and offered without | ||
compatibility promises until Terraform 1.8 is generally available. | ||
time: 2023-12-14T08:29:31.188561-05:00 | ||
custom: | ||
Issue: "889" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package diag | ||
|
||
// NewArgumentErrorDiagnostic returns a new error severity diagnostic with the | ||
// given summary, detail, and function argument. | ||
func NewArgumentErrorDiagnostic(functionArgument int, summary string, detail string) DiagnosticWithFunctionArgument { | ||
return withFunctionArgument{ | ||
Diagnostic: NewErrorDiagnostic(summary, detail), | ||
functionArgument: functionArgument, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package diag | ||
|
||
// NewArgumentWarningDiagnostic returns a new warning severity diagnostic with | ||
// the given summary, detail, and function argument. | ||
func NewArgumentWarningDiagnostic(functionArgument int, summary string, detail string) DiagnosticWithFunctionArgument { | ||
return withFunctionArgument{ | ||
Diagnostic: NewWarningDiagnostic(summary, detail), | ||
functionArgument: functionArgument, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package diag | ||
|
||
var _ DiagnosticWithFunctionArgument = withFunctionArgument{} | ||
|
||
// withFunctionArgument wraps a diagnostic with function argument information. | ||
type withFunctionArgument struct { | ||
Diagnostic | ||
|
||
functionArgument int | ||
} | ||
|
||
// Equal returns true if the other diagnostic is wholly equivalent. | ||
func (d withFunctionArgument) Equal(other Diagnostic) bool { | ||
o, ok := other.(withFunctionArgument) | ||
|
||
if !ok { | ||
return false | ||
} | ||
|
||
if d.functionArgument != o.functionArgument { | ||
return false | ||
} | ||
|
||
if d.Diagnostic == nil { | ||
return d.Diagnostic == o.Diagnostic | ||
} | ||
|
||
return d.Diagnostic.Equal(o.Diagnostic) | ||
} | ||
|
||
// FunctionArgument returns the diagnostic function argument. | ||
func (d withFunctionArgument) FunctionArgument() int { | ||
return d.functionArgument | ||
} | ||
|
||
// WithFunctionArgument wraps a diagnostic with function argument information | ||
// or overwrites the function argument. | ||
func WithFunctionArgument(functionArgument int, d Diagnostic) DiagnosticWithFunctionArgument { | ||
wp, ok := d.(withFunctionArgument) | ||
|
||
if !ok { | ||
return withFunctionArgument{ | ||
Diagnostic: d, | ||
functionArgument: functionArgument, | ||
} | ||
} | ||
|
||
wp.functionArgument = functionArgument | ||
|
||
return wp | ||
} |
Oops, something went wrong.