diff --git a/aws/resource_aws_backup_plan.go b/aws/resource_aws_backup_plan.go index 1a895826e15..c6811bb6707 100644 --- a/aws/resource_aws_backup_plan.go +++ b/aws/resource_aws_backup_plan.go @@ -217,7 +217,7 @@ func expandBackupPlanRules(vRules *schema.Set) []*backup.RuleInput { } if vRecoveryPointTags, ok := mRule["recovery_point_tags"].(map[string]interface{}); ok && len(vRecoveryPointTags) > 0 { - rule.RecoveryPointTags = tagsFromMapGeneric(vRecoveryPointTags) + rule.RecoveryPointTags = keyvaluetags.New(vRecoveryPointTags).IgnoreAws().BackupTags() } if vLifecycle, ok := mRule["lifecycle"].([]interface{}); ok && len(vLifecycle) > 0 && vLifecycle[0] != nil { @@ -251,7 +251,7 @@ func flattenBackupPlanRules(rules []*backup.Rule) *schema.Set { "schedule": aws.StringValue(rule.ScheduleExpression), "start_window": int(aws.Int64Value(rule.StartWindowMinutes)), "completion_window": int(aws.Int64Value(rule.CompletionWindowMinutes)), - "recovery_point_tags": tagsToMapGeneric(rule.RecoveryPointTags), + "recovery_point_tags": keyvaluetags.BackupKeyValueTags(rule.RecoveryPointTags).IgnoreAws().Map(), } if lifecycle := rule.Lifecycle; lifecycle != nil { diff --git a/aws/tagsGeneric.go b/aws/tagsGeneric.go deleted file mode 100644 index 2deb9baba71..00000000000 --- a/aws/tagsGeneric.go +++ /dev/null @@ -1,70 +0,0 @@ -package aws - -import ( - "log" - "regexp" - - "github.com/aws/aws-sdk-go/aws" -) - -// diffTags takes our tags locally and the ones remotely and returns -// the set of tags that must be created, and the set of tags that must -// be destroyed. -func diffTagsGeneric(oldTags, newTags map[string]interface{}) (map[string]*string, map[string]*string) { - // First, we're creating everything we have - create := make(map[string]*string) - for k, v := range newTags { - create[k] = aws.String(v.(string)) - } - - // Build the map of what to remove - remove := make(map[string]*string) - for k, v := range oldTags { - old, ok := create[k] - if !ok || old != aws.String(v.(string)) { - // Delete it! - remove[k] = aws.String(v.(string)) - } - } - - return create, remove -} - -// tagsFromMap returns the tags for the given map of data. -func tagsFromMapGeneric(m map[string]interface{}) map[string]*string { - result := make(map[string]*string) - for k, v := range m { - if !tagIgnoredGeneric(k) { - result[k] = aws.String(v.(string)) - } - } - - return result -} - -// tagsToMap turns the tags into a map. -func tagsToMapGeneric(ts map[string]*string) map[string]string { - result := make(map[string]string) - for k, v := range ts { - if !tagIgnoredGeneric(k) { - result[k] = aws.StringValue(v) - } - } - - return result -} - -// compare a tag against a list of strings and checks if it should -// be ignored or not -func tagIgnoredGeneric(k string) bool { - filter := []string{"^aws:"} - for _, v := range filter { - log.Printf("[DEBUG] Matching %v with %v\n", v, k) - r, _ := regexp.MatchString(v, k) - if r { - log.Printf("[DEBUG] Found AWS specific tag %s, ignoring.\n", k) - return true - } - } - return false -} diff --git a/aws/tagsGeneric_test.go b/aws/tagsGeneric_test.go deleted file mode 100644 index 2477f3aa507..00000000000 --- a/aws/tagsGeneric_test.go +++ /dev/null @@ -1,73 +0,0 @@ -package aws - -import ( - "reflect" - "testing" - - "github.com/aws/aws-sdk-go/aws" -) - -// go test -v -run="TestDiffGenericTags" -func TestDiffGenericTags(t *testing.T) { - cases := []struct { - Old, New map[string]interface{} - Create, Remove map[string]string - }{ - // Basic add/remove - { - Old: map[string]interface{}{ - "foo": "bar", - }, - New: map[string]interface{}{ - "bar": "baz", - }, - Create: map[string]string{ - "bar": "baz", - }, - Remove: map[string]string{ - "foo": "bar", - }, - }, - - // Modify - { - Old: map[string]interface{}{ - "foo": "bar", - }, - New: map[string]interface{}{ - "foo": "baz", - }, - Create: map[string]string{ - "foo": "baz", - }, - Remove: map[string]string{ - "foo": "bar", - }, - }, - } - - for i, tc := range cases { - c, r := diffTagsGeneric(tc.Old, tc.New) - cm := tagsToMapGeneric(c) - rm := tagsToMapGeneric(r) - if !reflect.DeepEqual(cm, tc.Create) { - t.Fatalf("%d: bad create: %#v", i, cm) - } - if !reflect.DeepEqual(rm, tc.Remove) { - t.Fatalf("%d: bad remove: %#v", i, rm) - } - } -} - -// go test -v -run="TestIgnoringTagsGeneric" -func TestIgnoringTagsGeneric(t *testing.T) { - ignoredTags := map[string]*string{ - "aws:cloudformation:logical-id": aws.String("foo"), - "aws:foo:bar": aws.String("baz"), - } - for k, v := range ignoredTags { - if !tagIgnoredGeneric(k) { - t.Fatalf("Tag %v with value %v not ignored, but should be!", k, *v) - } - } -}