hashicorp / terraform-provider-ultradns

Terraform UltraDNS provider. Please note: This Terraform provider is archived per our provider archiving process: https://terraform.io/docs/internals/archiving.html
https://www.terraform.io/docs/providers/ultradns/
Mozilla Public License 2.0
7 stars 24 forks source link

Support tf import for ultradns_record resource #16

Open ericksoen opened 4 years ago

ericksoen commented 4 years ago

Terraform Version

$ terraform --version
Terraform v0.11.11
+ provider.ultradns v0.1.0

Affected Resource(s)

Please list the resources as a list, for example:

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

provider "ultradns" {}

resource "ultradns_record" "domain" {
  zone  = "domain.com"
  name  = "shiny-app.domain.com"
  rdata = ["127.0.0.1"]
  type  = "A"
  ttl   = "600"
}

Debug Output

tf import ultradns_record.domain shiny-app.domain.com.domain.com
ultradns_record.domain: Importing from ID "shiny-app.domain.com.domain.com"...

Error: ultradns_record.domain (import id: shiny-app.domain.com.domain.com): import ultradns_record.domain (id: shiny-app.domain.com.domain.com): resource ultradns_record doesn't support import

Expected Behavior

Terraform import adds resource to state file and refreshes

Actual Behavior

Resource does not support import

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply

Important Factoids

From some initial investigation, it looks like there are two primary issues (beyond the missing Importer func on the resource record) that complicate an elegant solution:

  1. The composite id, OwnerName.Zone uses a period as delimiter character, making it difficult to accurately parse out the constituent parts necessary to run the refresh operation post-import. In the example above, the resource id includes four . characters.
    • You can potentially iterate through all the potential combinations of tokens and validate via a regular expression if each of the parts evaluates to a valid DNS, but an ID spec that uses a character that is not permitted in a DNS record name would significantly simplify the parsing behavior.
  2. The resource id does not include the required Type property necessary to construct a valid request to the UltraDNS API.

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:

sreckamp commented 4 years ago

It might also be useful to not that the id "shiny-app.domain.com.domain.com" is in the form name.zone and the name ends with the zone. This would be helpful in parsing the id.

func parse(id string) (name, zone string) {
    var id_parts = strings.Split(id, ".");
    for x := len(id_parts) - 1 ; x >=0; x -- {
        var n = strings.Join(id_parts[0:x], ".")
        var z = strings.Join(id_parts[x:], ".")
        if len(n) < len(z) {
            break
        }
        if strings.HasSuffix(n, z) {
            name = n
            zone = z
            return
        }
    }
    return
}