Skip to content

Commit

Permalink
Revert metadata item changes (hashicorp#225)
Browse files Browse the repository at this point in the history
* Revert "Add additional fingerprint error to check for when updating metadata (hashicorp#221)"

This reverts commit 4c8f62e.

* Revert "Fix bug where range variable is improperly dereferenced (hashicorp#217)"

This reverts commit 8f75c1c.

* Revert "Add support for google_compute_project_metadata_item (hashicorp#176)"

This reverts commit 236c0f5.
  • Loading branch information
danawillow authored Jul 20, 2017
1 parent bd0bafc commit 37b71c6
Show file tree
Hide file tree
Showing 9 changed files with 5 additions and 440 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ FEATURES:

* **New Resource:** `google_bigtable_instance` [GH-177]
* **New Resource:** `google_bigtable_table` [GH-177]
* **New Resource:** `google_compute_project_metadata_item` - allows management of single key/value pairs within the project metadata map [GH-176]

IMPROVEMENTS:

Expand Down
25 changes: 0 additions & 25 deletions google/import_compute_project_metadata_item_test.go

This file was deleted.

65 changes: 4 additions & 61 deletions google/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ package google

import (
"fmt"
"log"
"strings"

"google.golang.org/api/compute/v1"
)

const FINGERPRINT_RETRIES = 10

var FINGERPRINT_FAIL_ERRORS = []string{"Invalid fingerprint.", "Supplied fingerprint does not match current metadata fingerprint."}
const FINGERPRINT_FAIL = "Invalid fingerprint."

// Since the google compute API uses optimistic locking, there is a chance
// we need to resubmit our updated metadata. To do this, you need to provide
Expand All @@ -19,25 +16,11 @@ func MetadataRetryWrapper(update func() error) error {
attempt := 0
for attempt < FINGERPRINT_RETRIES {
err := update()
if err == nil {
return nil
}

// Check to see if the error matches any of our fingerprint-related failure messages
var fingerprintError bool
for _, msg := range FINGERPRINT_FAIL_ERRORS {
if strings.Contains(err.Error(), msg) {
fingerprintError = true
break
}
}

if !fingerprintError {
// Something else went wrong, don't retry
if err != nil && err.Error() == FINGERPRINT_FAIL {
attempt++
} else {
return err
}

attempt++
}

return fmt.Errorf("Failed to update metadata after %d retries", attempt)
Expand Down Expand Up @@ -88,43 +71,3 @@ func MetadataFormatSchema(curMDMap map[string]interface{}, md *compute.Metadata)

return newMD
}

// flattenComputeMetadata transforms a list of MetadataItems (as returned via the GCP client) into a simple map from key
// to value.
func flattenComputeMetadata(metadata []*compute.MetadataItems) map[string]string {
m := map[string]string{}

for _, item := range metadata {
// check for duplicates
if item.Value == nil {
continue
}
if val, ok := m[item.Key]; ok {
// warn loudly!
log.Printf("[WARN] Key '%s' already has value '%s' when flattening - ignoring incoming value '%s'",
item.Key,
val,
*item.Value)
}
m[item.Key] = *item.Value
}

return m
}

// expandComputeMetadata transforms a map representing computing metadata into a list of compute.MetadataItems suitable
// for the GCP client.
func expandComputeMetadata(m map[string]string) []*compute.MetadataItems {
metadata := make([]*compute.MetadataItems, len(m))

idx := 0
for key, value := range m {
// Make a copy of value as we need a ptr type; if we directly use 'value' then all items will reference the same
// memory address
vtmp := value
metadata[idx] = &compute.MetadataItems{Key: key, Value: &vtmp}
idx++
}

return metadata
}
1 change: 0 additions & 1 deletion google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func Provider() terraform.ResourceProvider {
"google_compute_instance_template": resourceComputeInstanceTemplate(),
"google_compute_network": resourceComputeNetwork(),
"google_compute_project_metadata": resourceComputeProjectMetadata(),
"google_compute_project_metadata_item": resourceComputeProjectMetadataItem(),
"google_compute_region_backend_service": resourceComputeRegionBackendService(),
"google_compute_route": resourceComputeRoute(),
"google_compute_router": resourceComputeRouter(),
Expand Down
178 changes: 0 additions & 178 deletions google/resource_compute_project_metadata_item.go

This file was deleted.

Loading

0 comments on commit 37b71c6

Please sign in to comment.