terraform-provider-opsgenie
terraform-provider-opsgenie copied to clipboard
Schedule rotation "time restriction" is not stable
Terraform Version
$ terraform -v
Terraform v0.14.6
Affected Resource(s)
-
opsgenie_schedule_rotation
Terraform Configuration Files
resource "opsgenie_schedule_rotation" "test" {
name = "Daytime"
schedule_id = opsgenie_schedule.test.id
type = "daily"
length = 1
start_date = "2021-01-01T06:00:00Z"
participant {
type = "user"
id = opsgenie_user.test.id
}
# weekdays, working-hours
time_restriction {
type = "weekday-and-time-of-day"
restrictions {
start_day = "monday"
start_hour = 8
start_min = 0
end_day = "monday"
end_hour = 18
end_min = 0
}
restrictions {
start_day = "tuesday"
start_hour = 8
start_min = 0
end_day = "tuesday"
end_hour = 18
end_min = 0
}
}
}
Expected Behavior
After applying this once, if I don't change the Terraform configuration nor the objects using Opsgenie UI, Terraform should not show any changes on subsequent applies.
Actual Behavior
After the initial creation of the resource with Terraform, subsequent applies all show pending changes of the form:
# opsgenie_schedule_rotation.test will be updated in-place
~ resource "opsgenie_schedule_rotation" "test" {
id = "51eebdb7-77a3-42e2-8795-bfc568b32924"
length = 1
name = "Daytime"
schedule_id = "390074cd-8b83-4e00-b11e-c39899086468"
start_date = "2021-01-01T06:00:00Z"
type = "daily"
participant {
id = "90e9256c-3694-4f8b-bda8-d817b4d6a241"
type = "user"
}
~ time_restriction {
type = "weekday-and-time-of-day"
~ restrictions {
~ end_day = "tuesday" -> "monday"
end_hour = 18
end_min = 0
~ start_day = "tuesday" -> "monday"
start_hour = 8
start_min = 0
}
~ restrictions {
~ end_day = "monday" -> "tuesday"
end_hour = 18
end_min = 0
~ start_day = "monday" -> "tuesday"
start_hour = 8
start_min = 0
}
}
}
Steps to Reproduce
Please list the steps required to reproduce the issue, for example:
-
terraform apply
-
terraform apply
Additional Information
restrictions
, and time_restriction
are supported by several resources, but they all are implemented differently:
- https://github.com/opsgenie/terraform-provider-opsgenie/blob/master/opsgenie/resource_opsgenie_alert_policy.go#L652-L681
- https://github.com/opsgenie/terraform-provider-opsgenie/blob/master/opsgenie/resource_opsgenie_notification_policy.go#L709-L738
- https://github.com/opsgenie/terraform-provider-opsgenie/blob/master/opsgenie/resource_opsgenie_notification_rule.go#L519-L552
- https://github.com/opsgenie/terraform-provider-opsgenie/blob/master/opsgenie/resource_opsgenie_schedule_rotation.go#L270-L311
- https://github.com/opsgenie/terraform-provider-opsgenie/blob/master/opsgenie/resource_opsgenie_team_routing_rule.go#L372-L405
(same for the related "expand" function)
Would there be any interest to have a common, single implementation, that do not show exhibit this behavior? I'd be happy to help refactoring the code to support this effort :+1:
This broke it: https://github.com/opsgenie/terraform-provider-opsgenie/pull/217
@ffahri can we have TypeSet back?
This broke it: #217
@ffahri can we have TypeSet back?
Good find. I am trying to understand what was even the goal of the PR you linked. For those who want this solved in the short term use version 0.6.0 as this is the last working version before the breaking commit.
@ffahri any news here?
Bumping this to see what the latest news is.
https://www.terraform.io/plugin/sdkv2/schemas/schema-types
https://github.com/opsgenie/terraform-provider-opsgenie/pull/217
According to here the PR linked above actually shouldn't have broken it since they set TypeSet to TypeList.
TypeSet implements set behavior and is used to represent an unordered collection of items, meaning that their ordering specified does not need to be consistent, and the ordering itself has no impact on the behavior of the resource.
TypeList is used to represent an ordered collection of items, where the order the items are presented can impact the behavior of the resource being modeled. An example of ordered items would be network routing rules, where rules are examined in the order they are given until a match is found. The items are all of the same type defined by the Elem property.
I will try and take a look and see.
I made a change, but I am unable to test it because I don't have access to an OpsGenie account anymore. Can someone try this please?
It probably won't work, but after reading the schema docs this seems it would work in theory. lol
https://github.com/devopstagon/terraform-provider-opsgenie/releases
Can run using my binary via these instructions: https://www.terraform.io/cli/config/config-file#provider-installation
Happy to test this out, however when trying to download your build of the provider visiting:
https://github.com/devopstagon/terraform-provider-opsgenie/releases
in a web browser indicates there are no releases available.
Happy to test this out, however when trying to download your build of the provider visiting:
https://github.com/devopstagon/terraform-provider-opsgenie/releases
in a web browser indicates there are no releases available.
I forgot to hit publish. It should be there now:
https://github.com/devopstagon/terraform-provider-opsgenie/releases/tag/0.7.1
@jcsmith any luck?
Haven't had a chance to give it a go yet. I should Be able later this afternoon or Monday morning.
Testing indicates this resolves the issue of terraform always reporting changes to schedule rotation time restrictions.
Testing indicates this resolves the issue of terraform always reporting changes to schedule rotation time restrictions.
Amazing. I will submit it as a PR then. Thanks for testing! I am honestly surprised such a simple change fixed it lol.
Hi everyone, I tried creating a opsgenie_schedule_rotation
resource using the code snippet provided by @multani. The resource gets created smoothly and Terraform does not report any changes on doing terraform plan
or terraform apply
. I noticed that the issue was originally mentioned with v0.14.6
version of Terraform. I am using v1.4.6
. Would request you all to try with recent versions of Terraform and let us know.
Closing this as there has been no activity since a week !