Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/placement_group - tag on create #12963

Merged
merged 1 commit into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 7 additions & 22 deletions aws/resource_aws_placement_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -183,19 +169,18 @@ 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 {
return out, ec2.PlacementGroupStateDeleted, nil
}

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)
}

Expand Down
5 changes: 2 additions & 3 deletions aws/resource_aws_placement_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down