本文整理匯總了Golang中github.com/hashicorp/terraform/terraform.ContextOpts.Config方法的典型用法代碼示例。如果您正苦於以下問題:Golang ContextOpts.Config方法的具體用法?Golang ContextOpts.Config怎麽用?Golang ContextOpts.Config使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hashicorp/terraform/terraform.ContextOpts
的用法示例。
在下文中一共展示了ContextOpts.Config方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: testStep
func testStep(
opts terraform.ContextOpts,
state *terraform.State,
step TestStep) (*terraform.State, error) {
// Write the configuration
cfgF, err := ioutil.TempFile("", "tf-test")
if err != nil {
return state, fmt.Errorf(
"Error creating temporary file for config: %s", err)
}
cfgPath := cfgF.Name() + ".tf"
cfgF.Close()
os.Remove(cfgF.Name())
cfgF, err = os.Create(cfgPath)
if err != nil {
return state, fmt.Errorf(
"Error creating temporary file for config: %s", err)
}
defer os.Remove(cfgPath)
_, err = io.Copy(cfgF, strings.NewReader(step.Config))
cfgF.Close()
if err != nil {
return state, fmt.Errorf(
"Error creating temporary file for config: %s", err)
}
// Parse the configuration
config, err := config.Load(cfgPath)
if err != nil {
return state, fmt.Errorf(
"Error parsing configuration: %s", err)
}
// Build the context
opts.Config = config
opts.State = state
ctx := terraform.NewContext(&opts)
if ws, es := ctx.Validate(); len(ws) > 0 || len(es) > 0 {
estrs := make([]string, len(es))
for i, e := range es {
estrs[i] = e.Error()
}
return state, fmt.Errorf(
"Configuration is invalid.\n\nWarnings: %#v\n\nErrors: %#v",
ws, estrs)
}
// Refresh!
state, err = ctx.Refresh()
if err != nil {
return state, fmt.Errorf(
"Error refreshing: %s", err)
}
// Plan!
if p, err := ctx.Plan(&terraform.PlanOpts{Destroy: step.Destroy}); err != nil {
return state, fmt.Errorf(
"Error planning: %s", err)
} else {
log.Printf("[WARN] Test: Step plan: %s", p)
}
// Apply!
state, err = ctx.Apply()
if err != nil {
return state, fmt.Errorf("Error applying: %s", err)
}
// Check! Excitement!
if step.Check != nil {
if err = step.Check(state); err != nil {
err = fmt.Errorf("Check failed: %s", err)
}
}
return state, err
}