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

Support multiple IPs in A/AAAA records #66

Open
mr-karan opened this issue Jun 30, 2023 · 2 comments
Open

Support multiple IPs in A/AAAA records #66

mr-karan opened this issue Jun 30, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@mr-karan
Copy link

Current implementation doesn't support multiple IPs. The last value of the record for a given hostname is overwritten because of this code:

https://github.com/libdns/route53/blob/068570957413f156f1795373ea9414c0db6e6197/provider.go#L98C1-L104C3

Can multiple IP support be considered as well?

@aymanbagabas
Copy link
Collaborator

@mr-karan try separating the IPs with new line characters \n

@mr-karan
Copy link
Author

mr-karan commented Jul 1, 2023

@aymanbagabas Tried that, doesn't seem to work:

package main

import (
	"context"
	"fmt"
	"log"
	"math/rand"
	"net"
	"strings"

	"github.com/libdns/libdns"
	route53 "github.com/libdns/route53"
)

func main() {
	p := &route53.Provider{}

	ctx := context.Background()

	ips := []string{}

	for i := 0; i < 3; i++ {
		// Generate a random IP address
		ip := net.IPv4(
			byte(rand.Intn(256)),
			byte(rand.Intn(256)),
			byte(rand.Intn(256)),
			byte(rand.Intn(256)),
		).String()

		ips = append(ips, ip)
	}


	ipsStr := strings.Join(ips, "\n")
	fmt.Println("IPs:", ipsStr)

	_, err := p.SetRecords(ctx, "test.internal.", []libdns.Record{
		{
			Name:  "libdns-r53-debug",
			Value: ipsStr,
			Type:  "A",
		},
	})
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Println("Set record with IPs:", ipsStr)
}

Output:

IPs: 133.66.56.242
161.98.106.27
60.68.58.254
2023/07/01 11:22:03 operation error Route 53: ChangeResourceRecordSets, https response error StatusCode: 400, RequestID: 6830bfee-dc68-43e3-a720-090efeccbc37, InvalidChangeBatch: [Invalid Resource Record: 'FATAL problem: ARRDATANotSingleField (Value contains spaces) encountered with '133.66.56.242
161.98.106.27
60.68.58.254'']
exit status 1

AWS CLI equivalent:

aws route53 change-resource-record-sets --hosted-zone-id redacted --change-batch '{
  "Changes": [
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "libdns-r53-debug.test.internal.",
        "Type": "A",
        "TTL": 30,
        "ResourceRecords": [
          {
            "Value": "165.232.188.121\n206.189.137.167\n165.232.188.64"
          }
        ]
      }
    }
  ]
}'

An error occurred (InvalidChangeBatch) when calling the ChangeResourceRecordSets operation: [Invalid Resource Record: 'FATAL problem: ARRDATANotSingleField (Value contains spaces) encountered with '165.232.188.121
206.189.137.167
165.232.188.64'']

The version which works (correct way):

aws route53 change-resource-record-sets --hosted-zone-id redacted --change-batch '{
  "Changes": [
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "libdns-r53-debug.test.internal.",
        "Type": "A",
        "TTL": 30,
        "ResourceRecords": [
          {
            "Value": "165.232.188.121"
          },
          {
            "Value": "206.189.137.167"
          },
          {
            "Value": "165.232.188.64"
          }
        ]
      }
    }
  ]
}'

Hope this helps.

@aymanbagabas aymanbagabas added the enhancement New feature or request label Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants