diff --git a/aws/resource_aws_placement_group.go b/aws/resource_aws_placement_group.go index cd09d12a4e2..a5600d41f64 100644 --- a/aws/resource_aws_placement_group.go +++ b/aws/resource_aws_placement_group.go @@ -6,7 +6,6 @@ import ( "time" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/ec2" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -54,8 +53,9 @@ func resourceAwsPlacementGroupCreate(d *schema.ResourceData, meta interface{}) e name := d.Get("name").(string) input := ec2.CreatePlacementGroupInput{ - GroupName: aws.String(name), - Strategy: aws.String(d.Get("strategy").(string)), + GroupName: aws.String(name), + Strategy: aws.String(d.Get("strategy").(string)), + TagSpecifications: ec2TagSpecificationsFromMap(d.Get("tags").(map[string]interface{}), ec2.ResourceTypePlacementGroup), } log.Printf("[DEBUG] Creating EC2 Placement group: %s", input) _, err := conn.CreatePlacementGroup(&input) @@ -100,20 +100,6 @@ func resourceAwsPlacementGroupCreate(d *schema.ResourceData, meta interface{}) e d.SetId(name) - if v := d.Get("tags").(map[string]interface{}); len(v) > 0 { - input := ec2.DescribePlacementGroupsInput{ - GroupNames: []*string{aws.String(d.Id())}, - } - out, err := conn.DescribePlacementGroups(&input) - if err != nil { - return err - } - pg := out.PlacementGroups[0] - if err := keyvaluetags.Ec2CreateTags(conn, aws.StringValue(pg.GroupId), v); err != nil { - return fmt.Errorf("error adding tags: %s", err) - } - } - return resourceAwsPlacementGroupRead(d, meta) } @@ -183,11 +169,10 @@ func resourceAwsPlacementGroupDelete(d *schema.ResourceData, meta interface{}) e }) if err != nil { - awsErr := err.(awserr.Error) - if awsErr.Code() == "InvalidPlacementGroup.Unknown" { - return out, "deleted", nil + if isAWSErr(err, "InvalidPlacementGroup.Unknown", "") { + return out, ec2.PlacementGroupStateDeleted, nil } - return out, "", awsErr + return out, "", err } if len(out.PlacementGroups) == 0 { @@ -195,7 +180,7 @@ func resourceAwsPlacementGroupDelete(d *schema.ResourceData, meta interface{}) e } pg := out.PlacementGroups[0] - if *pg.State == "available" { + if *pg.State == ec2.PlacementGroupStateAvailable { log.Printf("[DEBUG] Accepted status when deleting EC2 Placement group: %q %v", d.Id(), *pg.State) } diff --git a/aws/resource_aws_placement_group_test.go b/aws/resource_aws_placement_group_test.go index 2d4be811cb7..7a1815bb0c1 100644 --- a/aws/resource_aws_placement_group_test.go +++ b/aws/resource_aws_placement_group_test.go @@ -4,12 +4,11 @@ import ( "fmt" "testing" + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/ec2" "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" ) func TestAccAWSPlacementGroup_basic(t *testing.T) {