-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
add OpenStack DNS V2 RecordSet resource #14813
Conversation
@jtopjian for review at your convenience. I was able to use your stand-alone Designate environment to test this. It was much easier to understand than the AIO. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, this works really well. There's a variety of changes to put the finishing touches on it.
The biggest is the import
stuff. Second is the TypeList
.
Let me know if you have questions or need help with any of it.
Target: []string{"ACTIVE"}, | ||
Pending: []string{"PENDING"}, | ||
Refresh: waitForDNSRecordSet(dnsClient, zoneID, n.ID), | ||
Timeout: d.Timeout(schema.TimeoutCreate), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
schema.TimeoutUpdate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckDNSV2RecordSetExists("openstack_dns_recordset_v2.recordset_1", &recordset), | ||
resource.TestCheckResourceAttr( | ||
"openstack_dns_recordset_v2.recordset_1", "description", "a record set"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add checks for the records where appropriate? Something like:
resource.TestCheckResourceAttr(
"openstack_dns_recordset_v2.recordset_1", "records.0", "10.1.0.0"),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea
description = "An example record set" | ||
ttl = 3000 | ||
type = "A" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a record to the example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
||
resource "openstack_dns_recordset_v2" "rs.example.com" { | ||
zone_id = "${openstack_dns_zone_v2.example_zone.id}" | ||
name = "example.com." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this www.example.com.
(or rs.example.com
as the name is above)? Just to clarify to the user that this is where they will want to create subdomains for their zone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
ForceNew: false, | ||
}, | ||
"records": &schema.Schema{ | ||
Type: schema.TypeSet, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The good news is that we can use TypeList
. The DNS API is returning the records in the same order as specified. That's a rarity and it's also a better user experience since they can reference records using standard integer index (as well as be able to map/interpolate count
with a series of Compute instances, each with an IP address of the records!).
The bad news is that TypeSet
will need changed to TypeList
. It's pretty minor, though. You should be able to iterate over it by doing d.Get("records").([]interface)
. Grep for TypeList
in another OpenStack resource for examples and let me know if you need help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, nice, I'd forgotten there was a TypeList
type.
## Import | ||
|
||
This resource can be imported by specifying all three arguments, separated | ||
by a forward slash: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops. Just noticed this was carried over from the original doc I copied when I made the zone docs. This should read:
This resource can be imported by specifying the zone ID and recordset ID, separated by a forward slash.
I will take care of the zone doc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
by a forward slash: | ||
|
||
``` | ||
$ terraform import openstack_dns_recordset_v2.recordset_1 <recordset_id> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the idea of terraform import
is to create a terraform.tfstate
file that is populated by resources that do not exist in a .tf
file. While import
will not create the HCL, it will allow Terraform to recognize that those resources exist (so you can base other resources off of them and such).
When importing, you have to specify enough information to bootstrap Terraform to be able to look up the rest of the information. In this case, a Zone ID and RR ID is required. When doing this on the command line as it is now, the following error happens:
# terraform import openstack_dns_recordset_v2.foo 5805f911-1e86-44b1-8637-dfa73c2d3176
openstack_dns_recordset_v2.foo: Importing from ID "5805f911-1e86-44b1-8637-dfa73c2d3176"...
openstack_dns_recordset_v2.foo: Import complete!
Imported openstack_dns_recordset_v2 (ID: 5805f911-1e86-44b1-8637-dfa73c2d3176)
openstack_dns_recordset_v2.foo: Refreshing state... (ID: 5805f911-1e86-44b1-8637-dfa73c2d3176)
Error importing: 1 error(s) occurred:
* openstack_dns_recordset_v2.foo (import id: 5805f911-1e86-44b1-8637-dfa73c2d3176): 1 error(s) occurred:
* import openstack_dns_recordset_v2.foo result: 5805f911-1e86-44b1-8637-dfa73c2d3176: import openstack_dns_recordset_v2.foo (id: 5805f911-1e86-44b1-8637-dfa73c2d3176): Terraform detected a resource with this ID doesn't
exist. Please verify the ID is correct. You cannot import non-existent
resources using Terraform import.
So we need to use both Zone ID and RR ID. The catch is that the command-line only accepts one argument. So that's where the "separated by a forward slash" comes in.
See the resource_openstack_compute_floatingip_associate_v2.go
resource for how to handle this. That resource is an edge case because all resource attributes are shoved in the faux ID. Here we'll just do the zone and rr.
Out of all the changes requested, this is the most important as it involves what the ID of the resource will be. It won't be fun to change that later.
If you're wondering why the _importBasic
acc test passed, it's because all bootstrap information was available in the _basic
test and it only checks that all resource attributes are populated correctly in the Read
.
Let me know if you need a hand with this.
edit: resource_openstack_compute_volume_attach_v2.go
is another resource to use as an example. I just remembered resource_openstack_compute_floatingip_associate_v2.go
now mixes the compute and networking API, which was done afterwards, and might make some of the inline comments confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, a Zone ID and RR ID is required
Ah, OK; I'd suspected that, but didn't see it anywhere else (except of course it's clearly in the file you mentioned). I should have just tried the command-line import command. Will fix.
That's awesome - I'm glad you got it working. |
042ff48
to
92d859d
Compare
|
||
d.Set("name", n.Name) | ||
d.Set("description", n.Description) | ||
d.Set("ttl", n.TTL) | ||
d.Set("type", n.Type) | ||
d.Set("records", n.Records) | ||
d.Set("region", GetRegion(d)) | ||
d.Set("zone_id", n.ZoneID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jrperritt d.Set("zone_id", zoneID)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I was just narrowing down the search space for things that were causing errors. I found it in the test (I hadn't added parseDNSV2RecordSetID
). Running the tests now to verify they pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah - gotcha. Everything else looks good. You're on a mission tonight :)
Let me know when you're good and I'll do one final sweep.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And as I just found out (and I'm sure you already knew), the import verification condition will fail if the zone_id
isn't set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=== RUN TestAccDNSV2RecordSet_importBasic
--- FAIL: TestAccDNSV2RecordSet_importBasic (192.40s)
testing.go:280: Step 1 error: ImportStateVerify attributes not equivalent. Difference is shown below. Top is actual, bottom is expected.
(map[string]string) {
}
(map[string]string) (len=1) {
(string) (len=7) "zone_id": (string) (len=36) "68d14ad5-b21c-4a2a-9208-ca01dfa3677c"
}
Can you see anything obvious that may still be wrong with the importBasic
test setup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed it locally by adding what I mentioned above and it passed twice for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I just didn't pull down the most recent changes I made. OK, I think I'm done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, confirmed that I didn't fetch the most recent changes I made. All tests passing for me now, too.
@jtopjian I think I've addressed all the feedback. Thank you for the review and the help. |
No problem at all. Nice work on this and thank you for making all of the changes. I just pulled a clean branch and running the tests one last time. |
Good to go! Thank you for adding this!
|
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
For #14735
In addition, while I was testing I stumbled upon a panic condition while updating a DNS zone, so the third commit here addresses that.