diff --git a/aws/resource_aws_backup_selection.go b/aws/resource_aws_backup_selection.go index bb1bbe71c69..2b55b30a95d 100644 --- a/aws/resource_aws_backup_selection.go +++ b/aws/resource_aws_backup_selection.go @@ -1,14 +1,12 @@ package aws import ( - "bytes" "fmt" "log" "regexp" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/backup" - "github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" ) @@ -40,7 +38,7 @@ func resourceAwsBackupSelection() *schema.Resource { ForceNew: true, ValidateFunc: validateArn, }, - "tag": { + "selection_tag": { Type: schema.TypeSet, Optional: true, ForceNew: true, @@ -63,7 +61,6 @@ func resourceAwsBackupSelection() *schema.Resource { }, }, }, - Set: resourceAwsConditionTagHash, }, "resources": { Type: schema.TypeList, @@ -80,7 +77,7 @@ func resourceAwsBackupSelectionCreate(d *schema.ResourceData, meta interface{}) selection := &backup.Selection{ IamRoleArn: aws.String(d.Get("iam_role_arn").(string)), - ListOfTags: expandBackupConditionTags(d.Get("tag").(*schema.Set).List()), + ListOfTags: expandBackupConditionTags(d.Get("selection_tag").(*schema.Set).List()), Resources: expandStringList(d.Get("resources").([]interface{})), SelectionName: aws.String(d.Get("name").(string)), } @@ -124,7 +121,7 @@ func resourceAwsBackupSelectionRead(d *schema.ResourceData, meta interface{}) er d.Set("iam_role_arn", resp.BackupSelection.IamRoleArn) if resp.BackupSelection.ListOfTags != nil { - tag := &schema.Set{F: resourceAwsConditionTagHash} + tags := make([]map[string]interface{}, 0) for _, r := range resp.BackupSelection.ListOfTags { m := make(map[string]interface{}) @@ -133,11 +130,11 @@ func resourceAwsBackupSelectionRead(d *schema.ResourceData, meta interface{}) er m["key"] = aws.StringValue(r.ConditionKey) m["value"] = aws.StringValue(r.ConditionValue) - tag.Add(m) + tags = append(tags, m) } - if err := d.Set("tag", tag); err != nil { - return fmt.Errorf("error setting tag: %s", err) + if err := d.Set("selection_tag", tags); err != nil { + return fmt.Errorf("error setting selection tag: %s", err) } } if resp.BackupSelection.Resources != nil { @@ -181,22 +178,3 @@ func expandBackupConditionTags(tagList []interface{}) []*backup.Condition { return conditions } - -func resourceAwsConditionTagHash(v interface{}) int { - var buf bytes.Buffer - m := v.(map[string]interface{}) - - if v, ok := m["type"]; ok { - buf.WriteString(fmt.Sprintf("%s-", v.(string))) - } - - if v, ok := m["key"]; ok { - buf.WriteString(fmt.Sprintf("%s-", v.(string))) - } - - if v, ok := m["value"]; ok { - buf.WriteString(fmt.Sprintf("%s-", v.(string))) - } - - return hashcode.String(buf.String()) -} diff --git a/aws/resource_aws_backup_selection_test.go b/aws/resource_aws_backup_selection_test.go index 27d30f61eef..700e0482c28 100644 --- a/aws/resource_aws_backup_selection_test.go +++ b/aws/resource_aws_backup_selection_test.go @@ -61,7 +61,7 @@ func TestAccAwsBackupSelection_withTags(t *testing.T) { Config: testAccBackupSelectionConfigWithTags(rInt), Check: resource.ComposeTestCheckFunc( testAccCheckAwsBackupSelectionExists("aws_backup_selection.test", &selection1), - resource.TestCheckResourceAttr("aws_backup_selection.test", "tag.#", "2"), + resource.TestCheckResourceAttr("aws_backup_selection.test", "selection_tag.#", "2"), ), }, }, @@ -180,7 +180,7 @@ resource "aws_backup_selection" "test" { name = "tf_acc_test_backup_selection_%d" iam_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/service-role/AWSBackupDefaultServiceRole" - tag { + selection_tag { type = "STRINGEQUALS" key = "foo" value = "bar" @@ -201,13 +201,13 @@ resource "aws_backup_selection" "test" { name = "tf_acc_test_backup_selection_%d" iam_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/service-role/AWSBackupDefaultServiceRole" - tag { + selection_tag { type = "STRINGEQUALS" key = "foo" value = "bar" } - tag { + selection_tag { type = "STRINGEQUALS" key = "boo" value = "far" @@ -228,7 +228,7 @@ resource "aws_backup_selection" "test" { name = "tf_acc_test_backup_selection_%d" iam_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/service-role/AWSBackupDefaultServiceRole" - tag { + selection_tag { type = "STRINGEQUALS" key = "foo" value = "bar" diff --git a/website/docs/r/backup_selection.html.markdown b/website/docs/r/backup_selection.html.markdown index 42f8887c3bd..fbc07c0920b 100644 --- a/website/docs/r/backup_selection.html.markdown +++ b/website/docs/r/backup_selection.html.markdown @@ -38,10 +38,10 @@ The following arguments are supported: * `name` - (Required) The display name of a resource selection document. * `plan_id` - (Required) The backup plan ID to be associated with the selection of resources. * `iam_role` - (Required) The ARN of the IAM role that AWS Backup uses to authenticate when restoring the target resource. -* `tag` - (Optional) Tag-based conditions used to specify a set of resources to assign to a backup plan. +* `selection_tag` - (Optional) Tag-based conditions used to specify a set of resources to assign to a backup plan. * `resources` - (Optional) An array of strings that either contain Amazon Resource Names (ARNs) or match patterns of resources to assign to a backup plan.. -Tag conditions (`tag`) support the following: +Tag conditions (`selection_tag`) support the following: * `type` - (Required) An operation, such as `StringEquals`, that is applied to a key-value pair used to filter resources in a selection. * `key` - (Required) The key in a key-value pair.