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

opsgenie_team_routing_rule `order` and `time_restriction` properties do not get imported properly

Open aduric opened this issue 5 years ago • 2 comments

Terraform Version

0.12.24

Affected Resource(s)

Please list the resources as a list, for example:

  • opsgenie_team_routing_rule

When importing an opsgenie_team_routing_rule, the time_restriction properties do not get reflected in the state. Also, the order property gets imported as null.

Terraform State

   {
      "mode": "managed",
      "type": "opsgenie_team_routing_rule",
      "name": "dev",
      "provider": "provider.opsgenie",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "criteria": [
              {
                "conditions": [
                  {
                    "expected_value": "development",
                    "field": "description",
                    "key": "",
                    "not": false,
                    "operation": "contains",
                    "order": 0
                  }
                ],
                "type": "match-any-condition"
              }
            ],
            "id": "<GUID>",
            "name": "Dev",
            "notify": [
              {
                "id": "",
                "name": "",
                "type": "none"
              }
            ],
            "order": null,
            "team_id": "<GUID>",
            "time_restriction": [],
            "timezone": "America/New_York"
          }
        }
      ]
    }

Expected Behavior

All properties should get imported correctly.

Actual Behavior

  • The order property does not reflect the value in OpsGenie
  • The time_restriction property is empty

Steps to Reproduce

  1. Create 2 or more Routing Rules in the OpsGenie UI with an ordering dependency and at least one with some time restrictions
  2. Import those routing rules into Terraform
  3. Run terraform plan
  4. Note that those properties are not part of the plan

aduric avatar Jul 08 '20 17:07 aduric

Got the same behavior

zonArt avatar Sep 23 '20 12:09 zonArt

Same problem seems to exist with conditions in opsgenie_integration_actions. The order field for integration actions and conditions for those actions are always saved as 0. An example

My code:

...
conditions {
        order = 1
        field          = "tags"
        operation      = "matches"
        expected_value = ".*prod.*"
      }
      conditions {
        order = 2
        field          = "state"
        operation      = "matches"
        expected_value = "open|test"
      }
 ...

output of terraform show

...
           conditions {
               expected_value = "open|test"
               field          = "state"
               not            = false
               operation      = "matches"
               order          = 0
           }
           conditions {
               expected_value = ".*prod.*"
               field          = "tags"
               not            = false
               operation      = "matches"
               order          = 0
           }
...

Happy to make a separate issue for this if needed

Note: if anyone runs into this specific issue, there seems to be a deterministic order that conditions are saved in that ignores order. Since the order is not actually important, you can get around this by matching the deterministic order in your code. For example, changing my code to this fixes the issue of unwanted replacements.

      conditions {
        field          = "state"
        operation      = "matches"
        expected_value = "open|test"
      }
      conditions {
        field          = "tags"
        operation      = "matches"
        expected_value = ".*prod.*"
      }

nate-selzer avatar Mar 03 '22 17:03 nate-selzer