Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix optional threshold fields handling in update function #400

Merged
merged 4 commits into from
Feb 6, 2020

Conversation

mzneos
Copy link
Contributor

@mzneos mzneos commented Jan 31, 2020

Optional fields in the threshold object were always added to the update payload, even when they were not actually set in the state or the configuration.
This broke the update function as the warning field cannot be set to a lower value that the slo value (target), which triggers a warning must be greater than slo value error.

If the warning field was not set, the ResourceData.Get() function would return the default value for the field, which is 0.0 for a float, hence the error being triggered.

This PR fixes this problem by using the ResourceData.GetOk() to check if the field was actually set or not.

The code was compiled and tested for two scenarios, both working as expected:

  • The update of an slo created with the previous terraform provider
  • The creation and then the update of an slo created with the new code

@ghost ghost added the size/S label Jan 31, 2020
@bkabrda
Copy link
Contributor

bkabrda commented Feb 4, 2020

Hey, thanks for sending the PR! I think it looks good, but I'd like to ask you to extend the test suite of SLOs to also test for this.

@fatbasstard
Copy link

We're hitting this exact issue ATM, looking forward to a release with this fix!

@mzneos
Copy link
Contributor Author

mzneos commented Feb 5, 2020

Hey, thanks for sending the PR! I think it looks good, but I'd like to ask you to extend the test suite of SLOs to also test for this.

Ok no problem, I'll do that as soon as possible

@ghost ghost added size/M and removed size/S labels Feb 5, 2020
@mzneos
Copy link
Contributor Author

mzneos commented Feb 5, 2020

This should be good now, I added checks on the warning attribute, for the creation and the update

@bkabrda
Copy link
Contributor

bkabrda commented Feb 6, 2020

@mzneos the tests don't actually pass. The reason is that you're checking for non-presence of attribute which actually is present in the state, but set to 0 (this is TF behavior for when such nested structures are used).

The code patch that you created is actually correct as it ignores these during update when they were not explicitly set before. The only thing you need to adjust is remove the TestCheckNoResourceAttr checks. The added test threshold will ensure that this is tested, as the tests will fail in the update step if warning is sent as 0.

@mzneos
Copy link
Contributor Author

mzneos commented Feb 6, 2020

Ok I see. I was expecting the TestCheckNoResourceAttr to detect that the warning attribute was not set, which is why I added it in the first place.

I removed those checks, everything should be good now.

@@ -136,6 +150,12 @@ func TestAccDatadogServiceLevelObjective_Basic(t *testing.T) {
"datadog_service_level_objective.foo", "thresholds.1.timeframe", "30d"),
resource.TestCheckResourceAttr(
"datadog_service_level_objective.foo", "thresholds.1.target", "98"),
resource.TestCheckResourceAttr(
"datadog_service_level_objective.foo", "thresholds.1.warning", "99.0"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last thing, this needs to be changed from 99.0 to 99 (because of how TF works internally). Otherwise this LGTM, so once you fix this, I can merge. Thanks @mzneos!

Copy link
Contributor Author

@mzneos mzneos Feb 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok, my bad. I added this check as it was missing, and just copy-pasted the value without thinking further than that.
I should have run the acceptance tests by myself to make sure everything was working, but wasn't really sure of how to properly do it, sorry for that.

It is fixed now

Copy link
Contributor

@bkabrda bkabrda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and tests are passing. Merging. Thanks a lot for your contribution!

@bkabrda bkabrda merged commit 36fba07 into DataDog:master Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants