opentofu/terraform/resource.go

32 lines
692 B
Go
Raw Normal View History

package terraform
2014-06-30 21:29:07 -05:00
import (
"fmt"
)
// Resource encapsulates a resource, its configuration, its provider,
// its current state, and potentially a desired diff from the state it
// wants to reach.
type Resource struct {
Id string
Config *ResourceConfig
Diff *ResourceDiff
Provider ResourceProvider
State *ResourceState
}
2014-06-30 21:29:07 -05:00
2014-06-30 22:59:23 -05:00
// Vars returns the mapping of variables that should be replaced in
// configuration based on the attributes of this resource.
2014-06-30 21:29:07 -05:00
func (r *Resource) Vars() map[string]string {
if r.State == nil {
return nil
}
vars := make(map[string]string)
for ak, av := range r.State.Attributes {
vars[fmt.Sprintf("%s.%s", r.Id, ak)] = av
}
return vars
}