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

v2.0.9 of the Provider is a breaking change / not backwards compatible #304

Closed
tlkamp opened this issue Oct 12, 2023 · 3 comments
Closed

Comments

@tlkamp
Copy link

tlkamp commented Oct 12, 2023

Terraform Version

Terraform v1.5.2

Affected Resource(s)

ns1_record

Terraform Configuration

resource "ns1_record" "dns" {
  zone   = var.domain_name
  domain = "${var.record}.${var.domain_name}"
  type   = "A"
  ttl    = var.records_ttl

  dynamic "answers" {
    for_each = toset(var.ips)
    content {
      answer = answers.value
    }
  }
}

Plan Output

  # module.indexer.ns1_record.dns will be updated in-place
  ~ resource "ns1_record" "dns" {
        id                = "[redacted]"
        # (7 unchanged attributes hidden)

      + answers {
          + answer = "[redacted]"
        }

        # (3 unchanged blocks hidden)
    }

Expected Behavior

I expected updates to the answer section on my record to succeed.

Actual Behavior

I'm receiving the following error:
Error: POST https://api.nsone.net/v1/zones/MYZONE/MYRECORD/A: 400 tags and blocked_tags must be updated together

Steps to Reproduce

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

  1. Create DNS resources with no tags or blocked_tags specified
  2. Trigger an update to the record

Workaround

  • Pin the version to v2.0.8
  • Specify values for tags and blocked_tags
    • Specifying null or empty values ({} and [] respectively) does not work

References

  • This does not occur in version v2.0.8
  • I noticed no acceptance tests were run when the merge completed, which probably would have revealed the issue.
  • I suspect it is related to the upstream ns1-go client update.
@tlkamp
Copy link
Author

tlkamp commented Oct 13, 2023

I was able to showcase the omitempty the behavior using Go Playground: https://go.dev/play/p/RyfVZ2Mubwd

The root cause is that the fields, even when empty, are now being sent to the API on POST requests and it is performing validation. The validation must not be performed when the fields are not sent, which is the old behavior.

// You can edit this code!
// Click here and start typing.
package main

import (
	"encoding/json"
	"fmt"
)

type OmitEmpties struct {
	Map    map[string]string `json:"map,omitempty"`
	List   []string          `json:"list,omitempty"`
	Number int               `json:"number"`
}

type NoOmits struct {
	Map    map[string]string `json:"map"`
	List   []string          `json:"list"`
	Number int               `json:"number"`
}

func main() {

	noOmits := &NoOmits{
		Number: 1,
	}

	omits := &OmitEmpties{
		Number: 1,
	}

	fmt.Println("OmitEmpty")
	omitBytes, err := json.Marshal(omits)
	fmt.Println(err)
	fmt.Println(string(omitBytes))

	fmt.Println()
	fmt.Println()

	fmt.Println("No Omit Empty")
	noOmitBytes, err := json.Marshal(noOmits)
	fmt.Println(err)
	fmt.Println(string(noOmitBytes))
}

Note the output:

OmitEmpty
<nil>
{"number":1}


No Omit Empty
<nil>
{"map":null,"list":null,"number":1}

@tlkamp
Copy link
Author

tlkamp commented Oct 13, 2023

Related PRs:

@pburrows-ns1
Copy link
Contributor

Closed based on discussion in ns1/ns1-go#222

@tlkamp Please open a new issue if you're still experiencing any with the latest provider version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants