/
component_processor.go
58 lines (49 loc) 路 1.74 KB
/
component_processor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package component
import (
e "github.com/cloudposse/atmos/internal/exec"
c "github.com/cloudposse/atmos/pkg/config"
u "github.com/cloudposse/atmos/pkg/utils"
"github.com/pkg/errors"
)
// ProcessComponentInStack accepts a component and a stack name and returns the component configuration in the stack
func ProcessComponentInStack(component string, stack string) (map[string]any, error) {
var configAndStacksInfo c.ConfigAndStacksInfo
configAndStacksInfo.ComponentFromArg = component
configAndStacksInfo.Stack = stack
configAndStacksInfo.ComponentType = "terraform"
configAndStacksInfo, err := e.ProcessStacks(configAndStacksInfo, true)
if err != nil {
configAndStacksInfo.ComponentType = "helmfile"
configAndStacksInfo, err = e.ProcessStacks(configAndStacksInfo, true)
if err != nil {
u.PrintErrorToStdError(err)
return nil, err
}
}
return configAndStacksInfo.ComponentSection, nil
}
// ProcessComponentFromContext accepts context (namespace, tenant, environment, stage) and returns the component configuration in the stack
func ProcessComponentFromContext(
component string,
namespace string,
tenant string,
environment string,
stage string,
) (map[string]any, error) {
err := c.InitConfig()
if err != nil {
u.PrintErrorToStdError(err)
return nil, err
}
if len(c.Config.Stacks.NamePattern) < 1 {
er := errors.New("stack name pattern must be provided in 'stacks.name_pattern' CLI config or 'ATMOS_STACKS_NAME_PATTERN' ENV variable")
u.PrintErrorToStdError(er)
return nil, er
}
stack, err := c.GetStackNameFromContextAndStackNamePattern(namespace, tenant, environment, stage, c.Config.Stacks.NamePattern)
if err != nil {
u.PrintErrorToStdError(err)
return nil, err
}
return ProcessComponentInStack(component, stack)
}