From a006a6a399b944d1a48ac8545b4e92abd5e91085 Mon Sep 17 00:00:00 2001 From: Lars Wander Date: Tue, 5 Jan 2016 11:37:52 -0500 Subject: [PATCH] provider/google: Fix project metadata sshkeys from showing up --- builtin/providers/google/metadata.go | 6 ++++-- builtin/providers/google/resource_compute_instance.go | 2 +- .../providers/google/resource_compute_project_metadata.go | 2 +- .../google/resource_compute_project_metadata_test.go | 6 ------ 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/builtin/providers/google/metadata.go b/builtin/providers/google/metadata.go index e75c45022..e2ebd18a3 100644 --- a/builtin/providers/google/metadata.go +++ b/builtin/providers/google/metadata.go @@ -60,11 +60,13 @@ func MetadataUpdate(oldMDMap map[string]interface{}, newMDMap map[string]interfa } // Format metadata from the server data format -> schema data format -func MetadataFormatSchema(md *compute.Metadata) map[string]interface{} { +func MetadataFormatSchema(curMDMap map[string]interface{}, md *compute.Metadata) map[string]interface{} { newMD := make(map[string]interface{}) for _, kv := range md.Items { - newMD[kv.Key] = *kv.Value + if _, ok := curMDMap[kv.Key]; ok { + newMD[kv.Key] = *kv.Value + } } return newMD diff --git a/builtin/providers/google/resource_compute_instance.go b/builtin/providers/google/resource_compute_instance.go index 8ca766485..66e0b5e85 100644 --- a/builtin/providers/google/resource_compute_instance.go +++ b/builtin/providers/google/resource_compute_instance.go @@ -562,7 +562,7 @@ func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error // Synch metadata md := instance.Metadata - _md := MetadataFormatSchema(md) + _md := MetadataFormatSchema(d.Get("metadata").(map[string]interface{}), md) delete(_md, "startup-script") if script, scriptExists := d.GetOk("metadata_startup_script"); scriptExists { diff --git a/builtin/providers/google/resource_compute_project_metadata.go b/builtin/providers/google/resource_compute_project_metadata.go index c2f8a4a5f..c549415c2 100644 --- a/builtin/providers/google/resource_compute_project_metadata.go +++ b/builtin/providers/google/resource_compute_project_metadata.go @@ -90,7 +90,7 @@ func resourceComputeProjectMetadataRead(d *schema.ResourceData, meta interface{} md := project.CommonInstanceMetadata - if err = d.Set("metadata", MetadataFormatSchema(md)); err != nil { + if err = d.Set("metadata", MetadataFormatSchema(d.Get("metadata").(map[string]interface{}), md)); err != nil { return fmt.Errorf("Error setting metadata: %s", err) } diff --git a/builtin/providers/google/resource_compute_project_metadata_test.go b/builtin/providers/google/resource_compute_project_metadata_test.go index cb0145d8d..7be3dfb26 100644 --- a/builtin/providers/google/resource_compute_project_metadata_test.go +++ b/builtin/providers/google/resource_compute_project_metadata_test.go @@ -13,8 +13,6 @@ import ( func TestAccComputeProjectMetadata_basic(t *testing.T) { var project compute.Project - t.Skip("See https://github.com/hashicorp/terraform/issues/4504") - resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -38,8 +36,6 @@ func TestAccComputeProjectMetadata_basic(t *testing.T) { func TestAccComputeProjectMetadata_modify_1(t *testing.T) { var project compute.Project - t.Skip("See https://github.com/hashicorp/terraform/issues/4504") - resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -76,8 +72,6 @@ func TestAccComputeProjectMetadata_modify_1(t *testing.T) { func TestAccComputeProjectMetadata_modify_2(t *testing.T) { var project compute.Project - t.Skip("See https://github.com/hashicorp/terraform/issues/4504") - resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders,