Skip to content

Commit

Permalink
Add a bit better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterSzegedi committed Jun 10, 2024
1 parent a638735 commit 6e9b32a
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions internal/service/ec2/vpc_default_internet_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ func resourceDefaultInternetGatewayCreate(ctx context.Context, d *schema.Resourc
}
vpc, err := findVPCV2(ctx, ec2Client, input)
if err == nil {

// Check if there is an IGW assigned to the default VPC
log.Print("[INFO] Found existing attached EC2 Internet Gateway")
input := &ec2.DescribeInternetGatewaysInput{}
input.Filters = newAttributeFilterList(map[string]string{
"attachment.vpc-id": *vpc.VpcId,
Expand All @@ -103,13 +102,12 @@ func resourceDefaultInternetGatewayCreate(ctx context.Context, d *schema.Resourc
d.Set("existing_default_internet_gateway", true)

} else if tfresource.NotFound(err) {

Check failure on line 104 in internal/service/ec2/vpc_default_internet_gateway.go

View workflow job for this annotation

GitHub Actions / 2 of 2

unnecessary trailing newline (whitespace)
log.Print("[INFO] Found default VPC without attached EC2 Internet Gateway. Creating and attaching one")
input := &ec2.CreateInternetGatewayInput{}

log.Printf("[DEBUG] Creating EC2 Internet Gateway: %s", input)
output, err := conn.CreateInternetGatewayWithContext(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "creating EC2 Internet Gateway: %s", err)
return sdkdiag.AppendErrorf(diags, "Creating EC2 Internet Gateway: %s", err)
}

igw = output.InternetGateway
Expand All @@ -118,10 +116,10 @@ func resourceDefaultInternetGatewayCreate(ctx context.Context, d *schema.Resourc
d.Set("existing_default_internet_gateway", false)

if err := attachInternetGateway(ctx, conn, d.Id(), *vpc.VpcId, d.Timeout(schema.TimeoutDelete)); err != nil {
return sdkdiag.AppendErrorf(diags, "attaching EC2 Internet Gateway (%s): %s", d.Id(), err)
return sdkdiag.AppendErrorf(diags, "Attaching EC2 Internet Gateway (%s): %s", d.Id(), err)
}
} else {
return sdkdiag.AppendErrorf(diags, "creating EC2 Internet Gateway (%s): %s", d.Id(), err)
return sdkdiag.AppendErrorf(diags, "Creating EC2 Internet Gateway (%s): %s", d.Id(), err)
}
}
return append(diags, resourceInternetGatewayRead(ctx, d, meta)...)
Expand Down

0 comments on commit 6e9b32a

Please sign in to comment.