Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions cmd/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,9 @@ func runBundleNew(input *bundleNew) error {
}

localParams, paramsErr := params.GetFromPath(templateData.TemplateName, templateData.ExistingParamsPath)
if paramsErr != nil {
return fmt.Errorf("error getting params from path: %w", paramsErr)
if paramsErr == nil {
templateData.ParamsSchema = localParams
}
templateData.ParamsSchema = localParams

if newErr := cmdbundle.RunNew(cache, templateData); newErr != nil {
return fmt.Errorf("error running bundle new: %w", newErr)
Expand Down
5 changes: 5 additions & 0 deletions pkg/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ func GetFromPath(templateName, paramsPath string) (string, error) {

fmt.Print(importResult.PrettyDiags())

if importResult.Schema == nil {
fmt.Println("Params schema unable to be imported.")
return "", fmt.Errorf("failed to import params schema")
}

props := map[string]any{
"params": importResult.Schema,
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/provisioners/bicep.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ type BicepProvisioner struct{}
func (p *BicepProvisioner) ExportMassdriverInputs(stepPath string, variables map[string]any) error {
// read existing bicep params for this step
bicepParamsImport := bicep.BicepToSchema(path.Join(stepPath, "template.bicep"))
if bicepParamsImport.Schema == nil {
return errors.New("failed to read existing Bicep param declarations: " + bicepParamsImport.PrettyDiags())
}
Comment thread
chrisghill marked this conversation as resolved.
Comment thread
chrisghill marked this conversation as resolved.

newParams := FindMissingFromAirlock(variables, bicepParamsImport.Schema)
if len(newParams["properties"].(map[string]any)) == 0 {
Expand Down
3 changes: 3 additions & 0 deletions pkg/provisioners/opentofu.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ type OpentofuProvisioner struct{}
func (p *OpentofuProvisioner) ExportMassdriverInputs(stepPath string, variables map[string]any) error {
// read existing OpenTofu variables for this step
tofuVarsImport := opentofu.TofuToSchema(stepPath)
if tofuVarsImport.Schema == nil {
return errors.New("failed to read existing OpenTofu variable declarations: " + tofuVarsImport.PrettyDiags())
}

newVariables := FindMissingFromAirlock(variables, tofuVarsImport.Schema)
if len(newVariables["properties"].(map[string]any)) == 0 {
Expand Down
18 changes: 16 additions & 2 deletions pkg/provisioners/opentofu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path"
"reflect"
"slices"
"strings"
"testing"

"github.com/massdriver-cloud/mass/pkg/provisioners"
Expand All @@ -17,6 +18,7 @@ func TestOpentofuExportMassdriverInputs(t *testing.T) {
name string
variables map[string]any
want string
errString string
}
tests := []test{
{
Expand Down Expand Up @@ -65,6 +67,10 @@ variable "bar" {
},
want: ``,
},
{
name: "invalid",
errString: "failed to read existing OpenTofu variable declarations",
},
}

for _, tc := range tests {
Expand All @@ -83,8 +89,16 @@ variable "bar" {

prov := provisioners.OpentofuProvisioner{}
err = prov.ExportMassdriverInputs(testDir, tc.variables)
if err != nil {
t.Errorf("Error during validation: %s", err)
if tc.errString == "" && err != nil {
t.Errorf("Unexpected error during validation: %s", err)
}
if tc.errString != "" {
if err == nil {
t.Fatalf("Expected error but got none")
}
if !strings.Contains(err.Error(), tc.errString) {
t.Fatalf("got error %s want %s", err.Error(), tc.errString)
}
}

expectedFilepath := path.Join(testDir, "_massdriver_variables.tf")
Expand Down
3 changes: 3 additions & 0 deletions pkg/provisioners/testdata/opentofu/invalid.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "invalid" {
default = timestamp()
}
Loading