本文整理汇总了Golang中github.com/xanzy/terraform-api/terraform.InstanceState.Attributes方法的典型用法代码示例。如果您正苦于以下问题:Golang InstanceState.Attributes方法的具体用法?Golang InstanceState.Attributes怎么用?Golang InstanceState.Attributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/xanzy/terraform-api/terraform.InstanceState
的用法示例。
在下文中一共展示了InstanceState.Attributes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: State
// State returns the new InstanceState after the diff and any Set
// calls.
func (d *ResourceData) State() *terraform.InstanceState {
var result terraform.InstanceState
result.ID = d.Id()
// If we have no ID, then this resource doesn't exist and we just
// return nil.
if result.ID == "" {
return nil
}
// In order to build the final state attributes, we read the full
// attribute set as a map[string]interface{}, write it to a MapFieldWriter,
// and then use that map.
rawMap := make(map[string]interface{})
for k := range d.schema {
source := getSourceSet
if d.partial {
source = getSourceState
if _, ok := d.partialMap[k]; ok {
source = getSourceSet
}
}
raw := d.get([]string{k}, source)
if raw.Exists && !raw.Computed {
rawMap[k] = raw.Value
if raw.ValueProcessed != nil {
rawMap[k] = raw.ValueProcessed
}
}
}
mapW := &MapFieldWriter{Schema: d.schema}
if err := mapW.WriteField(nil, rawMap); err != nil {
return nil
}
result.Attributes = mapW.Map()
result.Ephemeral.ConnInfo = d.ConnInfo()
// TODO: This is hacky and we can remove this when we have a proper
// state writer. We should instead have a proper StateFieldWriter
// and use that.
for k, schema := range d.schema {
if schema.Type != TypeMap {
continue
}
if result.Attributes[k] == "" {
delete(result.Attributes, k)
}
}
if v := d.Id(); v != "" {
result.Attributes["id"] = d.Id()
}
return &result
}
示例2: Apply
// Apply performs a create or update depending on the diff, and calls
// the proper function on the matching Resource.
func (m *Map) Apply(
info *terraform.InstanceInfo,
s *terraform.InstanceState,
d *terraform.InstanceDiff,
meta interface{}) (*terraform.InstanceState, error) {
r, ok := m.Mapping[info.Type]
if !ok {
return nil, fmt.Errorf("Unknown resource type: %s", info.Type)
}
if d.Destroy || d.RequiresNew() {
if s.ID != "" {
// Destroy the resource if it is created
err := r.Destroy(s, meta)
if err != nil {
return s, err
}
s.ID = ""
}
// If we're only destroying, and not creating, then return now.
// Otherwise, we continue so that we can create a new resource.
if !d.RequiresNew() {
return nil, nil
}
}
var result *terraform.InstanceState
var err error
if s.ID == "" {
result, err = r.Create(s, d, meta)
} else {
if r.Update == nil {
return s, fmt.Errorf(
"Resource type '%s' doesn't support update",
info.Type)
}
result, err = r.Update(s, d, meta)
}
if result != nil {
if result.Attributes == nil {
result.Attributes = make(map[string]string)
}
result.Attributes["id"] = result.ID
}
return result, err
}