Skip to content

Commit

Permalink
Compute project metadata reads were failing on import.
Browse files Browse the repository at this point in the history
  • Loading branch information
nat-henderson committed Dec 12, 2018
1 parent a28dec1 commit 9a1bed7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions google-beta/resource_compute_project_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,21 @@ func resourceComputeProjectMetadataRead(d *schema.ResourceData, meta interface{}
md := flattenMetadata(project.CommonInstanceMetadata)
existingMetadata := d.Get("metadata").(map[string]interface{})
// Remove all keys not explicitly mentioned in the terraform config
for k := range md {
if _, ok := existingMetadata[k]; !ok {
delete(md, k)
// unless you're doing an import.
if len(existingMetadata) > 0 {
for k := range md {
if _, ok := existingMetadata[k]; !ok {
delete(md, k)
}
}
}

if err = d.Set("metadata", md); err != nil {
return fmt.Errorf("Error setting metadata: %s", err)
}

d.Set("project", d.Id())
d.SetId(d.Id())
d.Set("project", project.Name)
d.SetId(project.Name)
return nil
}

Expand Down

0 comments on commit 9a1bed7

Please sign in to comment.