-
-
Notifications
You must be signed in to change notification settings - Fork 91
/
component_processor.go
81 lines (68 loc) · 2.38 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package component
import (
"github.com/pkg/errors"
e "github.com/cloudposse/atmos/internal/exec"
cfg "github.com/cloudposse/atmos/pkg/config"
"github.com/cloudposse/atmos/pkg/schema"
u "github.com/cloudposse/atmos/pkg/utils"
)
// ProcessComponentInStack accepts a component and a stack name and returns the component configuration in the stack
func ProcessComponentInStack(
component string,
stack string,
atmosCliConfigPath string,
atmosBasePath string,
) (map[string]any, error) {
var configAndStacksInfo schema.ConfigAndStacksInfo
configAndStacksInfo.ComponentFromArg = component
configAndStacksInfo.Stack = stack
configAndStacksInfo.AtmosCliConfigPath = atmosCliConfigPath
configAndStacksInfo.AtmosBasePath = atmosBasePath
cliConfig, err := cfg.InitCliConfig(configAndStacksInfo, true)
if err != nil {
u.LogError(err)
return nil, err
}
configAndStacksInfo.ComponentType = "terraform"
configAndStacksInfo, err = e.ProcessStacks(cliConfig, configAndStacksInfo, true)
if err != nil {
configAndStacksInfo.ComponentType = "helmfile"
configAndStacksInfo, err = e.ProcessStacks(cliConfig, configAndStacksInfo, true)
if err != nil {
u.LogError(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,
atmosCliConfigPath string,
atmosBasePath string,
) (map[string]any, error) {
var configAndStacksInfo schema.ConfigAndStacksInfo
configAndStacksInfo.ComponentFromArg = component
configAndStacksInfo.AtmosCliConfigPath = atmosCliConfigPath
configAndStacksInfo.AtmosBasePath = atmosBasePath
cliConfig, err := cfg.InitCliConfig(configAndStacksInfo, true)
if err != nil {
u.LogError(err)
return nil, err
}
if len(cliConfig.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.LogError(er)
return nil, er
}
stack, err := cfg.GetStackNameFromContextAndStackNamePattern(namespace, tenant, environment, stage, cliConfig.Stacks.NamePattern)
if err != nil {
u.LogError(err)
return nil, err
}
return ProcessComponentInStack(component, stack, atmosCliConfigPath, atmosBasePath)
}