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

Replace DNS NS record objects with records array #991

Merged
merged 1 commit into from
Jun 6, 2018

Conversation

phekmat
Copy link
Contributor

@phekmat phekmat commented Mar 16, 2018

  • Replace and deprecate the azurerm_dns_ns_record.record objects with
    a single records array to simplify working with DNS zone resources

The motivation behind this was primarily to be able to use azurerm_dns_zone.name_servers directly, but it's equally useful with plain variables. TXT records have the same issue and it would be nice to give it the same treatment.

Copy link
Collaborator

@katbyte katbyte left a 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{} {
Copy link
Collaborator

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
Copy link
Collaborator

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@tombuildsstuff tombuildsstuff added this to the Soon milestone May 24, 2018
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a 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,
Copy link
Contributor

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

Copy link
Contributor Author

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,
Copy link
Contributor

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)

Copy link
Contributor Author

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
Copy link
Contributor

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 :)

Copy link
Contributor Author

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") {
Copy link
Contributor

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

Copy link
Contributor Author

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(
Copy link
Contributor

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?

Copy link
Contributor Author

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": {
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Collaborator

@katbyte katbyte left a 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,
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@phekmat
Copy link
Contributor Author

phekmat commented Jun 4, 2018

@katbyte That's actually a bug I introduced with the last commit in inverting the if condition in expandAzureRmDnsNsRecords. I'll fix that and re-run the acceptance tests locally to verify

- 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
@phekmat
Copy link
Contributor Author

phekmat commented Jun 4, 2018

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 record to records.

Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phekmat,

Thank you for the changes, this LGTM now 👍

@katbyte
Copy link
Collaborator

katbyte commented Jun 6, 2018

Tests pass:
screen shot 2018-06-05 at 18 23 32

@katbyte katbyte merged commit eac118c into hashicorp:master Jun 6, 2018
@katbyte katbyte modified the milestones: Soon, 1.7.0 Jun 6, 2018
katbyte added a commit that referenced this pull request Jun 6, 2018
@ghost
Copy link

ghost commented Mar 31, 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 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!

@ghost ghost locked and limited conversation to collaborators Mar 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants