func New()

in cft/graph/graph.go [38:91]


func New(t cft.Template) Graph {
	// Map out parameter and resource names so we know which is which
	entities := make(map[string]string)
	for typeName, entity := range t.Map() {
		if typeName != "Parameters" && typeName != "Resources" {
			continue
		}

		if entityTree, ok := entity.(map[string]interface{}); ok {
			for entityName := range entityTree {
				entities[entityName] = typeName
			}
		}
	}

	// Now find the deps
	graph := Graph{
		nodes: make(map[Node]map[Node]bool),
		order: make([]Node, 0),
	}

	for typeName, entity := range t.Map() {
		if typeName != "Resources" && typeName != "Outputs" {
			continue
		}

		if entityTree, ok := entity.(map[string]interface{}); ok {
			for fromName, res := range entityTree {
				from := Node{typeName, fromName}
				graph.link(from)

				resource := res.(map[string]interface{})
				for _, toName := range getRefs(resource) {
					toName = strings.Split(toName, ".")[0]

					toType, ok := entities[toName]

					if !ok {
						if strings.HasPrefix(toName, "AWS::") {
							toType = "Parameters"
						} else {
							config.Debugf("template has unresolved dependency '%s' at %s: %s", toName, typeName, fromName)
							continue
						}
					}

					graph.link(from, Node{toType, toName})
				}
			}
		}
	}

	return graph
}