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

Make dnsimple_records importable #9130

Merged
merged 2 commits into from
Apr 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions builtin/providers/dnsimple/import_dnsimple_record_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package dnsimple

import (
"fmt"
"os"
"testing"

"github.com/hashicorp/terraform/helper/resource"
)

func TestAccDnsimpleRecord_import(t *testing.T) {
resourceName := "dnsimple_record.foobar"
domain := os.Getenv("DNSIMPLE_DOMAIN")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDNSimpleRecordDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: fmt.Sprintf(testAccCheckDNSimpleRecordConfig_import, domain),
},
resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateIdPrefix: fmt.Sprintf("%s_", domain),
},
},
})
}

const testAccCheckDNSimpleRecordConfig_import = `
resource "dnsimple_record" "foobar" {
domain = "%s"

name = "terraform"
value = "192.168.0.10"
type = "A"
ttl = 3600
}`
19 changes: 19 additions & 0 deletions builtin/providers/dnsimple/resource_dnsimple_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ func resourceDNSimpleRecord() *schema.Resource {
Read: resourceDNSimpleRecordRead,
Update: resourceDNSimpleRecordUpdate,
Delete: resourceDNSimpleRecordDelete,
Importer: &schema.ResourceImporter{
State: resourceDNSimpleRecordImport,
},

Schema: map[string]*schema.Schema{
"domain": {
Expand Down Expand Up @@ -184,3 +187,19 @@ func resourceDNSimpleRecordDelete(d *schema.ResourceData, meta interface{}) erro

return nil
}

func resourceDNSimpleRecordImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
parts := strings.Split(d.Id(), "_")

if len(parts) != 2 {
return nil, fmt.Errorf("Error Importing dnsimple_record. Please make sure the record ID is in the form DOMAIN_RECORDID (i.e. example.com_1234")
}

d.SetId(parts[1])
d.Set("domain", parts[0])

if err := resourceDNSimpleRecordRead(d, meta); err != nil {
return nil, err
}
return []*schema.ResourceData{d}, nil
}
10 changes: 10 additions & 0 deletions website/source/docs/providers/dnsimple/r/record.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,13 @@ The following attributes are exported:
* `priority` - The priority of the record
* `domain_id` - The domain ID of the record
* `hostname` - The FQDN of the record

## Import

DNSimple resources can be imported using their domain name and numeric ID, e.g.

```
$ terraform import dnsimple_record.resource_name example.com_1234
```

The numeric ID can be found in the URL when editing a record on the dnsimple web dashboard.