当前位置: 首页>>代码示例>>Golang>>正文


Golang Tree.Name方法代码示例

本文整理汇总了Golang中github.com/hashicorp/terraform/config/module.Tree.Name方法的典型用法代码示例。如果您正苦于以下问题:Golang Tree.Name方法的具体用法?Golang Tree.Name怎么用?Golang Tree.Name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/hashicorp/terraform/config/module.Tree的用法示例。


在下文中一共展示了Tree.Name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: transformSingle

func (t *ModuleVariableTransformer) transformSingle(g *Graph, parent, m *module.Tree) error {
	// If we have no vars, we're done!
	vars := m.Config().Variables
	if len(vars) == 0 {
		log.Printf("[TRACE] Module %#v has no variables, skipping.", m.Path())
		return nil
	}

	// Look for usage of this module
	var mod *config.Module
	for _, modUse := range parent.Config().Modules {
		if modUse.Name == m.Name() {
			mod = modUse
			break
		}
	}
	if mod == nil {
		log.Printf("[INFO] Module %#v not used, not adding variables", m.Path())
		return nil
	}

	// Build the reference map so we can determine if we're referencing things.
	refMap := NewReferenceMap(g.Vertices())

	// Add all variables here
	for _, v := range vars {
		// Determine the value of the variable. If it isn't in the
		// configuration then it was never set and that's not a problem.
		var value *config.RawConfig
		if raw, ok := mod.RawConfig.Raw[v.Name]; ok {
			var err error
			value, err = config.NewRawConfig(map[string]interface{}{
				v.Name: raw,
			})
			if err != nil {
				// This shouldn't happen because it is already in
				// a RawConfig above meaning it worked once before.
				panic(err)
			}
		}

		// Build the node.
		//
		// NOTE: For now this is just an "applyable" variable. As we build
		// new graph builders for the other operations I suspect we'll
		// find a way to parameterize this, require new transforms, etc.
		node := &NodeApplyableModuleVariable{
			PathValue: normalizeModulePath(m.Path()),
			Config:    v,
			Value:     value,
			Module:    t.Module,
		}

		if !t.DisablePrune {
			// If the node is not referenced by anything, then we don't need
			// to include it since it won't be used.
			if matches := refMap.ReferencedBy(node); len(matches) == 0 {
				log.Printf(
					"[INFO] Not including %q in graph, nothing depends on it",
					dag.VertexName(node))
				continue
			}
		}

		// Add it!
		g.Add(node)
	}

	return nil
}
开发者ID:hooklift,项目名称:terraform,代码行数:70,代码来源:transform_module_variable.go


注:本文中的github.com/hashicorp/terraform/config/module.Tree.Name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。