thousandeyes / terraform-provider-thousandeyes

ThousandEyes Terraform Provider
Apache License 2.0
21 stars 26 forks source link

feat: Implement third party notification support within alert rules #110

Closed pedro-te closed 1 year ago

pedro-te commented 1 year ago

This adds support for third party notifications within alert rules. This functionality was added to the Go SDK by a customer and external contributor, and we're adding the support to the terraform provider as it was a bit more complex than adding the support to the Go SDK.

Tests are ok:

go vet ./... && echo && go test ./...

?       github.com/thousandeyes/terraform-provider-thousandeyes [no test files]
ok      github.com/thousandeyes/terraform-provider-thousandeyes/thousandeyes    0.279s

Tested the provider with a local override:

resource "thousandeyes_alert_rule" "thousandeyes_alert_rule_slack" {
  rule_name = "Pedro-test: Alert Rule with third party integration"
  alert_type = "End-to-End (Server)"
  expression = "((loss >= 10%))"
  minimum_sources = 5
  rounds_violating_required = 10
  rounds_violating_out_of = 10
  rounds_violating_mode = "ANY"
  notifications {
    email {
      message = "Pedro-test"
      recipient = ["pedro@bitconnect.net"]
    }

    third_party {
      integration_id = "sl-8026"
      integration_type = "SLACK"
    }

    third_party {
      integration_id = "pgd-5866"
      integration_type = "PAGER_DUTY"
    }
  }
}

terraform plan and apply:

╷
│ Warning: Provider development overrides are in effect
│
│ The following provider development overrides are set in the CLI configuration:
│  - thousandeyes/thousandeyes in /Users/pedrorg/go/bin
│
│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases.
╵
thousandeyes_agent_to_server.google_agent_to_server: Refreshing state... [id=3026865]
thousandeyes_alert_rule.thousandeyes_alert_rule_slack: Refreshing state... [id=5009877]
thousandeyes_label.tf: Refreshing state... [id=410351]
thousandeyes_agent_to_agent.example_agent_to_agent: Refreshing state... [id=3026866]
thousandeyes_agent_to_server.thousandeyes_agent_to_server_tcp_no_port: Refreshing state... [id=3113616]
thousandeyes_sip_server.sip_server_example: Refreshing state... [id=3026862]
thousandeyes_alert_rule.test_alert_rule-2: Refreshing state... [id=4946550]
thousandeyes_alert_rule.test_alert_rule: Refreshing state... [id=4946549]
thousandeyes_dns_server.example_dns_server_test: Refreshing state... [id=3027162]
thousandeyes_agent_to_server.thousandeyes_agent_to_server_icmp_test: Refreshing state... [id=3113617]
thousandeyes_voice.webex_rtp_example: Refreshing state... [id=3026905]
thousandeyes_page_load.test: Refreshing state... [id=3026863]
thousandeyes_http_server.www_thousandeyes_http_test: Refreshing state... [id=3026864]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # thousandeyes_alert_rule.thousandeyes_alert_rule_slack will be updated in-place
  ~ resource "thousandeyes_alert_rule" "thousandeyes_alert_rule_slack" {
        id                        = "5009877"
        # (10 unchanged attributes hidden)

      + notifications {
          + email {
              + message   = "Pedro-test"
              + recipient = [
                  + "pedro@bitconnect.net",
                ]
            }

          + third_party {
              + integration_id   = "pgd-5866"
              + integration_type = "PAGER_DUTY"
            }
          + third_party {
              + integration_id   = "sl-8026"
              + integration_type = "SLACK"
            }
        }
      - notifications {
          - email {
              - message   = "Pedro-test" -> null
              - recipient = [
                  - "pedro@bitconnect.net",
                ] -> null
            }
        }
    }

Plan: 0 to add, 1 to change, 0 to destroy.
(...)
thousandeyes_alert_rule.thousandeyes_alert_rule_slack: Modifying... [id=5009877]
thousandeyes_alert_rule.thousandeyes_alert_rule_slack: Modifications complete after 1s [id=5009877]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

Subsequent plan:

╷
│ Warning: Provider development overrides are in effect
│
│ The following provider development overrides are set in the CLI configuration:
│  - thousandeyes/thousandeyes in /Users/pedrorg/go/bin
│
│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases.
╵
thousandeyes_sip_server.sip_server_example: Refreshing state... [id=3026862]
thousandeyes_dns_server.example_dns_server_test: Refreshing state... [id=3027162]
thousandeyes_alert_rule.thousandeyes_alert_rule_slack: Refreshing state... [id=5009877]
thousandeyes_agent_to_agent.example_agent_to_agent: Refreshing state... [id=3026866]
thousandeyes_alert_rule.test_alert_rule-2: Refreshing state... [id=4946550]
thousandeyes_agent_to_server.google_agent_to_server: Refreshing state... [id=3026865]
thousandeyes_agent_to_server.thousandeyes_agent_to_server_icmp_test: Refreshing state... [id=3113617]
thousandeyes_label.tf: Refreshing state... [id=410351]
thousandeyes_alert_rule.test_alert_rule: Refreshing state... [id=4946549]
thousandeyes_agent_to_server.thousandeyes_agent_to_server_tcp_no_port: Refreshing state... [id=3113616]
thousandeyes_page_load.test: Refreshing state... [id=3026863]
thousandeyes_voice.webex_rtp_example: Refreshing state... [id=3026905]
thousandeyes_http_server.www_thousandeyes_http_test: Refreshing state... [id=3026864]

No changes. Your infrastructure matches the configuration.

The filtering of the fields inside the third_party block stops terraform from wanting to update the third_party blocks on every plan because of additional fields that our API returns.