Skip to content

Commit

Permalink
fix: error handling and fix to provicer constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
parthpnx committed Oct 24, 2024
1 parent 1796bc8 commit 6cd24fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
18 changes: 10 additions & 8 deletions internal/provider/log_group/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package loggroup

import (
"context"
"strings"
"errors"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand All @@ -17,20 +17,22 @@ func Create(d *schema.ResourceData, m interface{}) error {

var (
name = d.Get(Name).(string)
ctx = context.TODO()
)

_, err := c.CreateLogGroup(context.TODO(), &cloudwatchlogs.CreateLogGroupInput{
LogGroupName: aws.String(name),
})

if err != nil {
tflog.Error(context.TODO(), "Error creating log group")
if !strings.Contains(err.Error(), "ResourceAlreadyExistsException") {
return err
}
var exception *types.ResourceAlreadyExistsException
if !errors.As(err, &exception) {
return err
}

lg, _ := findLogGroupByName(context.TODO(), c, name)
lg, err := findLogGroupByName(ctx, c, name)
if err != nil {
return err
}

d.Set(Name, name)
d.SetId(TrimLogGroupARNWildcardSuffix(aws.ToString(lg.Arn)))
Expand Down
1 change: 0 additions & 1 deletion internal/provider/log_group/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func Resource() *schema.Resource {
Name: {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
},
}
Expand Down

0 comments on commit 6cd24fc

Please sign in to comment.