Skip to content

Commit

Permalink
resource/aws_backup_selection: Use TypeSet for resources attribute to…
Browse files Browse the repository at this point in the history
… prevent ordering issues and aws_partition/aws_region data sources in testing to prevent invalid ARN errors

Previous output from acceptance testing:

```
--- FAIL: TestAccAwsBackupSelection_withResources (13.48s)
    testing.go:538: Step 0 error: Error applying: 1 error occurred:
        	* aws_backup_selection.test: 1 error occurred:
        	* aws_backup_selection.test: error creating Backup Selection: InvalidParameterValueException: Invalid ARN: arn:aws:elasticfilesystem:us-east-1:--OMITTED--:file-system/. Expected region is us-west-2
        	status code: 400, request id: 8c64a59c-7b8c-46de-8e7e-6fa1a7879b3a

--- FAIL: TestAccAwsBackupSelection_disappears (13.53s)
    testing.go:538: Step 0 error: Error applying: 1 error occurred:
        	* aws_backup_selection.test: 1 error occurred:
        	* aws_backup_selection.test: error creating Backup Selection: InvalidParameterValueException: Invalid ARN: arn:aws:ec2:us-east-1:--OMITTED--:volume/. Expected region is us-west-2
        	status code: 400, request id: bb483272-0b15-4978-88ab-0a5cf2400302

--- FAIL: TestAccAwsBackupSelection_basic (13.60s)
    testing.go:538: Step 0 error: Error applying: 1 error occurred:
        	* aws_backup_selection.test: 1 error occurred:
        	* aws_backup_selection.test: error creating Backup Selection: InvalidParameterValueException: Invalid ARN: arn:aws:ec2:us-east-1:--OMITTED--:volume/. Expected region is us-west-2
        	status code: 400, request id: 6e4c8dda-6cc8-4d63-be62-b4b156e4c30b

--- FAIL: TestAccAwsBackupSelection_withTags (13.66s)
    testing.go:538: Step 0 error: Error applying: 1 error occurred:
        	* aws_backup_selection.test: 1 error occurred:
        	* aws_backup_selection.test: error creating Backup Selection: InvalidParameterValueException: Invalid ARN: arn:aws:ec2:us-east-1:--OMITTED--:volume/. Expected region is us-west-2
        	status code: 400, request id: a1229860-b1f7-4462-9b22-68d46cf62e31

--- FAIL: TestAccAwsBackupSelection_withResources (14.15s)
    testing.go:538: Step 0 error: After applying this step, the plan was not empty:

        DIFF:

        DESTROY/CREATE: aws_backup_selection.test
          iam_role_arn:                   "arn:aws:iam::123456789012:role/service-role/AWSBackupDefaultServiceRole" => "arn:aws:iam::187416307283:role/service-role/AWSBackupDefaultServiceRole"
          name:                           "tf_acc_test_backup_selection_5994421555613158377" => "tf_acc_test_backup_selection_5994421555613158377"
          plan_id:                        "7e69f127-aab4-4217-90cc-437ec8d9e19a" => "7e69f127-aab4-4217-90cc-437ec8d9e19a"
          resources.#:                    "2" => "2"
          resources.0:                    "arn:aws:ec2:us-west-2:123456789012:volume/" => "arn:aws:elasticfilesystem:us-west-2:123456789012:file-system/" (forces new resource)
          resources.1:                    "arn:aws:elasticfilesystem:us-west-2:123456789012:file-system/" => "arn:aws:ec2:us-west-2:123456789012:volume/" (forces new resource)
          selection_tag.#:                "1" => "1"
          selection_tag.3487478888.key:   "foo" => "foo"
          selection_tag.3487478888.type:  "STRINGEQUALS" => "STRINGEQUALS"
          selection_tag.3487478888.value: "bar" => "bar"
```

Output from acceptance testing:

```
--- PASS: TestAccAwsBackupSelection_withResources (16.55s)
--- PASS: TestAccAwsBackupSelection_basic (17.21s)
--- PASS: TestAccAwsBackupSelection_disappears (17.70s)
--- PASS: TestAccAwsBackupSelection_withTags (17.79s)
```
  • Loading branch information
bflad committed Apr 4, 2019
1 parent 315263c commit 7524304
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions aws/resource_aws_backup_selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func resourceAwsBackupSelection() *schema.Resource {
},
},
"resources": {
Type: schema.TypeList,
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
Expand All @@ -78,7 +78,7 @@ func resourceAwsBackupSelectionCreate(d *schema.ResourceData, meta interface{})
selection := &backup.Selection{
IamRoleArn: aws.String(d.Get("iam_role_arn").(string)),
ListOfTags: expandBackupConditionTags(d.Get("selection_tag").(*schema.Set).List()),
Resources: expandStringList(d.Get("resources").([]interface{})),
Resources: expandStringSet(d.Get("resources").(*schema.Set)),
SelectionName: aws.String(d.Get("name").(string)),
}

Expand Down
18 changes: 11 additions & 7 deletions aws/resource_aws_backup_selection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ func testAccBackupSelectionConfigBase(rInt int) string {
return fmt.Sprintf(`
data "aws_caller_identity" "current" {}
data "aws_partition" "current" {}
data "aws_region" "current" {}
resource "aws_backup_vault" "test" {
name = "tf_acc_test_backup_vault_%d"
}
Expand All @@ -178,7 +182,7 @@ resource "aws_backup_selection" "test" {
plan_id = "${aws_backup_plan.test.id}"
name = "tf_acc_test_backup_selection_%d"
iam_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/service-role/AWSBackupDefaultServiceRole"
iam_role_arn = "arn:${data.aws_partition.current.partition}:iam::${data.aws_caller_identity.current.account_id}:role/service-role/AWSBackupDefaultServiceRole"
selection_tag {
type = "STRINGEQUALS"
Expand All @@ -187,7 +191,7 @@ resource "aws_backup_selection" "test" {
}
resources = [
"arn:aws:ec2:us-east-1:${data.aws_caller_identity.current.account_id}:volume/"
"arn:${data.aws_partition.current.partition}:ec2:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:volume/"
]
}
`, rInt)
Expand All @@ -199,7 +203,7 @@ resource "aws_backup_selection" "test" {
plan_id = "${aws_backup_plan.test.id}"
name = "tf_acc_test_backup_selection_%d"
iam_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/service-role/AWSBackupDefaultServiceRole"
iam_role_arn = "arn:${data.aws_partition.current.partition}:iam::${data.aws_caller_identity.current.account_id}:role/service-role/AWSBackupDefaultServiceRole"
selection_tag {
type = "STRINGEQUALS"
Expand All @@ -214,7 +218,7 @@ resource "aws_backup_selection" "test" {
}
resources = [
"arn:aws:ec2:us-east-1:${data.aws_caller_identity.current.account_id}:volume/"
"arn:${data.aws_partition.current.partition}:ec2:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:volume/"
]
}
`, rInt)
Expand All @@ -226,7 +230,7 @@ resource "aws_backup_selection" "test" {
plan_id = "${aws_backup_plan.test.id}"
name = "tf_acc_test_backup_selection_%d"
iam_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/service-role/AWSBackupDefaultServiceRole"
iam_role_arn = "arn:${data.aws_partition.current.partition}:iam::${data.aws_caller_identity.current.account_id}:role/service-role/AWSBackupDefaultServiceRole"
selection_tag {
type = "STRINGEQUALS"
Expand All @@ -235,8 +239,8 @@ resource "aws_backup_selection" "test" {
}
resources = [
"arn:aws:elasticfilesystem:us-east-1:${data.aws_caller_identity.current.account_id}:file-system/",
"arn:aws:ec2:us-east-1:${data.aws_caller_identity.current.account_id}:volume/"
"arn:${data.aws_partition.current.partition}:elasticfilesystem:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:file-system/",
"arn:${data.aws_partition.current.partition}:ec2:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:volume/"
]
}
`, rInt)
Expand Down

0 comments on commit 7524304

Please sign in to comment.