Merge #3288: Disallow Update func when no updates are possible.

This commit is contained in:
Martin Atkins 2015-10-03 17:15:04 -07:00
commit 6e4b445b58
10 changed files with 44 additions and 33 deletions

View File

@ -19,7 +19,6 @@ func resourceArtifact() *schema.Resource {
return &schema.Resource{ return &schema.Resource{
Create: resourceArtifactRead, Create: resourceArtifactRead,
Read: resourceArtifactRead, Read: resourceArtifactRead,
Update: resourceArtifactRead,
Delete: resourceArtifactDelete, Delete: resourceArtifactDelete,
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{

View File

@ -15,8 +15,6 @@ func resourceAwsAppCookieStickinessPolicy() *schema.Resource {
// There is no concept of "updating" an App Stickiness policy in // There is no concept of "updating" an App Stickiness policy in
// the AWS API. // the AWS API.
Create: resourceAwsAppCookieStickinessPolicyCreate, Create: resourceAwsAppCookieStickinessPolicyCreate,
Update: resourceAwsAppCookieStickinessPolicyCreate,
Read: resourceAwsAppCookieStickinessPolicyRead, Read: resourceAwsAppCookieStickinessPolicyRead,
Delete: resourceAwsAppCookieStickinessPolicyDelete, Delete: resourceAwsAppCookieStickinessPolicyDelete,

View File

@ -15,8 +15,6 @@ func resourceAwsLBCookieStickinessPolicy() *schema.Resource {
// There is no concept of "updating" an LB Stickiness policy in // There is no concept of "updating" an LB Stickiness policy in
// the AWS API. // the AWS API.
Create: resourceAwsLBCookieStickinessPolicyCreate, Create: resourceAwsLBCookieStickinessPolicyCreate,
Update: resourceAwsLBCookieStickinessPolicyCreate,
Read: resourceAwsLBCookieStickinessPolicyRead, Read: resourceAwsLBCookieStickinessPolicyRead,
Delete: resourceAwsLBCookieStickinessPolicyDelete, Delete: resourceAwsLBCookieStickinessPolicyDelete,

View File

@ -16,7 +16,6 @@ func resourceAwsS3BucketObject() *schema.Resource {
return &schema.Resource{ return &schema.Resource{
Create: resourceAwsS3BucketObjectPut, Create: resourceAwsS3BucketObjectPut,
Read: resourceAwsS3BucketObjectRead, Read: resourceAwsS3BucketObjectRead,
Update: resourceAwsS3BucketObjectPut,
Delete: resourceAwsS3BucketObjectDelete, Delete: resourceAwsS3BucketObjectDelete,
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{

View File

@ -17,8 +17,6 @@ func resourceAwsVpnConnectionRoute() *schema.Resource {
// You can't update a route. You can just delete one and make // You can't update a route. You can just delete one and make
// a new one. // a new one.
Create: resourceAwsVpnConnectionRouteCreate, Create: resourceAwsVpnConnectionRouteCreate,
Update: resourceAwsVpnConnectionRouteCreate,
Read: resourceAwsVpnConnectionRouteRead, Read: resourceAwsVpnConnectionRouteRead,
Delete: resourceAwsVpnConnectionRouteDelete, Delete: resourceAwsVpnConnectionRouteDelete,

View File

@ -13,7 +13,6 @@ func resourceAzureStorageBlob() *schema.Resource {
return &schema.Resource{ return &schema.Resource{
Create: resourceAzureStorageBlobCreate, Create: resourceAzureStorageBlobCreate,
Read: resourceAzureStorageBlobRead, Read: resourceAzureStorageBlobRead,
Update: resourceAzureStorageBlobUpdate,
Exists: resourceAzureStorageBlobExists, Exists: resourceAzureStorageBlobExists,
Delete: resourceAzureStorageBlobDelete, Delete: resourceAzureStorageBlobDelete,
@ -122,17 +121,6 @@ func resourceAzureStorageBlobRead(d *schema.ResourceData, meta interface{}) erro
return nil return nil
} }
// resourceAzureStorageBlobUpdate does all the necessary API calls to
// update a blob on Azure.
func resourceAzureStorageBlobUpdate(d *schema.ResourceData, meta interface{}) error {
// NOTE: although empty as most parameters have ForceNew set; this is
// still required in case of changes to the storage_service_key
// run the ExistsFunc beforehand to ensure the resource's existence nonetheless:
_, err := resourceAzureStorageBlobExists(d, meta)
return err
}
// resourceAzureStorageBlobExists does all the necessary API calls to // resourceAzureStorageBlobExists does all the necessary API calls to
// check for the existence of the blob on Azure. // check for the existence of the blob on Azure.
func resourceAzureStorageBlobExists(d *schema.ResourceData, meta interface{}) (bool, error) { func resourceAzureStorageBlobExists(d *schema.ResourceData, meta interface{}) (bool, error) {

View File

@ -1,8 +1,8 @@
package google package google
import ( import (
"os"
"fmt" "fmt"
"os"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -13,7 +13,6 @@ func resourceStorageBucketObject() *schema.Resource {
return &schema.Resource{ return &schema.Resource{
Create: resourceStorageBucketObjectCreate, Create: resourceStorageBucketObjectCreate,
Read: resourceStorageBucketObjectRead, Read: resourceStorageBucketObjectRead,
Update: resourceStorageBucketObjectUpdate,
Delete: resourceStorageBucketObjectDelete, Delete: resourceStorageBucketObjectDelete,
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
@ -107,12 +106,6 @@ func resourceStorageBucketObjectRead(d *schema.ResourceData, meta interface{}) e
return nil return nil
} }
func resourceStorageBucketObjectUpdate(d *schema.ResourceData, meta interface{}) error {
// The Cloud storage API doesn't support updating object data contents,
// only metadata. So once we implement metadata we'll have work to do here
return nil
}
func resourceStorageBucketObjectDelete(d *schema.ResourceData, meta interface{}) error { func resourceStorageBucketObjectDelete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config) config := meta.(*Config)

View File

@ -16,7 +16,6 @@ func resource() *schema.Resource {
return &schema.Resource{ return &schema.Resource{
Create: resourceCreate, Create: resourceCreate,
Read: resourceRead, Read: resourceRead,
Update: resourceUpdate,
Delete: resourceDelete, Delete: resourceDelete,
Schema: map[string]*schema.Schema{}, Schema: map[string]*schema.Schema{},
@ -32,10 +31,6 @@ func resourceRead(d *schema.ResourceData, meta interface{}) error {
return nil return nil
} }
func resourceUpdate(d *schema.ResourceData, meta interface{}) error {
return nil
}
func resourceDelete(d *schema.ResourceData, meta interface{}) error { func resourceDelete(d *schema.ResourceData, meta interface{}) error {
d.SetId("") d.SetId("")
return nil return nil

View File

@ -244,7 +244,20 @@ func (r *Resource) InternalValidate(topSchemaMap schemaMap) error {
return fmt.Errorf( return fmt.Errorf(
"No Update defined, must set ForceNew on: %#v", nonForceNewAttrs) "No Update defined, must set ForceNew on: %#v", nonForceNewAttrs)
} }
} else {
nonUpdateableAttrs := make([]string, 0)
for k, v := range r.Schema {
if v.ForceNew || (v.Computed && !v.Optional) {
nonUpdateableAttrs = append(nonUpdateableAttrs, k)
}
}
updateableAttrs := len(r.Schema) - len(nonUpdateableAttrs)
if updateableAttrs == 0 {
return fmt.Errorf(
"All fields are ForceNew or Computed w/out Optional, Update is superfluous")
}
} }
tsm = schemaMap(r.Schema) tsm = schemaMap(r.Schema)
} }

View File

@ -335,6 +335,36 @@ func TestResourceInternalValidate(t *testing.T) {
}, },
true, true,
}, },
// Update undefined for non-ForceNew field
{
&Resource{
Create: func(d *ResourceData, meta interface{}) error { return nil },
Schema: map[string]*Schema{
"boo": &Schema{
Type: TypeInt,
Optional: true,
},
},
},
true,
},
// Update defined for ForceNew field
{
&Resource{
Create: func(d *ResourceData, meta interface{}) error { return nil },
Update: func(d *ResourceData, meta interface{}) error { return nil },
Schema: map[string]*Schema{
"goo": &Schema{
Type: TypeInt,
Optional: true,
ForceNew: true,
},
},
},
true,
},
} }
for i, tc := range cases { for i, tc := range cases {