Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

adding thresholds for alert contacts #18

Merged
merged 1 commit into from
Mar 15, 2019

Conversation

drubin
Copy link
Contributor

@drubin drubin commented Feb 22, 2019

@louy I have tried working on this but I got very stuck with adding proper tests :( I don't know how which method to use to validate a "hash"

I am pretty sure this actually sets and updates the recurrence and threshold correctly but I can't validate without fixing the tests.

    testing.go:518: Step 1 error: ImportStateVerify attributes not equivalent. Difference is shown below. Top is actual, bottom is expected.

        (map[string]string) {
        }


        (map[string]string) (len=4) {
         (string) (len=15) "alert_contact.#": (string) (len=1) "1",
         (string) (len=18) "alert_contact.0.id": (string) (len=7) "1234",
         (string) (len=26) "alert_contact.0.recurrence": (string) (len=1) "1",
         (string) (len=25) "alert_contact.0.threshold": (string) (len=1) "8"
        }

I also think my biggest issue is I somehow need to modify the GetMonitor method by adjusting the type Monitor struct { to include the AlertContacts

Any advice?

@louy
Copy link
Owner

louy commented Feb 22, 2019

I think the reason it's breaking for you is that the alert contact ID doesn't exist.

can you try adding an alert contact resource to your test?

i.e.

				resource "uptimerobot_alert_contact" "test" {
					...
				}
				resource "uptimerobot_monitor" "test" {
					...
					alert_contact {
						id         = "${uptimerobot_alert_contact.test.id}"
						threshold  = 8
						recurrence = 1
					}
				}

@drubin
Copy link
Contributor Author

drubin commented Feb 22, 2019

@louy 1234 not the real number was a hard-coded alert contact I have in my account (I was just trying to simplify things)

@louy
Copy link
Owner

louy commented Feb 22, 2019

I see. Let me try this locally. However, the error message you mentioned looks like UR rejecting your alert contact id rather than an issue in threshold/recurrence

@drubin
Copy link
Contributor Author

drubin commented Feb 22, 2019

But this test will only work if you have a paid for account that you are running the tests with on CI (are you?)

@louy
Copy link
Owner

louy commented Feb 22, 2019

Sadly no, so I think for the purpose of making the test work for non-paid users (including myself) we can set them to 0

@louy
Copy link
Owner

louy commented Feb 22, 2019

Ok I see the problem now. Yeah you're right GetMonitor is missing the return value alert_contact

@louy
Copy link
Owner

louy commented Feb 22, 2019

Looking at their API, I think I remember what the issue was now.

The getMonitors api doesn't return alert_contacts, which is why I didn't create a test for this in the past

I think for this one you can skip this step in the test and it should work fine:

			resource.TestStep{
				ResourceName:      "uptimerobot_monitor.test",
				ImportState:       true,
				ImportStateVerify: true,
			},

Please do this in a separate test case (rather than updating the existing http monitor test case) and I'll merge :)

@drubin drubin force-pushed the update-contact-intervals branch from 2cc5631 to 780ac00 Compare February 22, 2019 14:45
@drubin
Copy link
Contributor Author

drubin commented Feb 22, 2019

@louy I updated it, not sure why the tests are failing to check out the code?

Also does that I did make sense?

Will terraform try to change the alert_contacts every single time we push a change since it can't read the value from uptimerobot or will it assume it hasn't changed?

@louy
Copy link
Owner

louy commented Mar 1, 2019

I'm not sure why the build is breaking either, but I suspect it's an issue with circleci's permission to access github. Maybe try to re-authorise it or something? :)

I don't think TF will try to update this every time, but the issue is rather that TF can't import this field (which is why the ImportVerify test step fails). If we can add a few resource.TestCheckResourceAttr for the alert contact we can confirm this. I'll leave a line comment on this one but otherwise this should be good to go

@louy
Copy link
Owner

louy commented Mar 1, 2019

Sorry it's taken me a while btw. Just busy at work as you can imagine

@drubin drubin force-pushed the update-contact-intervals branch 2 times, most recently from 79ca216 to 37d3d0e Compare March 10, 2019 21:42
@drubin
Copy link
Contributor Author

drubin commented Mar 10, 2019

@louy I figured out why it was failing. It was failing because of I setup automatic builds for my fork for #9

I think you have set it not to build fork's because they would have access to your API key.

I have added your suggested changes, tests pass locally.

Let me know if there is anything else to get this merged so we can try it out?

Sadly the uptimerobot API doesn't support fetching them
@drubin drubin force-pushed the update-contact-intervals branch from 37d3d0e to 5d6932a Compare March 10, 2019 21:46
@drubin drubin changed the title WIP: adding thresholds for alert contacts adding thresholds for alert contacts Mar 10, 2019
@louy louy merged commit 5d6932a into louy:master Mar 15, 2019
@drubin drubin deleted the update-contact-intervals branch March 15, 2019 14:59
@louy
Copy link
Owner

louy commented Mar 15, 2019

Makes sense. Yeah I guess I don't want anyone to be able to get hold of my api key ;)

I've merged this now and it should be released in v0.3.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants