-
Notifications
You must be signed in to change notification settings - Fork 144
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
Fix import of ovh_ip_reverse resources with IPv6 #346
Conversation
When importing an `ovh_ip_reverse` resources, the user is expected to provide the IP block and IP address separated with a colon, e.g. `198.51.100.0/24:198.51.100.42`: * `198.51.100.0/24` is extracted as the IP block; * `198.51.100.42` is extracted as the address. Unfortunately, the `:` separator does not work well with IPv6 addresses, e.g. `2001:0DB8::/32:2001:0DB8::42` is interpreted as: * `2001` is extracted as the IP block; * `0DB8::/32:2001:0DB8::42` is extracted as the address. This is obviously wrong and raise an API error: ``` │ Error: calling /ip/%222001/reverse/0DB8::%2F32:2001:0DB8::42: │ HTTP Error 400: "[ipReverse] Given data (0DB8::/32:2001:0DB8::42) is not valid for type ip" ``` Replace the `:` separator with a `|` separator to avoid this issue.
Thanks for your fix. Can you copy-paste me the Thanks :) |
Hey @scraly ! I have some terraform definition like this that ensure each dedicated server reverse DNS for both IPv4 and IPv6 is set to data "ovh_dedicated_servers" "all_dedicated_servers" {}
data "ovh_dedicated_server" "dedicated_server" {
for_each = toset(data.ovh_dedicated_servers.all_dedicated_servers.result)
service_name = each.key
}
resource "ovh_ip_reverse" "dedicated_server" {
for_each = toset(data.ovh_dedicated_servers.all_dedicated_servers.result)
ip = "${data.ovh_dedicated_server.dedicated_server[each.key].ip}/32"
ip_reverse = data.ovh_dedicated_server.dedicated_server[each.key].ip
reverse = "${split(".", data.ovh_dedicated_server.dedicated_server[each.key].name)[0]}.example.com."
}
resource "ovh_ip_reverse" "dedicated_server6" {
for_each = toset(data.ovh_dedicated_servers.all_dedicated_servers.result)
ip = element([for ip in data.ovh_dedicated_server.dedicated_server[each.key].ips : ip if length(regexall("^[:[:xdigit:]]+/\\d+$", ip)) > 0], 0)
ip_reverse = regex("^([:[:xdigit:]]+)/\\d+$", element([for ip in data.ovh_dedicated_server.dedicated_server[each.key].ips : ip if length(regexall("^[:[:xdigit:]]+/\\d+$", ip)) > 0], 0))[0]
reverse = "${split(".", data.ovh_dedicated_server.dedicated_server[each.key].name)[0]}.example.com."
} For each server I ran an import command for IPv4 and another one for IPv6, for example:
Then |
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.
Thanks,
moreover can you add the import section in the documentation page (with the format you recommend)? Like this:
https://registry.terraform.io/providers/ovh/ovh/latest/docs/resources/cloud_project_kube#import
Thank you :)
Use the 2001:0DB8::/32 IPv6 prefix reserved for documentation purpose.
Example for importing an IPv6 address added. Do you also want an example with IPv4 or is it fine this way since the syntax is basically the same? |
I think only one example should be OK :) |
Any news about the example to add? :-) |
The status was and is still in "changes request" so I guess you didn't see my last message :-) |
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.
top, thank you :)
When importing an
ovh_ip_reverse
resources, the user is expected toprovide the IP block and IP address separated with a colon, e.g.
198.51.100.0/24:198.51.100.42
:198.51.100.0/24
is extracted as the IP block;198.51.100.42
is extracted as the address.Unfortunately, the
:
separator does not work well with IPv6 addresses,e.g.
2001:0DB8::/32:2001:0DB8::42
is interpreted as:2001
is extracted as the IP block;0DB8::/32:2001:0DB8::42
is extracted as the address.This is obviously wrong and raise an API error:
Replace the
:
separator with a|
separator to avoid this issue.