helper/schema: nice error if update isn't supported
This commit is contained in:
parent
e2b8951a58
commit
2444986fe8
|
@ -2,6 +2,7 @@ package schema
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
@ -73,6 +74,10 @@ func (r *Resource) Apply(
|
||||||
// We're creating, it is a new resource.
|
// We're creating, it is a new resource.
|
||||||
err = r.Create(data, meta)
|
err = r.Create(data, meta)
|
||||||
} else {
|
} else {
|
||||||
|
if r.Update == nil {
|
||||||
|
return s, fmt.Errorf("%s doesn't support update", s.Type)
|
||||||
|
}
|
||||||
|
|
||||||
err = r.Update(data, meta)
|
err = r.Update(data, meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -186,6 +186,50 @@ func TestResourceApply_update(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestResourceApply_updateNoCallback(t *testing.T) {
|
||||||
|
r := &Resource{
|
||||||
|
Schema: map[string]*Schema{
|
||||||
|
"foo": &Schema{
|
||||||
|
Type: TypeInt,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
r.Update = nil
|
||||||
|
|
||||||
|
s := &terraform.ResourceState{
|
||||||
|
ID: "foo",
|
||||||
|
Attributes: map[string]string{
|
||||||
|
"foo": "12",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
d := &terraform.ResourceDiff{
|
||||||
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
||||||
|
"foo": &terraform.ResourceAttrDiff{
|
||||||
|
New: "13",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
actual, err := r.Apply(s, d, nil)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("should error")
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := &terraform.ResourceState{
|
||||||
|
ID: "foo",
|
||||||
|
Attributes: map[string]string{
|
||||||
|
"foo": "12",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
|
t.Fatalf("bad: %#v", actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestResourceInternalValidate(t *testing.T) {
|
func TestResourceInternalValidate(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
In *Resource
|
In *Resource
|
||||||
|
|
Loading…
Reference in New Issue