-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provider/aws: Add acceptance test for aws_placement_group
- Loading branch information
Radek Simko
committed
Oct 8, 2015
1 parent
110be43
commit f30c647
Showing
1 changed file
with
98 additions
and
0 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
builtin/providers/aws/resource_aws_placement_group_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/ec2" | ||
) | ||
|
||
func TestAccAWSPlacementGroup_basic(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAWSPlacementGroupDestroy, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccAWSPlacementGroupConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSPlacementGroupExists("aws_placement_group.pg"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckAWSPlacementGroupDestroy(s *terraform.State) error { | ||
conn := testAccProvider.Meta().(*AWSClient).ec2conn | ||
|
||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != "aws_placement_group" { | ||
continue | ||
} | ||
_, err := conn.DeletePlacementGroup(&ec2.DeletePlacementGroupInput{ | ||
GroupName: aws.String(rs.Primary.ID), | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func testAccCheckAWSPlacementGroupExists(n string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
if !ok { | ||
return fmt.Errorf("Not found: %s", n) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("No Placement Group ID is set") | ||
} | ||
|
||
conn := testAccProvider.Meta().(*AWSClient).ec2conn | ||
_, err := conn.DescribePlacementGroups(&ec2.DescribePlacementGroupsInput{ | ||
GroupNames: []*string{aws.String(rs.Primary.ID)}, | ||
}) | ||
|
||
if err != nil { | ||
return fmt.Errorf("Placement Group error: %v", err) | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
func testAccCheckAWSDestroyPlacementGroup(n string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
if !ok { | ||
return fmt.Errorf("Not found: %s", n) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("No Placement Group ID is set") | ||
} | ||
|
||
conn := testAccProvider.Meta().(*AWSClient).ec2conn | ||
_, err := conn.DeletePlacementGroup(&ec2.DeletePlacementGroupInput{ | ||
GroupName: aws.String(rs.Primary.ID), | ||
}) | ||
|
||
if err != nil { | ||
return fmt.Errorf("Error destroying Placement Group (%s): %s", rs.Primary.ID, err) | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
var testAccAWSPlacementGroupConfig = ` | ||
resource "aws_placement_group" "pg" { | ||
name = "tf-test-pg" | ||
strategy = "cluster" | ||
} | ||
` |