Skip to content

Commit

Permalink
addrs: ModuleCallOutput to ConfigOutputValue translation
Browse files Browse the repository at this point in the history
The end-goal is to retrieve ConfigOutputValues for References.
This ties in with the work on deprecated outputs.
  • Loading branch information
DanielMSchmidt committed Dec 6, 2024
1 parent 0d6c1d3 commit 00eabce
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/addrs/module_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ func (m ModuleCallOutput) UniqueKey() UniqueKey {

func (m ModuleCallOutput) uniqueKeySigil() {}

func (m ModuleCallOutput) ConfigOutputValue() ConfigOutputValue {
return ConfigOutputValue{
Module: Module{m.Call.Name},
OutputValue: OutputValue{
Name: m.Name,
},
}
}

// ModuleCallInstanceOutput is the address of a particular named output produced by
// an instance of a module call.
type ModuleCallInstanceOutput struct {
Expand Down
41 changes: 41 additions & 0 deletions internal/addrs/module_call_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1

package addrs

import (
"testing"
)

func TestModuleCallOutput_ConfigOutputValue(t *testing.T) {
for name, tc := range map[string]struct {
input ModuleCallOutput
expeced ConfigOutputValue
}{
"simple": {
input: ModuleCallOutput{
Call: ModuleCall{
Name: "child_module",
},
Name: "output_name",
},
expeced: ConfigOutputValue{
Module: []string{"child_module"},
OutputValue: OutputValue{
Name: "output_name",
},
},
},
} {
t.Run(name, func(t *testing.T) {
result := tc.input.ConfigOutputValue()

if !result.Module.Equal(tc.expeced.Module) {
t.Fatalf("different module, expected %#v, got %#v", tc.expeced.Module, result.Module)
}
if !result.OutputValue.Equal(tc.expeced.OutputValue) {
t.Fatalf("different output, expected %#v, got %#v", tc.expeced.OutputValue, result.OutputValue)
}
})
}
}

0 comments on commit 00eabce

Please sign in to comment.