Skip to content

Commit

Permalink
Merge pull request #32710 from jimfkong/f-aws_ssmcontacts_rotations
Browse files Browse the repository at this point in the history
add ssm contacts rotation resource and data source
  • Loading branch information
johnsonaj committed Feb 1, 2024
2 parents 0e5c59c + 1ef9e89 commit eb165ab
Show file tree
Hide file tree
Showing 15 changed files with 2,578 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changelog/32710.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:new-resource
aws_ssmcontacts_rotation
```

```release-note:new-data-source
aws_ssmcontacts_rotation
```
18 changes: 18 additions & 0 deletions internal/framework/flex/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ func Int32ToFramework(ctx context.Context, v *int32) types.Int64 {
return output
}

func Int32ValueToFramework(ctx context.Context, v int32) types.Int64 {
var output types.Int64

panicOnError(Flatten(ctx, v, &output))

return output
}

// Int32FromFramework coverts a Framework Int64 value to an int32 pointer.
// A null Int64 is converted to a nil int32 pointer.
func Int32FromFramework(ctx context.Context, v types.Int64) *int32 {
Expand All @@ -67,3 +75,13 @@ func Int32FromFramework(ctx context.Context, v types.Int64) *int32 {

return output
}

// Int32ValueFromFramework coverts a Framework Int64 value to an int32 pointer.
// A null Int64 is converted to a nil int32 pointer.
func Int32ValueFromFramework(ctx context.Context, v types.Int64) int32 {
var output int32

panicOnError(Expand(ctx, v, &output))

return output
}
14 changes: 14 additions & 0 deletions internal/service/ssmcontacts/exports_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package ssmcontacts

// Exports for use in tests only.

var (
ResourceRotation = newResourceRotation
)

var (
FindRotationByID = findRotationByID
)
65 changes: 65 additions & 0 deletions internal/service/ssmcontacts/planmodifiers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package ssmcontacts

import (
"context"
"sort"

"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
)

var _ planmodifier.List = shiftCoveragesPlanModifier{}

func ShiftCoveragesPlanModifier() planmodifier.List {
return &shiftCoveragesPlanModifier{}
}

type shiftCoveragesPlanModifier struct{}

func (s shiftCoveragesPlanModifier) PlanModifyList(ctx context.Context, req planmodifier.ListRequest, resp *planmodifier.ListResponse) {
if req.PlanValue.IsNull() {
return
}

if req.PlanValue.IsUnknown() {
return
}

if req.ConfigValue.IsUnknown() {
return
}

var plan, state []shiftCoveragesData
resp.Diagnostics.Append(req.PlanValue.ElementsAs(ctx, &plan, false)...)
resp.Diagnostics.Append(req.StateValue.ElementsAs(ctx, &state, false)...)

req.PlanValue.ElementsAs(ctx, &plan, false)
if resp.Diagnostics.HasError() {
return
}

sort.Slice(plan, func(i, j int) bool {
return plan[i].MapBlockKey.ValueString() < plan[j].MapBlockKey.ValueString()
})

sort.Slice(state, func(i, j int) bool {
return state[i].MapBlockKey.ValueString() < state[j].MapBlockKey.ValueString()
})

isEqual := cmp.Diff(plan, state) == ""

if isEqual {
resp.PlanValue = req.StateValue
}
}

func (s shiftCoveragesPlanModifier) Description(_ context.Context) string {
return "Suppress diff for shift_coverages"
}

func (s shiftCoveragesPlanModifier) MarkdownDescription(ctx context.Context) string {
return s.Description(ctx)
}
Loading

0 comments on commit eb165ab

Please sign in to comment.