dnsimple / terraform-provider-dnsimple

Terraform DNSimple provider.
https://www.terraform.io/docs/providers/dnsimple/
Mozilla Public License 2.0
22 stars 20 forks source link

nil entry in ImportState results #18

Closed jamesarosen closed 4 years ago

jamesarosen commented 5 years ago

Terraform Version

0.12.6

Affected Resource(s)

Terraform Configuration Files

provider "dnsimple" {
  version = "~> 0.2.0"
}

resource "dnsimple_record" "www_mycompany_com" {
  domain    = "www.mycompany.com"
  name      = "www.mycompany.com"
  ttl       = 60
  type      = "CNAME"
  value     = "www.origins.mycompany.com"
}

Expected Behavior

terraform import dnsimple_record.www_mycompany_com www.mycompany.com_123456789 should import the domain.

Actual Behavior

What actually happened?

dnsimple_record.www_mycompany_com: Importing from ID "www.mycompany.com_123456789"...

Error: nil entry in ImportState results. This is always a bug with
the resource that is being imported. Please report this as
a bug to Terraform.

Steps to Reproduce

  1. export DNSIMPLE_ACCOUNT=1234
  2. export DNSIMPLE_TOKEN=abcde12345ABCDE
  3. create a DNS record in DNSimple
  4. get the ID of the record
  5. write a matching dnsimple_record resource
  6. run terraform import dnsimple_record.my_record my.domain_12345

Important Factoids

I'm using a user token, not an account token. We're on the "Silver" plan, which doesn't allow multiple users.

When I run

curl -H 'Authorization: Bearer abcde12345ABCDE' https://api.dnsimple.com/v2/whoami

I get back

{
  "data": {
    "user": {
      "id": 9876,
      "email": "me@mycompany.com",
      "created_at":"2012-07-20T08:16:56Z",
      "updated_at":"2019-08-02T16:24:28Z"
    },
    "account":null
  }
}

I'm not 100% sure that I have the right thing set for DNSIMPLE_ACCOUNT. I've tried:

jamesarosen commented 5 years ago

I've now also tried this with an Account Token:

curl -H 'Authorization: Bearer MYACCOUNTTOKEN' https://api.dnsimple.com/v2/whoami
{
  "data": {
    "user": null,
    "account": {
      "id": 7812,
      "email": "me@mycompany.com",
      "plan_identifier":"silver-v2-monthly",
      "created_at":"2012-07-20T08:16:56Z",
      "updated_at":"2019-07-18T03:55:54Z"
    }
  }
}

But I get the same result when running terraform import.

jamesarosen commented 5 years ago

Oh! I finally figured it out. The Terraform object ID is mycompany.com_123456789, not www.mycompany.com_123456789. It's

terraform import dnsimple_record.child parent.com_CHILDID

I definitely didn't understand the docs. It would be lovely to make that distinction a little clearer!

weppos commented 4 years ago

I definitely didn't understand the docs. It would be lovely to make that distinction a little clearer!

Can you point me to the docs that is misleading?

jamesarosen commented 4 years ago

https://www.terraform.io/docs/providers/dnsimple/r/record.html#import says

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.

"domain name" is ambiguous. www.example.com is a fully-qualified domain name. example.com is an apex domain.

weppos commented 4 years ago

In the context of dnsimple, www.example.com and example.com are both records of the example.com domain.

The documentation uses the terms "domain" as argument, and "hostname" as attribute. The "hostname" is the fully-qualified record name you are referring to.

I expanded the examples a bit so hopefully this is more clear. Thanks for the feedback.