Skip to content

Commit

Permalink
Fix error when supplying multiple resources to manifest_decode()
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhouston committed Apr 8, 2024
1 parent 75fa00f commit 6700deb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/framework/provider/functions/manifest_decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (f ManifestDecodeFunction) Run(ctx context.Context, req function.RunRequest
return
} else if len(elems) > 1 {
resp.Error = function.NewFuncError("YAML manifest contains multiple resources: use decode_manifest_multi to decode manifests containing more than one resource")
return
}

dynamResp := types.DynamicValue(elems[0])
Expand Down
15 changes: 15 additions & 0 deletions internal/framework/provider/functions/manifest_decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"os"
"path"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand Down Expand Up @@ -44,6 +45,20 @@ func TestManifestDecode(t *testing.T) {
})
}

func TestManifestDecode_ErrorOnMulti(t *testing.T) {
t.Parallel()

resource.UnitTest(t, resource.TestCase{
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
Steps: []resource.TestStep{
{
Config: testManifestDecodeConfig("testdata/decode_multi.yaml"),
ExpectError: regexp.MustCompile(`YAML\s+manifest\s+contains\s+multiple\s+resources`),
},
},
})
}

func testManifestDecodeConfig(filename string) string {
cwd, _ := os.Getwd()
return fmt.Sprintf(`
Expand Down

0 comments on commit 6700deb

Please sign in to comment.