From 6cd24fc7d55e6d3c1a117beba09b8fba46b7f00f Mon Sep 17 00:00:00 2001 From: Parth Gohil <138430690+parthpnx@users.noreply.github.com> Date: Thu, 24 Oct 2024 13:57:12 +0530 Subject: [PATCH] fix: error handling and fix to provicer constraints --- internal/provider/log_group/create.go | 18 ++++++++++-------- internal/provider/log_group/resource.go | 1 - 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/internal/provider/log_group/create.go b/internal/provider/log_group/create.go index e530576..8bc7a6e 100644 --- a/internal/provider/log_group/create.go +++ b/internal/provider/log_group/create.go @@ -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" ) @@ -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))) diff --git a/internal/provider/log_group/resource.go b/internal/provider/log_group/resource.go index 4d8ca91..6e95f3e 100644 --- a/internal/provider/log_group/resource.go +++ b/internal/provider/log_group/resource.go @@ -21,7 +21,6 @@ func Resource() *schema.Resource { Name: { Type: schema.TypeString, Required: true, - ForceNew: true, }, }, }