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

NS1 Provider: Modeling ns1 metadata #13636

Closed
pashap opened this issue Apr 13, 2017 · 5 comments
Closed

NS1 Provider: Modeling ns1 metadata #13636

pashap opened this issue Apr 13, 2017 · 5 comments

Comments

@pashap
Copy link
Contributor

pashap commented Apr 13, 2017

There has been a struggle to model NS1 record metadata within the ns1 provider. The crux of the problem has to do with the fact that ns1 metadata is used within nested objects of the record resource and that its important not to use default values when ns1 metadata fields are absent from the configuration.

Ideally, the ns1 record resource could contain nested meta schemas that represent ns1 metadata:

provider "ns1" {
}

resource "ns1_zone" "basic" {
  zone = "testzone.test"
}

resource "ns1_record" "basic" {
  zone = "${ns1_zone.basic.zone}"
  domain = "www.${ns1_zone.basic.zone}"
  type = "CNAME"
  ttl = 60
  meta = { 
    up = true
    weight = 10
  }

  answers = {
    answer = "sub1.${ns1_zone.basic.zone}"
    meta = { 
      up = true
      weight = 10
    }
  }
  answers = {
    answer = "sub2.${ns1_zone.basic.zone}"
    meta = { 
      up = false
      weight = 5
    }
  }
  answers = {
    answer = "sub3.${ns1_zone.basic.zone}"
    meta = {  // <- meta.up will be false bc of default value with d.GetOk
      weight = 5
    }
  }

}

I have tried "flattening" the ns1 metadata structure, but still run into the same issue of absent fields != default values for answers:

provider "ns1" {
}

resource "ns1_zone" "basic" {
  zone = "testzone.test"
}

resource "ns1_record" "basic" {
  zone = "${ns1_zone.basic.zone}"
  domain = "www.${ns1_zone.basic.zone}"
  type = "CNAME"
  ttl = 60
  // ns1 metadata fields
  up = true
  weight = 10

  answers = {
    answer = "sub1.${ns1_zone.basic.zone}"
    // ns1 metadata fields
    up = true
    weight = 10
  }
  answers = {
    answer = "sub2.${ns1_zone.basic.zone}"
    // ns1 metadata fields 
    up = false
    weight = 5
  }
  answers = {
    answer = "sub3.${ns1_zone.basic.zone}"
    // ns1 metadata fields
    // without setting "up", it is still false as a default for the "answers" schema
    weight = 5
  }

}

There is an open issue addressing how to get d.GetOk to properly detect absence from config vs default values.

Are there any suggestions for how to model nested schemas within a resource that need to differentiate between a field being absent and its default?

References

@catsby
Copy link
Contributor

catsby commented May 2, 2017

Hello – 

The issue #5694 is a frustrating one for sure. I'm not sure we have a complete solution for that yet.

As a workaround, do you think you could define up to be a TypeString instead of TypeBool? It's a bit odd for sure, but Terraform will convert the boolean value of true in configurations to 1 and false to 0, and save them as strings as well, so the value is safe in parseBool.

I wrote an example implementation in a "fake" resource here:

Conceptually it's this:

In summary, omitting the value will get you "", and true or "true" (string) will get you a boolean value.

I think that should work here, but please let me know what you think!

@catsby catsby added the waiting-response An issue/pull request is waiting for a response from the community label May 2, 2017
@catsby
Copy link
Contributor

catsby commented May 8, 2017

I'm going to close this for now. The crux of the issue is #5694, hopefully my idea above is a viable workaround.

Thanks!

@catsby catsby closed this as completed May 8, 2017
@catsby catsby removed the waiting-response An issue/pull request is waiting for a response from the community label May 8, 2017
@pashap
Copy link
Contributor Author

pashap commented May 8, 2017

@catsby Thanks for the detailed explanation/proposed solution! This looks like it will do the trick, as soon as i get time(should be in the next two weeks), i will try implementing it with the NS1 provider. Thanks again for the examples

@catsby
Copy link
Contributor

catsby commented May 8, 2017

You're very welcome! Thanks for raising the issue, sorry that #5694 is still unresolved 😦

@ghost
Copy link

ghost commented Apr 13, 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 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants