Skip to content

Commit

Permalink
Only use read
Browse files Browse the repository at this point in the history
  • Loading branch information
nickschuch committed Nov 21, 2024
1 parent 6fee54a commit f016aa9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 54 deletions.
43 changes: 0 additions & 43 deletions internal/provider/log_group/create.go

This file was deleted.

27 changes: 18 additions & 9 deletions internal/provider/log_group/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package loggroup

import (
"context"
"log"
"errors"
"strings"

"github.com/aws/aws-sdk-go-v2/aws"
// "github.com/aws/aws-sdk-go-v2/aws/session"
"github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs"
"github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand All @@ -17,21 +16,31 @@ import (
func Read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
var diags diag.Diagnostics

var (
name = d.Get(Name).(string)
)

cfg := m.(aws.Config)
c := cloudwatchlogs.NewFromConfig(cfg)

logGroupName := d.Get("name").(string)
client := cloudwatchlogs.NewFromConfig(cfg)

_, err := client.CreateLogGroup(ctx, &cloudwatchlogs.CreateLogGroupInput{
LogGroupName: aws.String(name),
})

var exception *types.ResourceAlreadyExistsException

lg, err := findLogGroupByName(ctx, c, logGroupName)
if !errors.As(err, &exception) && err != nil {
return diag.FromErr(err)
}

if !d.IsNewResource() && err != nil {
log.Printf("[WARN] CloudWatch Logs Log Group (%s) not found, removing from state", d.Id())
d.SetId("")
lg, err := findLogGroupByName(ctx, client, name)
if err != nil {
return diag.FromErr(err)
}

d.SetId(TrimLogGroupARNWildcardSuffix(aws.ToString(lg.Arn)))
d.Set(Name, logGroupName)
d.Set(Name, name)

return diags
}
Expand Down
3 changes: 1 addition & 2 deletions internal/provider/log_group/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ const (
// Resource returns this packages resource.
func Resource() *schema.Resource {
return &schema.Resource{
CreateContext: Create,
ReadContext: Read,
ReadContext: Read,

Schema: map[string]*schema.Schema{
Name: {
Expand Down

0 comments on commit f016aa9

Please sign in to comment.