Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify resource_pagerduty_schedule.go to send "end": null when a layer's end is removed #460

Merged
merged 7 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.16
require (
cloud.google.com/go v0.71.0 // indirect
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1
github.com/heimweh/go-pagerduty v0.0.0-20211210233744-b65de43109c1
github.com/heimweh/go-pagerduty v0.0.0-20220208023456-83fe435832fb
golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd // indirect
google.golang.org/api v0.35.0 // indirect
google.golang.org/genproto v0.0.0-20201109203340-2640f1f9cdfb // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ github.com/heimweh/go-pagerduty v0.0.0-20211119212911-31ef1eea0d0f h1:/sgh3L7adJ
github.com/heimweh/go-pagerduty v0.0.0-20211119212911-31ef1eea0d0f/go.mod h1:JtJGtgN0y9KOCaqFMZFaBCWskpO/KK3Ro9TwjP9ss6w=
github.com/heimweh/go-pagerduty v0.0.0-20211210233744-b65de43109c1 h1:49zl3n/g+ff/7/CpxiuqnenyxId5iAjbhgoE9iDHULc=
github.com/heimweh/go-pagerduty v0.0.0-20211210233744-b65de43109c1/go.mod h1:JtJGtgN0y9KOCaqFMZFaBCWskpO/KK3Ro9TwjP9ss6w=
github.com/heimweh/go-pagerduty v0.0.0-20220208023456-83fe435832fb h1:p3faOVCU8L4wab9mpxN9Cm/VNVkPD8GMEfD0sPHw9nY=
github.com/heimweh/go-pagerduty v0.0.0-20220208023456-83fe435832fb/go.mod h1:JtJGtgN0y9KOCaqFMZFaBCWskpO/KK3Ro9TwjP9ss6w=
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down
14 changes: 9 additions & 5 deletions pagerduty/resource_pagerduty_schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ func resourcePagerDutyScheduleUpdate(d *schema.ResourceData, meta interface{}) e
if err != nil {
return err
}
o.End = end.String()
endStr := end.String()
o.End = &endStr
schedule.ScheduleLayers = append(schedule.ScheduleLayers, o)
}
}
Expand Down Expand Up @@ -372,11 +373,13 @@ func expandScheduleLayers(v interface{}) ([]*pagerduty.ScheduleLayer, error) {
return nil, err
}

// The type of layer.*.end is schema.TypeString. If the end is an empty string, it means the layer does not end.
// A client should send a payload including `"end": null` to unset the end of layer.
scheduleLayer := &pagerduty.ScheduleLayer{
ID: rsl["id"].(string),
Name: rsl["name"].(string),
Start: rsl["start"].(string),
End: rsl["end"].(string),
End: stringTypeToStringPtr(rsl["end"].(string)),
RotationVirtualStart: rvs.String(),
RotationTurnLengthSeconds: rsl["rotation_turn_length_seconds"].(int),
}
Expand Down Expand Up @@ -417,8 +420,9 @@ func flattenScheduleLayers(v []*pagerduty.ScheduleLayer) ([]map[string]interface
// A schedule layer can never be removed but it can be ended.
// Here we check each layer and if it has been ended we don't read it back
// because it's not relevant anymore.
if sl.End != "" {
end, err := timeToUTC(sl.End)
endStr := stringPtrToStringType(sl.End)
if endStr != "" {
end, err := timeToUTC(endStr)
if err != nil {
return nil, err
}
Expand All @@ -430,7 +434,7 @@ func flattenScheduleLayers(v []*pagerduty.ScheduleLayer) ([]map[string]interface
scheduleLayer := map[string]interface{}{
"id": sl.ID,
"name": sl.Name,
"end": sl.End,
"end": endStr,
"start": sl.Start,
"rotation_virtual_start": sl.RotationVirtualStart,
"rotation_turn_length_seconds": sl.RotationTurnLengthSeconds,
Expand Down
18 changes: 18 additions & 0 deletions pagerduty/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,21 @@ func flattenSlice(v []interface{}) interface{} {
}
return string(b)
}

// stringTypeToStringPtr is a helper that returns a pointer to
// the string value passed in or nil if the string is empty.
func stringTypeToStringPtr(v string) *string {
if v == "" {
return nil
}
return &v
}

// stringPtrToStringType is a helper that returns the string value passed in
// or an empty string if the given pointer is nil.
func stringPtrToStringType(v *string) string {
if v == nil {
return ""
}
return *v
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 30 additions & 1 deletion vendor/github.com/heimweh/go-pagerduty/pagerduty/user.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ github.com/hashicorp/terraform-registry-address
github.com/hashicorp/terraform-svchost
# github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d
github.com/hashicorp/yamux
# github.com/heimweh/go-pagerduty v0.0.0-20211210233744-b65de43109c1
# github.com/heimweh/go-pagerduty v0.0.0-20220208023456-83fe435832fb
## explicit
github.com/heimweh/go-pagerduty/pagerduty
# github.com/klauspost/compress v1.11.2
Expand Down