route53

package module
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 28, 2023 License: MIT Imports: 12 Imported by: 1

README

Route53 for libdns

Why a fork

This is a fork of https://github.com/libdns/route53. Main changes are in the following areas:

This is exclusively and specifically designed for integrating with https://github.com/mr-karan/nomad-external-dns/. If you're looking for a general purpose Route53 provider, please use the original repo.

Example

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/libdns/libdns"
	route53 "github.com/mr-karan/libdns-route53"
)

func main() {
	// Create a new AWS Route53 provider. The region is explicitly set to "ap-south-1".
	p, err := route53.NewProvider(context.Background(), route53.Opt{Region: "ap-south-1"})
	if err != nil {
		log.Fatal(err)
	}

	ctx := context.Background()

	var (
		// Set the IP address to be assigned to the dummy record
		ip = "192.168.0.1"
		// Set the zone to be used. This is the domain name for which the DNS records will be set.
		zone = "test.internal."
	)

	// Use the provider to set a record on Route53. The libdns.Record struct describes a DNS record.
	// The name, value, and type are set for this record.
	_, err = p.SetRecords(ctx, zone, []libdns.Record{
		{
			Name:  "dummy", // The record's name
			Value: ip,      // The record's value, in this case an IP address
			Type:  "A",     // The record type, A for Address record
		},
	})

	if err != nil {
		log.Fatalln(err)
	}
	fmt.Println("Set record with IP:", ip)
}

For a more complete example, see the example directory.


godoc reference

This package implements the libdns interfaces for AWS Route53.

Authenticating

This package supports all the credential configuration methods described in the AWS Developer Guide, such as Environment Variables, Shared configuration files, the AWS Credentials file located in .aws/credentials, and Static Credentials. You may also pass in static credentials directly (or via caddy's configuration).

The following IAM policy is a minimal working example to give libdns permissions to manage DNS records:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "",
            "Effect": "Allow",
            "Action": [
                "route53:ListResourceRecordSets",
                "route53:GetChange",
                "route53:ChangeResourceRecordSets"
            ],
            "Resource": [
                "arn:aws:route53:::hostedzone/ZABCD1EFGHIL",
                "arn:aws:route53:::change/*"
            ]
        },
        {
            "Sid": "",
            "Effect": "Allow",
            "Action": [
                "route53:ListHostedZonesByName",
                "route53:ListHostedZones"
            ],
            "Resource": "*"
        }
    ]
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Opt

type Opt struct {
	Region             string        `json:"region,omitempty"`
	MaxRetries         int           `json:"max_retries,omitempty"`
	MaxWaitDur         time.Duration `json:"max_wait_dur,omitempty"`
	WaitForPropogation bool          `json:"wait_for_propogation,omitempty"`
}

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider implements the libdns interfaces for Route53

func NewProvider

func NewProvider(ctx context.Context, opt Opt) (*Provider, error)

func (*Provider) AppendRecords

func (p *Provider) AppendRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

AppendRecords adds records to the zone. It returns the records that were added.

func (*Provider) DeleteRecords

func (p *Provider) DeleteRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

DeleteRecords deletes the records from the zone. If a record does not have an ID, it will be looked up. It returns the records that were deleted.

func (*Provider) GetRecords

func (p *Provider) GetRecords(ctx context.Context, zone string) ([]libdns.Record, error)

GetRecords lists all the records in the zone.

func (*Provider) SetRecords

func (p *Provider) SetRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

SetRecords sets the records in the zone, either by updating existing records or creating new ones. It returns the updated records.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL