Skip to content

Commit

Permalink
aws/resource_aws_security_group: Only Use waitForSgToExist if Resourc…
Browse files Browse the repository at this point in the history
…e is New
  • Loading branch information
jammerful committed Mar 23, 2018
1 parent ba36727 commit 2e41ac6
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions aws/resource_aws_security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,18 @@ func resourceAwsSecurityGroupCreate(d *schema.ResourceData, meta interface{}) er
func resourceAwsSecurityGroupRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn

sgRaw, err := waitForSgToExist(conn, d.Id(), d.Timeout(schema.TimeoutRead))
var sgRaw interface{}
var err error
if d.IsNewResource() {
sgRaw, err = waitForSgToExist(conn, d.Id(), d.Timeout(schema.TimeoutRead))
} else {
sgRaw, _, err = SGStateRefreshFunc(conn, d.Id())()
}

if err != nil {
return err
}

if sgRaw == nil {
log.Printf("[WARN] Security group (%s) not found, removing from state", d.Id())
d.SetId("")
Expand Down Expand Up @@ -384,7 +392,14 @@ func resourceAwsSecurityGroupRead(d *schema.ResourceData, meta interface{}) erro
func resourceAwsSecurityGroupUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn

sgRaw, err := waitForSgToExist(conn, d.Id(), d.Timeout(schema.TimeoutRead))
var sgRaw interface{}
var err error
if d.IsNewResource() {
sgRaw, err = waitForSgToExist(conn, d.Id(), d.Timeout(schema.TimeoutRead))
} else {
sgRaw, _, err = SGStateRefreshFunc(conn, d.Id())()
}

if err != nil {
return err
}
Expand Down

0 comments on commit 2e41ac6

Please sign in to comment.