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

[MS] Adding DNS PTR Record #141

Merged
merged 7 commits into from
Jul 3, 2017
Merged

[MS] Adding DNS PTR Record #141

merged 7 commits into from
Jul 3, 2017

Conversation

echuvyrov
Copy link
Contributor

Enabling the creation of DNS PTR Record

"records": &schema.Schema{
Type: schema.TypeSet,
Required: true,
Elem: &schema.Schema{Type: schema.TypeString},
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this contain zero records?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It cannot, it would be invalid

}
}

func resourceArmDnsPtrRecordCreate(d *schema.ResourceData, meta interface{}) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

resourceArmDnsPtrRecordCreateOrUpdate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

RecordSetProperties: &props,
}

_, err := dnsClient.CreateOrUpdate(resGroup, zoneName, name, dns.PTR, parameters, "", "")
Copy link
Contributor

Choose a reason for hiding this comment

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

It is not obvious what the last two parameters are and why are they empty strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, changed second-to-last parameter to properly be the eTag of the record and added comments explaining why the last parameter is empty

return err
}

rec, err := dnsClient.Get(resGroup, zoneName, name, dns.PTR)
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the dnsClient.CreateOrUpdate method's "response" return value already contains the resource ID, there is no need to call Get just to retrieve the ID value.

rec, err := dnsClient.CreateOrUpdate(...)

if err != nil {
    return err
}
d.SetId(*rec.ID)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, changed

Copy link
Member

@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 @echuvyrov

Thanks for this PR - I've taken a look and left some comments in-line - but this is looking good!

Thanks!

@@ -124,6 +124,8 @@ func Provider() terraform.ResourceProvider {

"azurerm_application_insights": resourceArmApplicationInsights(),

//PTR record uses Azure Go SDK
Copy link
Member

Choose a reason for hiding this comment

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

minor: can we move this sorted alphabetically under the Azure SDK for Go comment?

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


metadata := expandTags(tags)

recordStrings := d.Get("records").(*schema.Set).List()
Copy link
Member

Choose a reason for hiding this comment

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

we'd generally tend to pull this out into a separate function - could we update this to match?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed


resp, err := dnsClient.Get(resGroup, zoneName, name, dns.PTR)
if err != nil {
return fmt.Errorf("Error reading DNS PTR record %s: %s", name, err)
Copy link
Member

Choose a reason for hiding this comment

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

this last one should be %+v as it's an error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed, thanks for catching that!

d.Set("zonename", zoneName)
d.Set("ttl", resp.TTL)

if resp.PtrRecords != nil {
Copy link
Member

Choose a reason for hiding this comment

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

we'd generally pull this out into a Flatten method - could we update this to match?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed


func TestAccAzureRMDnsPtrRecord_basic(t *testing.T) {
ri := acctest.RandInt()
config := fmt.Sprintf(testAccAzureRMDnsPtrRecord_basic, ri, ri, ri)
Copy link
Member

Choose a reason for hiding this comment

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

could we switch this to match the newer resources by making this a function which returns a formatted string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

func TestAccAzureRMDnsPtrRecord_updateRecords(t *testing.T) {
ri := acctest.RandInt()
preConfig := fmt.Sprintf(testAccAzureRMDnsPtrRecord_basic, ri, ri, ri)
postConfig := fmt.Sprintf(testAccAzureRMDnsPtrRecord_updateRecords, ri, ri, ri)
Copy link
Member

Choose a reason for hiding this comment

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

(same here)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

func TestAccAzureRMDnsPtrRecord_withTags(t *testing.T) {
ri := acctest.RandInt()
preConfig := fmt.Sprintf(testAccAzureRMDnsPtrRecord_withTags, ri, ri, ri)
postConfig := fmt.Sprintf(testAccAzureRMDnsPtrRecord_withTagsUpdate, ri, ri, ri)
Copy link
Member

Choose a reason for hiding this comment

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

(same here)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

Check: resource.ComposeTestCheckFunc(
testCheckAzureRMDnsPtrRecordExists("azurerm_dns_ptr_record.test"),
resource.TestCheckResourceAttr(
"azurerm_dns_ptr_record.test", "tags.%", "2"),
Copy link
Member

Choose a reason for hiding this comment

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

do we want to check the ordering of the values here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

Copy link
Member

Choose a reason for hiding this comment

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

apologies, I'd closed the wrong comment box and had meant to put this here. on reflection this isn't such a big deal, given we're asserting the number of entries in place.

conn := testAccProvider.Meta().(*ArmClient).dnsClient
resp, err := conn.Get(resourceGroup, zoneName, ptrName, dns.PTR)
if err != nil {
return fmt.Errorf("Bad: Get PTR RecordSet: %s", err)
Copy link
Member

Choose a reason for hiding this comment

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

this needs to be %+v

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

Create a DNS PTR Record.
---

# azurerm\_dns\_a\_record
Copy link
Member

Choose a reason for hiding this comment

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

*ptr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

@echuvyrov
Copy link
Contributor Author

@tombuildsstuff @whiskeyjay made the changes you guys suggested, thanks! The only one I wasn't sure about was about order checking in the tests - I added tag checking, lmk if you meant something else.

Copy link
Member

@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 @echuvyrov

Thanks for pushing those updates - I've pushed a commit to resolve a couple of minor issues I noticed below (I hope you don't mind) - and this now LGTM :)

Tests pass:

$ TF_ACC=1 envchain azurerm go test ./azurerm -v -timeout 120m -run TestAccAzureRMDns
=== RUN   TestAccAzureRMDnsARecord_importBasic
--- PASS: TestAccAzureRMDnsARecord_importBasic (106.92s)
=== RUN   TestAccAzureRMDnsAAAARecord_importBasic
--- PASS: TestAccAzureRMDnsAAAARecord_importBasic (92.47s)
=== RUN   TestAccAzureRMDnsCNameRecord_importBasic
--- PASS: TestAccAzureRMDnsCNameRecord_importBasic (92.02s)
=== RUN   TestAccAzureRMDnsMxRecord_importBasic
--- PASS: TestAccAzureRMDnsMxRecord_importBasic (91.66s)
=== RUN   TestAccAzureRMDnsNsRecord_importBasic
--- PASS: TestAccAzureRMDnsNsRecord_importBasic (92.20s)
=== RUN   TestAccAzureRMDnsPtrRecord_importBasic
--- PASS: TestAccAzureRMDnsPtrRecord_importBasic (74.45s)
=== RUN   TestAccAzureRMDnsSrvRecord_importBasic
--- PASS: TestAccAzureRMDnsSrvRecord_importBasic (94.21s)
=== RUN   TestAccAzureRMDnsTxtRecord_importBasic
--- PASS: TestAccAzureRMDnsTxtRecord_importBasic (93.43s)
=== RUN   TestAccAzureRMDnsZone_importBasic
--- PASS: TestAccAzureRMDnsZone_importBasic (89.80s)
=== RUN   TestAccAzureRMDnsARecord_basic
--- PASS: TestAccAzureRMDnsARecord_basic (88.74s)
=== RUN   TestAccAzureRMDnsARecord_updateRecords
--- PASS: TestAccAzureRMDnsARecord_updateRecords (91.76s)
=== RUN   TestAccAzureRMDnsARecord_withTags
--- PASS: TestAccAzureRMDnsARecord_withTags (103.81s)
=== RUN   TestAccAzureRMDnsAAAARecord_basic
--- PASS: TestAccAzureRMDnsAAAARecord_basic (78.32s)
=== RUN   TestAccAzureRMDnsAAAARecord_updateRecords
--- PASS: TestAccAzureRMDnsAAAARecord_updateRecords (106.47s)
=== RUN   TestAccAzureRMDnsAAAARecord_withTags
--- PASS: TestAccAzureRMDnsAAAARecord_withTags (110.22s)
=== RUN   TestAccAzureRMDnsCNameRecord_basic
--- PASS: TestAccAzureRMDnsCNameRecord_basic (89.36s)
=== RUN   TestAccAzureRMDnsCNameRecord_subdomain
--- PASS: TestAccAzureRMDnsCNameRecord_subdomain (95.82s)
=== RUN   TestAccAzureRMDnsCNameRecord_updateRecords
--- PASS: TestAccAzureRMDnsCNameRecord_updateRecords (94.08s)
=== RUN   TestAccAzureRMDnsCNameRecord_withTags
--- PASS: TestAccAzureRMDnsCNameRecord_withTags (108.93s)
=== RUN   TestAccAzureRMDnsMxRecord_basic
--- PASS: TestAccAzureRMDnsMxRecord_basic (74.31s)
=== RUN   TestAccAzureRMDnsMxRecord_updateRecords
--- PASS: TestAccAzureRMDnsMxRecord_updateRecords (106.70s)
=== RUN   TestAccAzureRMDnsMxRecord_withTags
--- PASS: TestAccAzureRMDnsMxRecord_withTags (136.45s)
=== RUN   TestAccAzureRMDnsNsRecord_basic
--- PASS: TestAccAzureRMDnsNsRecord_basic (91.50s)
=== RUN   TestAccAzureRMDnsNsRecord_updateRecords
--- PASS: TestAccAzureRMDnsNsRecord_updateRecords (145.28s)
=== RUN   TestAccAzureRMDnsNsRecord_withTags
--- PASS: TestAccAzureRMDnsNsRecord_withTags (106.33s)
=== RUN   TestAccAzureRMDnsPtrRecord_basic
--- PASS: TestAccAzureRMDnsPtrRecord_basic (82.45s)
=== RUN   TestAccAzureRMDnsPtrRecord_updateRecords
--- PASS: TestAccAzureRMDnsPtrRecord_updateRecords (125.35s)
=== RUN   TestAccAzureRMDnsPtrRecord_withTags
--- PASS: TestAccAzureRMDnsPtrRecord_withTags (89.33s)
=== RUN   TestAccAzureRMDnsSrvRecord_basic
--- PASS: TestAccAzureRMDnsSrvRecord_basic (70.97s)
=== RUN   TestAccAzureRMDnsSrvRecord_updateRecords
--- PASS: TestAccAzureRMDnsSrvRecord_updateRecords (103.76s)
=== RUN   TestAccAzureRMDnsSrvRecord_withTags
--- PASS: TestAccAzureRMDnsSrvRecord_withTags (89.54s)
=== RUN   TestAccAzureRMDnsTxtRecord_basic
--- PASS: TestAccAzureRMDnsTxtRecord_basic (73.52s)
=== RUN   TestAccAzureRMDnsTxtRecord_updateRecords
--- PASS: TestAccAzureRMDnsTxtRecord_updateRecords (101.40s)
=== RUN   TestAccAzureRMDnsTxtRecord_withTags
--- PASS: TestAccAzureRMDnsTxtRecord_withTags (104.44s)
=== RUN   TestAccAzureRMDnsZone_basic
--- PASS: TestAccAzureRMDnsZone_basic (85.98s)
=== RUN   TestAccAzureRMDnsZone_withTags
--- PASS: TestAccAzureRMDnsZone_withTags (99.68s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	3481.650s

Thanks!

return err
}

log.Printf("[INFO] here is actual %v", id)
Copy link
Member

Choose a reason for hiding this comment

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

can we remove this comment?

Check: resource.ComposeTestCheckFunc(
testCheckAzureRMDnsPtrRecordExists("azurerm_dns_ptr_record.test"),
resource.TestCheckResourceAttr(
"azurerm_dns_ptr_record.test", "tags.%", "2"),
Copy link
Member

Choose a reason for hiding this comment

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

apologies, I'd closed the wrong comment box and had meant to put this here. on reflection this isn't such a big deal, given we're asserting the number of entries in place.


The following attributes are exported:

* `id` - The DNS PTR Record ID.
Copy link
Member

Choose a reason for hiding this comment

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

we should expose etag here too

@tombuildsstuff tombuildsstuff merged commit 4639a9e into hashicorp:master Jul 3, 2017
tombuildsstuff added a commit that referenced this pull request Jul 3, 2017
tombuildsstuff added a commit that referenced this pull request Jul 4, 2017
tombuildsstuff added a commit that referenced this pull request Jul 4, 2017
@ghost
Copy link

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

Successfully merging this pull request may close these issues.

None yet

3 participants