-
Notifications
You must be signed in to change notification settings - Fork 53
Allow existing powerdns_records to be updated instead of destroyed & recreated #78
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
base: master
Are you sure you want to change the base?
Conversation
Hi, thanks for the pull request. Please add tests that confirm this patch works. Thank you. |
I just noticed current tests in the master are broken. I will try to fix them, if not possible, I'll revert the commit that introduced problems, then please rebase and add tests, thank you. |
Great, thanks. I noticed testacc failed on master for me but I wasn't sure if it was a actual failure or my environment. Do both |
@ag-TJNII they both look for tests in
Using |
So to test updates I need to know the inputs to the resource so I can compare current record state to desired record state to make sure the record is updated. This is going to be very difficult with the current test input as const strings model. To add tests I'm thinking:
I've created a branch with the baseline of these changes here: master...ag-TJNII:TJNII-powerdns_record_test_refactor This branch is not done but it does show the pattern I have in mind. This is a pretty significant refactor. I believe it will improve the tests as it will add record field verification to all record types for both create and update. However I don't want to unilaterally rewrite this suite. What's the team's opinion on this proposal? Is this direction acceptable, or should I rethink my strategy? |
Check out Terraform Best practices regarding testing, there is an example on how to test resource update: https://www.terraform.io/docs/extend/best-practices/testing.html#update-test-verify-configuration-changes |
…g attribute values
454852d
to
e63bee2
Compare
e63bee2
to
632c081
Compare
Updated the test suite to verify updates. The test suite update:
I modified all the basic record tests to check for updates as well as creation. I do not check the values in the Terraform state using This is a fairly large refactor of the test suite, which is generally not a nice thing to do to someone else's code base, however I wasn't able to think of a way to do these tests using the old pattern without a significant amount of duplicated code. Please let me know if you'd prefer the tests to be handled another way. Thanks! |
Also after thinking through the tests & API calls I limited this behavior change to ttl and records, as changing the zone, name, or type is creating a new entity in PDNS. |
Testing state has it's purpose and meaning. Please read https://www.terraform.io/docs/extend/testing/acceptance-tests/teststep.html I know you mean well, but I cannot accept this pull request as it ignores terraform testing practices. Testing resource update isn't anything new or unique to this provider, again please check the documentation |
I have read those documents many times, and unfortunately they don't document how to test updates on complex data types like TypeSets. This is the reason I skipped them in the current commit, I was not ignoring best practice. After searching more I see Terraform allows the records to be accessed by the hash used to index the values internally, but I can't seem to find how to get that hash ID. I see the zone test has these hash IDs baked in:
How did you determine that |
@ag-TJNII to answer your question demo
https://play.golang.org/p/vUw7w6Fr-HC see:
|
…improce inline documentation
Okay, thanks to @hwshadow's excellent tip I've added Terraform state attribute checking via the resource.TestCheckResourceAttr() test check function. This test suite now:
The test suite now implements the best practices implemented in https://www.terraform.io/docs/extend/best-practices/testing.html#update-test-verify-configuration-changes, and overall is a significant upgrade over the current test suite in master which only verifies that a record was created, but does not validate any attributes. @mbag I believe I've addressed your concerns, please let me know if not. Thanks! |
Hi, @mbag. Have you had a moment to review the changes? I need to begin using these changes so I'd like to prioritize any further work needed. |
@mbag Can I get an approve or feedback on what other changes are needed please? I've addressed your concerns. |
hi @ag-TJNII the functionality this PR adds is needed, but the complete rewrite of the tests would make the maintenance harder. I've checked some of the providers and at most they use Also the acceptance tests cases are similar to what we have now, meaning noone minds code repetition in test cases. |
@mbag I agree refactoring the tests is a big change, I was very hesitant about it. However, the original "string hcl" test pattern only tested that a record was created, it didn't test any values. This is the biggest reason why I changed from static hcl strings to these objects, so that the test input could be compared with what is in both tf state and in powerdns. This refactor greatly increases the test coverage as it allows the test to verify the actual record contents written into PowerDNS. It also greatly cuts down on the amount of boilerplate code needed to test updates as two very similar but slightly different HCL strings aren't needed. I believe this will make testing much easier and more robust in the long term, and I believe this change was necessary to get the level of test coverage requested for the original change. Yes, there is a function that generates the HCL that will need to be maintained, but I believe the gains outweigh the losses here. Please make sure the greatly increased test coverage added here isn't overlooked before you 👎 . |
Hi, any news on this? If the test suite changes are the only concern left, we could split them into a separate PR - though it would be nice to have both the new functionality and the improved test coverage. |
This PR modifies the powerdns_record provider to not delete and recreate records on argument change. The change is fairly minor, as PowerDNS creates and updates use the same API call this simply uses the existing
resourcePDNSRecordCreate
function for updates and setsForceNew
to false. I did not setForceNew: false
onset_ptr
as I'm not familiar with that functionality, so I err'd on the side of safety by leaving the delete/recreate behavior.Resolves #77