terraform-provider-opsgenie icon indicating copy to clipboard operation
terraform-provider-opsgenie copied to clipboard

Schedule rotation "time restriction" is not stable

Open multani opened this issue 4 years ago • 12 comments

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:

  1. terraform apply
  2. 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:

multani avatar Feb 19 '21 13:02 multani

This broke it: https://github.com/opsgenie/terraform-provider-opsgenie/pull/217

@ffahri can we have TypeSet back?

jaceq avatar Mar 01 '21 12:03 jaceq

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.

sharkymcdongles avatar Mar 31 '21 07:03 sharkymcdongles

@ffahri any news here?

filip-zyzniewski avatar Jul 08 '21 15:07 filip-zyzniewski

Bumping this to see what the latest news is.

jcsmith avatar Oct 10 '22 19:10 jcsmith

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.

devopstagon avatar Oct 13 '22 08:10 devopstagon

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

devopstagon avatar Oct 13 '22 12:10 devopstagon

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.

jcsmith avatar Oct 13 '22 14:10 jcsmith

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

devopstagon avatar Oct 13 '22 15:10 devopstagon

@jcsmith any luck?

devopstagon avatar Oct 14 '22 12:10 devopstagon

Haven't had a chance to give it a go yet. I should Be able later this afternoon or Monday morning.

jcsmith avatar Oct 14 '22 13:10 jcsmith

Testing indicates this resolves the issue of terraform always reporting changes to schedule rotation time restrictions.

jcsmith avatar Oct 17 '22 13:10 jcsmith

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.

devopstagon avatar Oct 17 '22 21:10 devopstagon

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.

arjunrajpal avatar Jul 04 '23 06:07 arjunrajpal

Closing this as there has been no activity since a week !

arjunrajpal avatar Jul 12 '23 05:07 arjunrajpal