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

add OpenStack DNS V2 RecordSet resource #14813

Merged
merged 4 commits into from
May 25, 2017
Merged

Conversation

jrperritt
Copy link
Contributor

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.

@jrperritt
Copy link
Contributor Author

jrperritt commented May 25, 2017

@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.

Copy link
Contributor

@jtopjian jtopjian left a 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),
Copy link
Contributor

Choose a reason for hiding this comment

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

schema.TimeoutUpdate

Copy link
Contributor Author

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"),
Copy link
Contributor

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"),

Copy link
Contributor Author

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"
}
Copy link
Contributor

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?

Copy link
Contributor Author

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."
Copy link
Contributor

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.

Copy link
Contributor Author

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,
Copy link
Contributor

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.

Copy link
Contributor Author

@jrperritt jrperritt May 25, 2017

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:
Copy link
Contributor

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.

Copy link
Contributor Author

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>
Copy link
Contributor

@jtopjian jtopjian May 25, 2017

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.

Copy link
Contributor Author

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.

@jtopjian
Copy link
Contributor

I was able to use your stand-alone Designate environment to test this. It was much easier to understand than the AIO.

That's awesome - I'm glad you got it working.

@jrperritt jrperritt force-pushed the 14735 branch 3 times, most recently from 042ff48 to 92d859d Compare May 25, 2017 04:15

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)
Copy link
Contributor

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)

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@jrperritt
Copy link
Contributor Author

@jtopjian I think I've addressed all the feedback. Thank you for the review and the help.

@jtopjian
Copy link
Contributor

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.

@jtopjian
Copy link
Contributor

Good to go! Thank you for adding this!

==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/05/25 04:42:42 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/openstack -v -run=TestAccDNSV2RecordSet -timeout 120m
=== RUN   TestAccDNSV2RecordSet_importBasic
--- PASS: TestAccDNSV2RecordSet_importBasic (201.94s)
=== RUN   TestAccDNSV2RecordSet_basic
--- PASS: TestAccDNSV2RecordSet_basic (252.42s)
=== RUN   TestAccDNSV2RecordSet_readTTL
--- PASS: TestAccDNSV2RecordSet_readTTL (201.49s)
=== RUN   TestAccDNSV2RecordSet_timeout
--- PASS: TestAccDNSV2RecordSet_timeout (201.34s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/openstack      857.207s

@ghost
Copy link

ghost commented Apr 12, 2020

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.

@ghost ghost locked and limited conversation to collaborators Apr 12, 2020
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