Skip to content

Commit

Permalink
Refactor: associateCFnChildren() should be maintained in cfntemplate.go
Browse files Browse the repository at this point in the history
  • Loading branch information
a2ush committed May 8, 2024
1 parent 09d8c06 commit 601056c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
34 changes: 34 additions & 0 deletions internal/ctl/cfntemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,40 @@ func ensureSingleParent(template *TemplateStruct) {
}
}

func associateCFnChildren(template *TemplateStruct, ds definition.DefinitionStructure, resources map[string]types.Node) {

for logicalId, v := range template.Resources {

def, ok := ds.Definitions[v.Type]

if v.Type == "" || !ok {
log.Infof("%s is not defined in CloudFormation template or definition file. Skip process", logicalId)
continue
}

if !def.CFn.HasChildren {
log.Infof("%s cannot have children resource.", logicalId)
continue
}

if _, ok = resources[logicalId]; !ok {
log.Infof("%s is not defined as a resource. Skip process", logicalId)
continue
}

for _, child := range v.Children {
_, ok := resources[child]
if !ok {
log.Infof("%s does not have parent resource", child)
continue
}
log.Infof("Add child(%s) on %s", child, logicalId)

resources[logicalId].AddChild(resources[child])
}
}
}

func findRefs(t map[string]interface{}, fromName string) []string {
refs := make([]string, 0)
var subRe = regexp.MustCompile(`\$\{([^!].+?)\}`)
Expand Down
34 changes: 0 additions & 34 deletions internal/ctl/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,40 +248,6 @@ func associateChildren(template *TemplateStruct, resources map[string]types.Node
}
}

func associateCFnChildren(template *TemplateStruct, ds definition.DefinitionStructure, resources map[string]types.Node) {

for logicalId, v := range template.Resources {

def, ok := ds.Definitions[v.Type]

if v.Type == "" || !ok {
log.Infof("%s is not defined in CloudFormation template or definition file. Skip process", logicalId)
continue
}

if !def.CFn.HasChildren {
log.Infof("%s cannot have children resource.", logicalId)
continue
}

if _, ok = resources[logicalId]; !ok {
log.Infof("%s is not defined as a resource. Skip process", logicalId)
continue
}

for _, child := range v.Children {
_, ok := resources[child]
if !ok {
log.Infof("%s does not have parent resource", child)
continue
}
log.Infof("Add child(%s) on %s", child, logicalId)

resources[logicalId].AddChild(resources[child])
}
}
}

func loadLinks(template *TemplateStruct, resources map[string]types.Node) {

for _, v := range template.Links {
Expand Down

0 comments on commit 601056c

Please sign in to comment.