Skip to content

Commit

Permalink
Add support for provider-defined functions (#10013)
Browse files Browse the repository at this point in the history
* Update provider to support provider functions

* Remove unused import

* Add ability to copy .go files in functions package into downstream
  • Loading branch information
SarahFrench authored Feb 22, 2024
1 parent 566f948 commit 2b6ef53
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
6 changes: 6 additions & 0 deletions mmv1/provider/terraform/common~compile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@
-%>
'<%= dir -%>/<%= fname.delete_suffix(".erb") -%>': 'third_party/terraform/framework_models/<%= fname -%>'
<% end -%>
<%
Dir["third_party/terraform/functions/*.go.erb"].each do |file_path|
fname = file_path.split('/')[-1]
-%>
'<%= dir -%>/functions/<%= fname.delete_suffix(".erb") -%>': 'third_party/terraform/functions/<%= fname -%>'
<% end -%>
<%
Dir["third_party/terraform/scripts/**/*.erb"].each do |file_path|
fname = file_path.delete_prefix("third_party/terraform/")
Expand Down
7 changes: 7 additions & 0 deletions mmv1/provider/terraform/common~copy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@
'<%= dir -%>/envvar/<%= fname -%>': 'third_party/terraform/envvar/<%= fname -%>'
<% end -%>

<%
Dir["third_party/terraform/functions/*.go"].each do |file_path|
fname = file_path.split('/')[-1]
-%>
'<%= dir -%>/functions/<%= fname -%>': 'third_party/terraform/functions/<%= fname -%>'
<% end -%>

<%
Dir["third_party/terraform/scripts/**/*.*"].each do |file_path|
next if file_path.end_with?('.erb')
Expand Down
1 change: 1 addition & 0 deletions mmv1/third_party/terraform/functions/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package functions
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/function"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-framework/provider/metaschema"
Expand All @@ -28,6 +29,7 @@ import (
// Ensure the implementation satisfies the expected interfaces
var (
_ provider.ProviderWithMetaSchema = &FrameworkProvider{}
_ provider.ProviderWithFunctions = &FrameworkProvider{}
)

// New is a helper function to simplify provider server and testing implementation.
Expand Down Expand Up @@ -294,5 +296,10 @@ func (p *FrameworkProvider) DataSources(_ context.Context) []func() datasource.D

// Resources defines the resources implemented in the provider.
func (p *FrameworkProvider) Resources(_ context.Context) []func() resource.Resource {
return nil
return nil
}

// Functions defines the provider functions implemented in the provider.
func (p *FrameworkProvider) Functions(_ context.Context) []func() function.Function {
return nil
}

0 comments on commit 2b6ef53

Please sign in to comment.