helper/schema: Review -> CustomizeDiff
Restoring the naming of this field in the resource back to CustomizeDiff, as this is generally more descriptive of the process that's happening, despite the lengthy name.
This commit is contained in:
parent
09e2109ff8
commit
529d7e6dae
|
@ -8,11 +8,11 @@ import (
|
||||||
|
|
||||||
func testResourceCustomDiff() *schema.Resource {
|
func testResourceCustomDiff() *schema.Resource {
|
||||||
return &schema.Resource{
|
return &schema.Resource{
|
||||||
Create: testResourceCustomDiffCreate,
|
Create: testResourceCustomDiffCreate,
|
||||||
Read: testResourceCustomDiffRead,
|
Read: testResourceCustomDiffRead,
|
||||||
Review: testResourceCustomDiffReview,
|
CustomizeDiff: testResourceCustomDiffCustomizeDiff,
|
||||||
Update: testResourceCustomDiffUpdate,
|
Update: testResourceCustomDiffUpdate,
|
||||||
Delete: testResourceCustomDiffDelete,
|
Delete: testResourceCustomDiffDelete,
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"required": {
|
"required": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
@ -57,7 +57,7 @@ func testResourceCustomDiffRead(d *schema.ResourceData, meta interface{}) error
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func testResourceCustomDiffReview(d *schema.ResourceDiff, meta interface{}) error {
|
func testResourceCustomDiffCustomizeDiff(d *schema.ResourceDiff, meta interface{}) error {
|
||||||
if d.Get("veto").(bool) == true {
|
if d.Get("veto").(bool) == true {
|
||||||
return fmt.Errorf("veto is true, diff vetoed")
|
return fmt.Errorf("veto is true, diff vetoed")
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,16 +85,16 @@ type Resource struct {
|
||||||
Delete DeleteFunc
|
Delete DeleteFunc
|
||||||
Exists ExistsFunc
|
Exists ExistsFunc
|
||||||
|
|
||||||
// Review is a custom function for "reviewing" the diff that Terraform has
|
// CustomizeDiff is a custom function for working with the diff that
|
||||||
// created for this resource - it can be used to customize the diff that has
|
// Terraform has created for this resource - it can be used to customize the
|
||||||
// been created, diff values not controlled by configuration, or even veto
|
// diff that has been created, diff values not controlled by configuration,
|
||||||
// the diff altogether and abort the plan. It is passed a *ResourceDiff, a
|
// or even veto the diff altogether and abort the plan. It is passed a
|
||||||
// structure similar to ResourceData but lacking most write functions,
|
// *ResourceDiff, a structure similar to ResourceData but lacking most write
|
||||||
// allowing the provider to customize the diff only.
|
// functions, allowing the provider to customize the diff only.
|
||||||
//
|
//
|
||||||
// For the most part, only computed fields can be customized by this
|
// For the most part, only computed fields can be customized by this
|
||||||
// function.
|
// function.
|
||||||
Review ReviewFunc
|
CustomizeDiff CustomizeDiffFunc
|
||||||
|
|
||||||
// Importer is the ResourceImporter implementation for this resource.
|
// Importer is the ResourceImporter implementation for this resource.
|
||||||
// If this is nil, then this resource does not support importing. If
|
// If this is nil, then this resource does not support importing. If
|
||||||
|
@ -138,7 +138,7 @@ type StateMigrateFunc func(
|
||||||
int, *terraform.InstanceState, interface{}) (*terraform.InstanceState, error)
|
int, *terraform.InstanceState, interface{}) (*terraform.InstanceState, error)
|
||||||
|
|
||||||
// See Resource documentation.
|
// See Resource documentation.
|
||||||
type ReviewFunc func(*ResourceDiff, interface{}) error
|
type CustomizeDiffFunc func(*ResourceDiff, interface{}) error
|
||||||
|
|
||||||
// Apply creates, updates, and/or deletes a resource.
|
// Apply creates, updates, and/or deletes a resource.
|
||||||
func (r *Resource) Apply(
|
func (r *Resource) Apply(
|
||||||
|
@ -229,7 +229,7 @@ func (r *Resource) Diff(
|
||||||
return nil, fmt.Errorf("[ERR] Error decoding timeout: %s", err)
|
return nil, fmt.Errorf("[ERR] Error decoding timeout: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
instanceDiff, err := schemaMap(r.Schema).Diff(s, c, r.Review, meta)
|
instanceDiff, err := schemaMap(r.Schema).Diff(s, c, r.CustomizeDiff, meta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return instanceDiff, err
|
return instanceDiff, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -266,7 +266,7 @@ func TestResourceDiff_CustomizeFunc(t *testing.T) {
|
||||||
|
|
||||||
var called bool
|
var called bool
|
||||||
|
|
||||||
r.Review = func(d *ResourceDiff, m interface{}) error {
|
r.CustomizeDiff = func(d *ResourceDiff, m interface{}) error {
|
||||||
called = true
|
called = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -386,7 +386,7 @@ func (m *schemaMap) DeepCopy() schemaMap {
|
||||||
func (m schemaMap) Diff(
|
func (m schemaMap) Diff(
|
||||||
s *terraform.InstanceState,
|
s *terraform.InstanceState,
|
||||||
c *terraform.ResourceConfig,
|
c *terraform.ResourceConfig,
|
||||||
review ReviewFunc,
|
customizeDiff CustomizeDiffFunc,
|
||||||
meta interface{}) (*terraform.InstanceDiff, error) {
|
meta interface{}) (*terraform.InstanceDiff, error) {
|
||||||
result := new(terraform.InstanceDiff)
|
result := new(terraform.InstanceDiff)
|
||||||
result.Attributes = make(map[string]*terraform.ResourceAttrDiff)
|
result.Attributes = make(map[string]*terraform.ResourceAttrDiff)
|
||||||
|
@ -411,10 +411,10 @@ func (m schemaMap) Diff(
|
||||||
|
|
||||||
// If this is a non-destroy diff, call any custom diff logic that has been
|
// If this is a non-destroy diff, call any custom diff logic that has been
|
||||||
// defined.
|
// defined.
|
||||||
if !result.DestroyTainted && review != nil {
|
if !result.DestroyTainted && customizeDiff != nil {
|
||||||
mc := m.DeepCopy()
|
mc := m.DeepCopy()
|
||||||
rd := newResourceDiff(mc, c, s, result)
|
rd := newResourceDiff(mc, c, s, result)
|
||||||
if err := review(rd, meta); err != nil {
|
if err := customizeDiff(rd, meta); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, k := range rd.UpdatedKeys() {
|
for _, k := range rd.UpdatedKeys() {
|
||||||
|
@ -451,10 +451,10 @@ func (m schemaMap) Diff(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-run customization
|
// Re-run customization
|
||||||
if !result2.DestroyTainted && review != nil {
|
if !result2.DestroyTainted && customizeDiff != nil {
|
||||||
mc := m.DeepCopy()
|
mc := m.DeepCopy()
|
||||||
rd := newResourceDiff(mc, c, d.state, result2)
|
rd := newResourceDiff(mc, c, d.state, result2)
|
||||||
if err := review(rd, meta); err != nil {
|
if err := customizeDiff(rd, meta); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, k := range rd.UpdatedKeys() {
|
for _, k := range rd.UpdatedKeys() {
|
||||||
|
|
|
@ -139,7 +139,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
||||||
State *terraform.InstanceState
|
State *terraform.InstanceState
|
||||||
Config map[string]interface{}
|
Config map[string]interface{}
|
||||||
ConfigVariables map[string]ast.Variable
|
ConfigVariables map[string]ast.Variable
|
||||||
Review ReviewFunc
|
CustomizeDiff CustomizeDiffFunc
|
||||||
Diff *terraform.InstanceDiff
|
Diff *terraform.InstanceDiff
|
||||||
Err bool
|
Err bool
|
||||||
}{
|
}{
|
||||||
|
@ -2827,7 +2827,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
Name: "overridden diff with a Review function, ForceNew not in schema",
|
Name: "overridden diff with a CustomizeDiff function, ForceNew not in schema",
|
||||||
Schema: map[string]*Schema{
|
Schema: map[string]*Schema{
|
||||||
"availability_zone": &Schema{
|
"availability_zone": &Schema{
|
||||||
Type: TypeString,
|
Type: TypeString,
|
||||||
|
@ -2842,7 +2842,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
||||||
"availability_zone": "foo",
|
"availability_zone": "foo",
|
||||||
},
|
},
|
||||||
|
|
||||||
Review: func(d *ResourceDiff, meta interface{}) error {
|
CustomizeDiff: func(d *ResourceDiff, meta interface{}) error {
|
||||||
if err := d.SetNew("availability_zone", "bar"); err != nil {
|
if err := d.SetNew("availability_zone", "bar"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -2866,7 +2866,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
Name: "overridden diff with a Review function, ForceNew in schema",
|
Name: "overridden diff with a CustomizeDiff function, ForceNew in schema",
|
||||||
Schema: map[string]*Schema{
|
Schema: map[string]*Schema{
|
||||||
"availability_zone": &Schema{
|
"availability_zone": &Schema{
|
||||||
Type: TypeString,
|
Type: TypeString,
|
||||||
|
@ -2882,7 +2882,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
||||||
"availability_zone": "foo",
|
"availability_zone": "foo",
|
||||||
},
|
},
|
||||||
|
|
||||||
Review: func(d *ResourceDiff, meta interface{}) error {
|
CustomizeDiff: func(d *ResourceDiff, meta interface{}) error {
|
||||||
if err := d.SetNew("availability_zone", "bar"); err != nil {
|
if err := d.SetNew("availability_zone", "bar"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -2903,7 +2903,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
Name: "required field with computed diff added with Review function",
|
Name: "required field with computed diff added with CustomizeDiff function",
|
||||||
Schema: map[string]*Schema{
|
Schema: map[string]*Schema{
|
||||||
"ami_id": &Schema{
|
"ami_id": &Schema{
|
||||||
Type: TypeString,
|
Type: TypeString,
|
||||||
|
@ -2921,7 +2921,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
||||||
"ami_id": "foo",
|
"ami_id": "foo",
|
||||||
},
|
},
|
||||||
|
|
||||||
Review: func(d *ResourceDiff, meta interface{}) error {
|
CustomizeDiff: func(d *ResourceDiff, meta interface{}) error {
|
||||||
if err := d.SetNew("instance_id", "bar"); err != nil {
|
if err := d.SetNew("instance_id", "bar"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -2945,7 +2945,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
Name: "Set ForceNew only marks the changing element as ForceNew - ReviewFunc edition",
|
Name: "Set ForceNew only marks the changing element as ForceNew - CustomizeDiffFunc edition",
|
||||||
Schema: map[string]*Schema{
|
Schema: map[string]*Schema{
|
||||||
"ports": &Schema{
|
"ports": &Schema{
|
||||||
Type: TypeSet,
|
Type: TypeSet,
|
||||||
|
@ -2971,7 +2971,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
||||||
"ports": []interface{}{5, 2, 6},
|
"ports": []interface{}{5, 2, 6},
|
||||||
},
|
},
|
||||||
|
|
||||||
Review: func(d *ResourceDiff, meta interface{}) error {
|
CustomizeDiff: func(d *ResourceDiff, meta interface{}) error {
|
||||||
if err := d.SetNew("ports", []interface{}{5, 2, 1}); err != nil {
|
if err := d.SetNew("ports", []interface{}{5, 2, 1}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -3011,7 +3011,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
Name: "tainted resource does not run ReviewFunc",
|
Name: "tainted resource does not run CustomizeDiffFunc",
|
||||||
Schema: map[string]*Schema{},
|
Schema: map[string]*Schema{},
|
||||||
|
|
||||||
State: &terraform.InstanceState{
|
State: &terraform.InstanceState{
|
||||||
|
@ -3023,7 +3023,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
||||||
|
|
||||||
Config: map[string]interface{}{},
|
Config: map[string]interface{}{},
|
||||||
|
|
||||||
Review: func(d *ResourceDiff, meta interface{}) error {
|
CustomizeDiff: func(d *ResourceDiff, meta interface{}) error {
|
||||||
return errors.New("diff customization should not have run")
|
return errors.New("diff customization should not have run")
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -3036,7 +3036,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
Name: "NewComputed based on a conditional with ReviewFunc",
|
Name: "NewComputed based on a conditional with CustomizeDiffFunc",
|
||||||
Schema: map[string]*Schema{
|
Schema: map[string]*Schema{
|
||||||
"etag": &Schema{
|
"etag": &Schema{
|
||||||
Type: TypeString,
|
Type: TypeString,
|
||||||
|
@ -3060,7 +3060,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
||||||
"etag": "bar",
|
"etag": "bar",
|
||||||
},
|
},
|
||||||
|
|
||||||
Review: func(d *ResourceDiff, meta interface{}) error {
|
CustomizeDiff: func(d *ResourceDiff, meta interface{}) error {
|
||||||
if d.HasChange("etag") {
|
if d.HasChange("etag") {
|
||||||
d.SetNewComputed("version_id")
|
d.SetNewComputed("version_id")
|
||||||
}
|
}
|
||||||
|
@ -3104,7 +3104,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
||||||
"foo": "baz",
|
"foo": "baz",
|
||||||
},
|
},
|
||||||
|
|
||||||
Review: func(d *ResourceDiff, meta interface{}) error {
|
CustomizeDiff: func(d *ResourceDiff, meta interface{}) error {
|
||||||
return fmt.Errorf("diff vetoed")
|
return fmt.Errorf("diff vetoed")
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -3125,7 +3125,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
d, err := schemaMap(tc.Schema).Diff(tc.State, terraform.NewResourceConfig(c), tc.Review, nil)
|
d, err := schemaMap(tc.Schema).Diff(tc.State, terraform.NewResourceConfig(c), tc.CustomizeDiff, nil)
|
||||||
if err != nil != tc.Err {
|
if err != nil != tc.Err {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue