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

R ovh domains zone #3

Merged
merged 8 commits into from
Dec 5, 2017
Merged

R ovh domains zone #3

merged 8 commits into from
Dec 5, 2017

Conversation

remijouannet
Copy link
Contributor

@remijouannet remijouannet commented Jul 4, 2017

Hello @yanndegat

As you ask in the previous pr hashicorp/terraform#14775
i moved my pr in this project,

here is my little readme again so we can continue to review my pr here

howto

if you want to use the OVH API you have to generate:

An Application Key
An Application Secret Key
A Consumer Key

you can generate all three on this page
https://eu.api.ovh.com/createToken/

the following rights are needed for this plugin

GET : /domain/zone/*
PUT : /domain/zone/*
POST : /domain/zone/*
DELETE : /domain/zone/*
GET : /me

ovh.tf example

provider "ovh" {
application_key = "azrzqrgqvvdsfgsfffgc"
application_secret = "aztfqsqfsdcsdqezrfdvcx"
consumer_key = "aergfvdsrgtfbvcretfgd"
}

resource "ovh_domain_zone_record" "test" {
zone = "testdemo.ovh"
subDomain = "test"
fieldType = "A"
ttl = "3600"
target = "0.0.0.0"
}

testacc

export OVH_APPLICATION_KEY="arqzergfazfeef"
export OVH_APPLICATION_SECRET="aertedytfghftyhytghbgfv"
export OVH_CONSUMER_KEY="tyfghjhuyghvbjhuytghbjygh"
export OVH_ZONE="testdemo.ovh"

then use the makefile : make testacc TEST=./builtin/providers/ovh

@yanndegat
Copy link
Collaborator

hi @remijouannet

FYI, i'm currently working with ovh to get a free ovh zone so that we can merge this PR and run the tests on HC infrastructure.

@remijouannet
Copy link
Contributor Author

Hi @yanndegat ,
no problem i'm not in the hurry,
you also can buy really cheap domain with the ext .ovh

@yanndegat
Copy link
Collaborator

yanndegat commented Jul 25, 2017 via email

Copy link
Contributor

@grubernaut grubernaut left a comment

Choose a reason for hiding this comment

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

Testing aside, ran through a quick review.

Type: schema.TypeString,
Required: true,
},
"ttl": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason ttl needs to be a TypeString and not a TypeInt? Would save you from having to call strconv during Create.

Copy link
Contributor

Choose a reason for hiding this comment

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

@remijouannet ping ^

Copy link
Contributor

Choose a reason for hiding this comment

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

Nevermind, saw you changed it to TypeInt 😄

Target: d.Get("target").(string),
}

newRecord.Ttl, _ = strconv.Atoi(d.Get("ttl").(string))
Copy link
Contributor

Choose a reason for hiding this comment

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

If ttl has to be a string, dropping the error here.

}

d.SetId(strconv.Itoa(resultRecord.Id))
d.Set("id", strconv.Itoa(resultRecord.Id))
Copy link
Contributor

Choose a reason for hiding this comment

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

duplicate set to 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.

@grubernaut as i understand terraform generate internally an ID for every ressource,
the OVH api return a ID for each DNS entry so I force the internal terraform ID to be the ID return by the API
as this id is also part of the resource i'm setting it in the resource data schema

I don't know if i'm clear here and if this right way to do it

return fmt.Errorf("Failed to create OVH Record: %s", err)
}

d.SetId(strconv.Itoa(resultRecord.Id))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can use fmt.Sprintf("%d", resultRecord.Id)) 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.

is there really a difference between using Sprintf and strconv ?

func resourceOVHRecordRead(d *schema.ResourceData, meta interface{}) error {
provider := meta.(*Config)

recordID, err := strconv.Atoi(d.Id())
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't believe you actually need this conversion back to an int here.


record := Record{}
err = provider.OVHClient.Get(
fmt.Sprintf("/domain/zone/%s/record/%d", d.Get("zone").(string), recordID),
Copy link
Contributor

Choose a reason for hiding this comment

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

As you can just use %s for the id here as you're building a string.

d.Set("zone", record.Zone)
d.Set("fieldType", record.FieldType)
d.Set("subDomain", record.SubDomain)
d.Set("ttl", strconv.Itoa(record.Ttl))
Copy link
Contributor

Choose a reason for hiding this comment

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

Same with ttl here

func resourceOVHRecordUpdate(d *schema.ResourceData, meta interface{}) error {
provider := meta.(*Config)

recordID, err := strconv.Atoi(d.Id())
Copy link
Contributor

Choose a reason for hiding this comment

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

Can leave this as a string

return nil
}

d.Set("id", record.Id)
Copy link
Contributor

Choose a reason for hiding this comment

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

record.Id is an int, can't use it for d.Set(). Need to use fmt.Sprintf("%d", record.Id) or strconv

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've changed the type of id in the data schema


log.Printf("[INFO] Deleting OVH Record: %s.%s, %s", d.Get("zone").(string), d.Get("subDomain").(string), d.Id())

recordID, err := strconv.Atoi(d.Id())
Copy link
Contributor

Choose a reason for hiding this comment

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

Can skip type conversion here, and continue using as a string on line 174

@remijouannet
Copy link
Contributor Author

thx for the review, will look at it as soon as I have free time for it

@remijouannet
Copy link
Contributor Author

remijouannet commented Jul 29, 2017

@yanndegat @grubernaut i made a few change following your comments, ttl and id type mostly

@remijouannet
Copy link
Contributor Author

@yanndegat @grubernaut Hello, any news ?

@grubernaut
Copy link
Contributor

Hey @remijouannet, sorry for the delay. Looking now.

Copy link
Contributor

@grubernaut grubernaut left a comment

Choose a reason for hiding this comment

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

LGTM, one minor nit

ttl = "3600"
target = "0.0.0.0"
}
``
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing '`' here

@grubernaut
Copy link
Contributor

Hey @remijouannet, looks good, thanks for the contribution!
Just need a zone to add for our acceptance tests, and this can be merged.

@remijouannet
Copy link
Contributor Author

@grubernaut still in discussion with OVH for a free domain for your acceptance tests ?

@grubernaut
Copy link
Contributor

I believe @yanndegat was in conversations with them, but if they are unable to provide one to us for free for acceptance testing, or require our input to do so, we can help out there. If they're fully unable to provide one to us for free testing, @randomcamel should be able to get us a paid account for it.

@remijouannet
Copy link
Contributor Author

@grubernaut @randomcamel do you already have an account for the openstack part ? doing all the test with the same account should be more convenient, an .ovh domain is very cheap like 3e/year, it should be enought for the acceptance tests

@grubernaut
Copy link
Contributor

grubernaut commented Aug 7, 2017

@remijouannet Aye, we currently have an OVH account that we test with, just need the person with the credit card (cough cough @randomcamel) to add a domain 😄

@yanndegat
Copy link
Collaborator

hi currently on holidays
news from ovh is that they can provide something for this but i'll have to go back through another round of emails starting september. If you guys from hashicorp can purchase an ovh domain for our tests purpose it would be great. if thinks ovh domain is 1$ a year.

@grubernaut
Copy link
Contributor

Hey @yanndegat,

Thanks for the patience in getting this in! We're currently working alongside OVH to get a domain for testing purposes, but are running into some issues there. Stay tuned for more!

@remijouannet
Copy link
Contributor Author

hey @yanndegat @grubernaut just want to know the status of the discussion with OVH

@remijouannet
Copy link
Contributor Author

heyhey @yanndegat @grubernaut just passing by to remind you the existence of this PR

@grubernaut
Copy link
Contributor

Hey @remijouannet, I no longer work for HashiCorp, but @catsby does and I believe @randomcamel is still the Terraform manager, they should be able to get an OVH domain setup for testing purposes so this PR can finally be merged. Thanks!!

@yanndegat
Copy link
Collaborator

yanndegat commented Nov 1, 2017 via email

@tounefr
Copy link

tounefr commented Nov 2, 2017

This feature would be very usefull.
However, i've noticed the domain needs to be refreshed after each update:
https://api.ovh.com/console/#/domain/zone/%7BzoneName%7D/record#POST

Create a new DNS record (Don't forget to refresh the zone)

Refresh request:
https://api.ovh.com/console/#/domain/zone/%7BzoneName%7D/refresh#POST

remijouannet/terraform-provider-ovh#1

@remijouannet
Copy link
Contributor Author

hello @tounefr fix in this pull request as well

@remijouannet
Copy link
Contributor Author

Hello @catsby @randomcamel,
it's been a 5 month since this PR is open,
the code has been reviewed, fix and validate,
can you please get a OVH domain for the acceptance tests (@yanndegat can help us for that)
so this PR can be merge

@yanndegat
Copy link
Collaborator

yanndegat commented Nov 7, 2017 via email

@smola
Copy link

smola commented Nov 26, 2017

I'm using this branch after rebase with latest master and it's working perfectly so far.

@tombuildsstuff
Copy link
Contributor

I've been working with @yanndegat to allow the CI system to be able to run these tests - this has now been completed and the tests can run (and pass!):

screen shot 2017-12-05 at 12 16 35

@remijouannet
Copy link
Contributor Author

@tombuildsstuff @yanndegat awesome thx for your work

@yanndegat
Copy link
Collaborator

yanndegat commented Dec 5, 2017 via email

@yanndegat yanndegat merged commit 2e1c84b into ovh:master Dec 5, 2017
@remijouannet remijouannet deleted the r-ovh-domains-zone branch December 5, 2017 17:22
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

Successfully merging this pull request may close these issues.

None yet

7 participants