-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Replace DNS NS record objects with records array #991
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @phekmat,
Thank you for opening this pr! It mostly looks good to me. Outside of the comments i have left inline:
- could we continue to use the old property in create/update if the new one is not set?
- could we create a copy of all tests with the old property on its own to ensure that it still works as expected until the deprecated property is removed?
Thanks 🙂 Look forward to getting this merged
@@ -152,31 +166,41 @@ func resourceArmDnsNsRecordDelete(d *schema.ResourceData, meta interface{}) erro | |||
return nil | |||
} | |||
|
|||
func flattenAzureRmDnsNsRecords(records *[]dns.NsRecord) []map[string]interface{} { | |||
func flattenAzureRmDnsNsRecordsSet(records *[]dns.NsRecord) []map[string]interface{} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we just get a quick //todo remove this when "record" is removed here?
@@ -122,7 +132,11 @@ func resourceArmDnsNsRecordRead(d *schema.ResourceData, meta interface{}) error | |||
d.Set("zone_name", zoneName) | |||
d.Set("ttl", resp.TTL) | |||
|
|||
if err := d.Set("record", flattenAzureRmDnsNsRecords(resp.NsRecords)); err != nil { | |||
if err := d.Set("records", flattenAzureRmDnsNsRecords(resp.NsRecords)); err != nil { | |||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we wrap this error with a bit more detail, such as:
if err := d.Set("records", flattenAzureRmDnsNsRecords(resp.NsRecords)); err != nil {
return fmt.Errorf("Error setting `records `: %+v", err)
}
return err | ||
} | ||
|
||
if err := d.Set("record", flattenAzureRmDnsNsRecordsSet(resp.NsRecords)); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @phekmat
Thanks for pushing those updates - I've taken a look through and left some comments inline (primarily, I think we can remove the state migration since this should be covered by the refresh
function), but this is mostly looking good to me :)
Thanks!
@@ -18,6 +18,8 @@ func resourceArmDnsNsRecord() *schema.Resource { | |||
Importer: &schema.ResourceImporter{ | |||
State: schema.ImportStatePassthrough, | |||
}, | |||
MigrateState: resourceArmDNSNsMigrateState, | |||
SchemaVersion: 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a migration shouldn't be needed for going from a Set -> a List - so I think we can remove this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
"record": { | ||
Type: schema.TypeSet, | ||
"records": { | ||
Type: schema.TypeList, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does the ordering matter for this? the reason for picking a Set over a List is where the fields can be returned out of order (vs a list where the ordering matters)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same concern. I couldn't find an explicit guarantee that Azure won't change the order someday, but it does respect the order in the portal and the REST API/CLI for both reads and writes.
@@ -33,9 +35,21 @@ func resourceArmDnsNsRecord() *schema.Resource { | |||
Required: true, | |||
}, | |||
|
|||
"records": { | |||
Type: schema.TypeList, | |||
//TODO: add `MinItems: 1`` and `Required: true` once we remove the `record` attribute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor MinItems: 1
is implied by the fact that this would be required, so we only actually need Required: true
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good to know. I updated the TODO
var records []dns.NsRecord | ||
|
||
//TODO: remove this once we remove the `record` attribute | ||
if d.HasChange("record") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO we should flip this around to check for records
then record
(as the else statement) since records
is now the recommended field
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me. Done
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func resourceArmDNSNsMigrateState( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(as above) I think we can remove this, since this should be handled by a refresh
which happens during a plan/apply?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -33,9 +35,21 @@ func resourceArmDnsNsRecord() *schema.Resource { | |||
Required: true, | |||
}, | |||
|
|||
"records": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we also update the documentation for this field? this is hosted in the website/docs/r/dns_ns_record.html.markdown
file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I added a warning that one or the other is required, but I'm open to changing the verbiage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @phekmat,
Thank you for the changes, this LGTM except that one of the tests is failing:
=== RUN TestAccAzureRMDnsNsRecord_withTags
--- FAIL: TestAccAzureRMDnsNsRecord_withTags (105.96s)
testing.go:513: Step 1 error: After applying this step, the plan was not empty:
DIFF:
UPDATE: azurerm_dns_ns_record.test
records.0: "ns2.contoso.com" => "ns1.contoso.com"
records.1: "ns1.contoso.com" => "ns2.contoso.com"
This looks to be a ordering issue, maybe a set is required after all?
@@ -18,6 +18,8 @@ func resourceArmDnsNsRecord() *schema.Resource { | |||
Importer: &schema.ResourceImporter{ | |||
State: schema.ImportStatePassthrough, | |||
}, | |||
// MigrateState: resourceArmDNSNsMigrateState, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we remove these comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@katbyte That's actually a bug I introduced with the last commit in inverting the |
- Replace and deprecate the `azurerm_dns_ns_record.record` objects with a single `records` array to simplify working with DNS zone resources - Duplicate tests to have coverage for the deprecated attribute - Add test for migrating from `record` attributes to `records` - Add TODOs to remove code once the deprecated attribute is removed - Update docs for the new attribute
I've fixed the issue causing the test failure (though I think it can be simplified; I'm not 100% sure). I've also added a test for changing from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the changes, this LGTM now 👍
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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks! |
azurerm_dns_ns_record.record
objects witha single
records
array to simplify working with DNS zone resourcesThe motivation behind this was primarily to be able to use
azurerm_dns_zone.name_servers
directly, but it's equally useful with plainvariable
s. TXT records have the same issue and it would be nice to give it the same treatment.