diff --git a/internal/funcs/generated/README.md b/internal/funcs/generated/README.md index d1fbb979..35e0f212 100644 --- a/internal/funcs/generated/README.md +++ b/internal/funcs/generated/README.md @@ -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 diff --git a/internal/funcs/generated/gen/gen.go b/internal/funcs/generated/gen/gen.go index 2cdd07ac..4bb53c3f 100644 --- a/internal/funcs/generated/gen/gen.go +++ b/internal/funcs/generated/gen/gen.go @@ -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" ) @@ -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) @@ -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 { @@ -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 {