Skip to content

Commit

Permalink
Merge pull request #35606 from stromp/b-fix_ssm_patching_manager_to_s…
Browse files Browse the repository at this point in the history
…et_computed_value_as_new

B fix ssm patching manager to set computed value as new
  • Loading branch information
ewbankkit authored Feb 2, 2024
2 parents b5650d3 + 76083c6 commit ebf9dd0
Show file tree
Hide file tree
Showing 7 changed files with 258 additions and 214 deletions.
3 changes: 3 additions & 0 deletions .changelog/35606.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_ssm_patch_baseline: Mark `json` as Computed if there are content changes
```
30 changes: 15 additions & 15 deletions internal/service/ssm/default_patch_baseline.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const (
patchBaselineIDRegexPattern = `pb-[0-9a-f]{17}`
)

// @SDKResource("aws_ssm_default_patch_baseline")
func ResourceDefaultPatchBaseline() *schema.Resource {
// @SDKResource("aws_ssm_default_patch_baseline", name="Default Patch Baseline")
func resourceDefaultPatchBaseline() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceDefaultPatchBaselineCreate,
ReadWithoutTimeout: resourceDefaultPatchBaselineRead,
Expand All @@ -47,7 +47,7 @@ func ResourceDefaultPatchBaseline() *schema.Resource {
if isPatchBaselineID(id) || isPatchBaselineARN(id) {
conn := meta.(*conns.AWSClient).SSMClient(ctx)

patchbaseline, err := findPatchBaselineByID(ctx, conn, id)
patchbaseline, err := findPatchBaselineByIDV2(ctx, conn, id)
if err != nil {
return nil, fmt.Errorf("reading SSM Patch Baseline (%s): %w", id, err)
}
Expand Down Expand Up @@ -171,17 +171,16 @@ const (

func resourceDefaultPatchBaselineCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
var diags diag.Diagnostics

conn := meta.(*conns.AWSClient).SSMClient(ctx)

baselineID := d.Get("baseline_id").(string)

patchBaseline, err := findPatchBaselineByID(ctx, conn, baselineID)
patchBaseline, err := findPatchBaselineByIDV2(ctx, conn, baselineID)

if err != nil {
return create.AppendDiagErrorMessage(diags, names.SSM, "registering", ResNameDefaultPatchBaseline, baselineID,
create.ProblemStandardMessage(names.SSM, create.ErrActionReading, resNamePatchBaseline, baselineID, err),
)
return sdkdiag.AppendErrorf(diags, "reading SSM Patch Baseline (%s): %s", baselineID, err)
}

if pbOS, cOS := string(patchBaseline.OperatingSystem), d.Get("operating_system"); pbOS != cOS {
return create.AppendDiagErrorMessage(diags, names.SSM, "registering", ResNameDefaultPatchBaseline, baselineID,
fmt.Sprintf("Patch Baseline Operating System (%s) does not match %s", pbOS, cOS),
Expand Down Expand Up @@ -304,28 +303,29 @@ func FindDefaultPatchBaseline(ctx context.Context, conn *ssm.Client, os types.Op
return out, nil
}

func findPatchBaselineByID(ctx context.Context, conn *ssm.Client, id string) (*ssm.GetPatchBaselineOutput, error) {
in := &ssm.GetPatchBaselineInput{
func findPatchBaselineByIDV2(ctx context.Context, conn *ssm.Client, id string) (*ssm.GetPatchBaselineOutput, error) {
input := &ssm.GetPatchBaselineInput{
BaselineId: aws.String(id),
}
out, err := conn.GetPatchBaseline(ctx, in)

output, err := conn.GetPatchBaseline(ctx, input)

if errs.IsA[*types.DoesNotExistException](err) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: in,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

if out == nil {
return nil, tfresource.NewEmptyResultError(in)
if output == nil {
return nil, tfresource.NewEmptyResultError(input)
}

return out, nil
return output, nil
}

func patchBaselinesPaginator(conn *ssm.Client, filters ...types.PatchOrchestratorFilter) *ssm.DescribePatchBaselinesPaginator {
Expand Down
12 changes: 12 additions & 0 deletions internal/service/ssm/exports_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package ssm

// Exports for use in tests only.
var (
ResourceDefaultPatchBaseline = resourceDefaultPatchBaseline
ResourcePatchBaseline = resourcePatchBaseline

FindPatchBaselineByID = findPatchBaselineByID
)
Loading

0 comments on commit ebf9dd0

Please sign in to comment.