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

Resource arm dns cname record #182

Merged
merged 5 commits into from
Jul 26, 2017
Merged

Resource arm dns cname record #182

merged 5 commits into from
Jul 26, 2017

Conversation

sebastus
Copy link
Contributor

No description provided.

@tombuildsstuff
Copy link
Contributor

Tests pass:

$ acctests azurerm TestAccAzureRMDnsCNameRecord_
=== RUN   TestAccAzureRMDnsCNameRecord_importBasic
--- PASS: TestAccAzureRMDnsCNameRecord_importBasic (101.52s)
=== RUN   TestAccAzureRMDnsCNameRecord_basic
--- PASS: TestAccAzureRMDnsCNameRecord_basic (106.86s)
=== RUN   TestAccAzureRMDnsCNameRecord_subdomain
--- PASS: TestAccAzureRMDnsCNameRecord_subdomain (88.39s)
=== RUN   TestAccAzureRMDnsCNameRecord_updateRecords
--- PASS: TestAccAzureRMDnsCNameRecord_updateRecords (104.18s)
=== RUN   TestAccAzureRMDnsCNameRecord_withTags
--- PASS: TestAccAzureRMDnsCNameRecord_withTags (111.62s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	512.600s

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

Thanks for this PR - I've taken a look and left some a few minor comments in-line but this generally looks good :)

Thanks!

d.Set("resource_group_name", resGroup)
d.Set("zone_name", zoneName)
d.Set("ttl", *result.TTL)
d.Set("etag", *result.Etag)
Copy link
Contributor

Choose a reason for hiding this comment

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

we should be able to remove the * for these two sets as d.Set() should take care of that for us automatically

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

if !createResponse.IsSuccessful() {
return fmt.Errorf("Error creating DNS CName Record: %s", createResponse.Error)
props := dns.RecordSetProperties{
Metadata: metadata,
Copy link
Contributor

Choose a reason for hiding this comment

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

from what I can see, these are the same thing, but just to confirm: is metadata the same thing as tags? The API documentation doesn't make it clear - but we currently submit these as tags?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the portal and in the sdk that property is called metadata, but it's otherwise identical to tags on other resources. and yes, in the tf file they are tags. I'll add a test to cover it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

test was already present.

d.Set("zone_name", zoneName)
d.Set("ttl", *result.TTL)
d.Set("etag", *result.Etag)
d.Set("record", cName)
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 check to see that result.RecordSetProperties.CnameRecord isn't nil here - unfortunately swagger/server-side changes could lead to Terraform crashing if we don't check - so it'd be good to change this too:

if props := result.RecordSetProperties; props != nil {
  if record := props.CnameRecord; record != nil {
    d.Set("record", record.Cname)
  }
}

(again, we shouldn't need the * here because d.Set will handle that automatically)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it.


flattenAndSetTags(d, &resp.Tags)
flattenAndSetTags(d, result.Metadata)
Copy link
Contributor

Choose a reason for hiding this comment

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

(same question about Metadata+Tags)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same answer.

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 guess the question back to you is: do you prefer the provider match the nomenclature in the tf file or that in the sdk?

Copy link
Contributor

Choose a reason for hiding this comment

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

do you prefer the provider match the nomenclature in the tf file or that in the sdk?

so we should be aiming for consistency with the schema (i.e. what's used in the *.tf file) - rather than renaming this to match the SDK; providing the field we send to/from the API is actually tags (albeit renamed), then that's fine :) i.e. users should be able to upgrade from resources made with the Riviera SDK to resources made with the Azure SDK without any code changes :)

(from what I can see, if this is tags then I'd consider this inconsistency some design feedback for the Azure API's, as the rest of the Azure API's refer to this field as tags)

@@ -54,112 +54,112 @@ func resourceArmDnsCNameRecord() *schema.Resource {
Required: true,
},

"etag": {
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 add this to the documentation too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tom - I'm new here so still learning. eTag can be left out - I'll remove it.

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

Thanks for pushing those updates - I've taken another look and left a couple of comments but this is looking good :)

Thanks!

props := dns.RecordSetProperties{
Metadata: metadata,
TTL: &ttl,
CnameRecord: &cnameRecord,
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: can we combine this into the properties object below?

readResponse, err := readRequest.Execute()
//last parameter is set to empty to allow updates to records after creation
// (per SDK, set it to '*' to prevent updates, all other values are ignored)
resp, err := dnsClient.CreateOrUpdate(resGroup, zoneName, name, dns.CNAME, parameters, "", "")
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the penultimate argument for here? in general we'd tend to split these out into assigned variables if there's multiple

i.e.

foo := "bar"
bar := "foo"
...CreateOrUpdate(..., foo, bar)


resp, error := dnsClient.Delete(resGroup, zoneName, name, dns.CNAME, "")
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("Error deleting DNS CNAME Record %s: %s", name, error)
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 make the second argument %+v to output the full error here?

if err != nil {
return fmt.Errorf("Bad: GetCNAMERecordSet: %s", err)
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should be checking for the 404 above this, and then returning the error if it's present - rather than hiding this?

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

Thanks for this contribution - due to changes within Azure detailed in #192 in order for us to merge this change in I've push a commit which contains fixes for the outstanding comments.

Your contribution is still included (and still credited to you), with the appropriate modifications. Feel free to ask about any of the changes.

Tests pass:

$ TF_ACC=1 envchain azurerm go test ./azurerm -v -timeout 120m -run TestAccAzureRMDnsC
=== RUN   TestAccAzureRMDnsCNameRecord_importBasic
--- PASS: TestAccAzureRMDnsCNameRecord_importBasic (71.30s)
=== RUN   TestAccAzureRMDnsCNameRecord_importWithTags
--- PASS: TestAccAzureRMDnsCNameRecord_importWithTags (80.29s)
=== RUN   TestAccAzureRMDnsCNameRecord_basic
--- PASS: TestAccAzureRMDnsCNameRecord_basic (70.55s)
=== RUN   TestAccAzureRMDnsCNameRecord_subdomain
--- PASS: TestAccAzureRMDnsCNameRecord_subdomain (86.35s)
=== RUN   TestAccAzureRMDnsCNameRecord_updateRecords
--- PASS: TestAccAzureRMDnsCNameRecord_updateRecords (98.04s)
=== RUN   TestAccAzureRMDnsCNameRecord_withTags
--- PASS: TestAccAzureRMDnsCNameRecord_withTags (94.55s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	501.101s

Thanks!

@tombuildsstuff tombuildsstuff merged commit 6026a72 into hashicorp:master Jul 26, 2017
@sebastus sebastus deleted the resource_arm_dns_cname_record branch September 6, 2017 21:37
@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 👉 [email protected]. 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.

2 participants