Skip to content

Commit

Permalink
funcs/generated: Support pre-releases
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed May 9, 2023
1 parent 664a8e0 commit 467311b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 6 additions & 1 deletion internal/funcs/generated/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ This package can generate function signature files for Terraform >= 1.4 automati

It is intended to run whenever HashiCorp releases a new Terraform version. If the Terraform version contains updated function signatures, it generates a new file for that version. When no changes are detected, one should commit the version bump in `gen/gen.go`.

It may only work with full releases and will likely fail for pre-releases or versions containing metadata.
Pre-releases are accepted with the following caveats:

- The given pre-release version of Terraform is downloaded
- The pre-release part of the version is omitted in all other contexts (e.g. function name, file name, constraint etc.)

... meaning that e.g. `1.5.0-alpha20230504` downloads Terraform `1.5.0-alpha20230504` but assumes compatibility with `1.5.0`. Therefore, generating signatures based on pre-releases should be used with the assumption that those signatures won't change before the final release.

## Running

Expand Down
11 changes: 7 additions & 4 deletions internal/funcs/generated/gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ import (
tfjson "github.com/hashicorp/terraform-json"
)

var (
terraformVersion = version.Must(version.NewVersion("1.4.0"))
)

const (
terraformVersion = "1.4.0"
functionSignatureHash = "8877af98abc453ce29d43e390c71b97bceaf90563ed28cf575e0100288602e9d"
)

Expand All @@ -47,7 +50,7 @@ func main() {
return
}
log.Printf("generating new signatures for %q\n", newSignatureHash)
functionsFile := fmt.Sprintf("%s.go", terraformVersion)
functionsFile := fmt.Sprintf("%s.go", terraformVersion.Core().String())
err = writeFunctions(functionsFile, functions)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -79,7 +82,7 @@ func signaturesFromTerraform(ctx context.Context) (*tfjson.MetadataFunctions, er
&releases.ExactVersion{
Product: product.Terraform,
InstallDir: installDir,
Version: version.Must(version.NewVersion(terraformVersion)),
Version: terraformVersion,
},
})
if err != nil {
Expand Down Expand Up @@ -171,7 +174,7 @@ func {{ .FunctionName }}() map[string]schema.FunctionSignature {

var buf bytes.Buffer
err = tpl.Execute(&buf, data{
FunctionName: fmt.Sprintf("v%s_Functions", escapeVersion(terraformVersion)),
FunctionName: fmt.Sprintf("v%s_Functions", escapeVersion(terraformVersion.Core().String())),
Signatures: functions.Signatures,
})
if err != nil {
Expand Down

0 comments on commit 467311b

Please sign in to comment.