|
|
|
|
@ -7,6 +7,7 @@ import (
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/config"
|
|
|
|
|
"github.com/mitchellh/copystructure"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// ResourceProvisionerConfig is used to pair a provisioner
|
|
|
|
|
@ -93,6 +94,45 @@ func NewResourceConfig(c *config.RawConfig) *ResourceConfig {
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeepCopy performs a deep copy of the configuration. This makes it safe
|
|
|
|
|
// to modify any of the structures that are part of the resource config without
|
|
|
|
|
// affecting the original configuration.
|
|
|
|
|
func (c *ResourceConfig) DeepCopy() *ResourceConfig {
|
|
|
|
|
// Copy, this will copy all the exported attributes
|
|
|
|
|
copy, err := copystructure.Config{Lock: true}.Copy(c)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Force the type
|
|
|
|
|
result := copy.(*ResourceConfig)
|
|
|
|
|
|
|
|
|
|
// For the raw configuration, we can just use its own copy method
|
|
|
|
|
result.raw = c.raw.Copy()
|
|
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Equal checks the equality of two resource configs.
|
|
|
|
|
func (c *ResourceConfig) Equal(c2 *ResourceConfig) bool {
|
|
|
|
|
// Two resource configs if their exported properties are equal.
|
|
|
|
|
// We don't compare "raw" because it is never used again after
|
|
|
|
|
// initialization and for all intents and purposes they are equal
|
|
|
|
|
// if the exported properties are equal.
|
|
|
|
|
check := [][2]interface{}{
|
|
|
|
|
{c.ComputedKeys, c2.ComputedKeys},
|
|
|
|
|
{c.Raw, c2.Raw},
|
|
|
|
|
{c.Config, c2.Config},
|
|
|
|
|
}
|
|
|
|
|
for _, pair := range check {
|
|
|
|
|
if !reflect.DeepEqual(pair[0], pair[1]) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CheckSet checks that the given list of configuration keys is
|
|
|
|
|
// properly set. If not, errors are returned for each unset key.
|
|
|
|
|
//
|
|
|
|
|
|