Skip to content

Instantly share code, notes, and snippets.

@gosuri
Created November 12, 2014 07:34
Show Gist options
  • Save gosuri/86463897daf47ec84c5b to your computer and use it in GitHub Desktop.
Save gosuri/86463897daf47ec84c5b to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/mitchellh/goamz/aws"
"github.com/mitchellh/goamz/route53"
"log"
)
func main() {
auth, err := aws.EnvAuth()
if err != nil {
log.Fatal(err)
}
client := route53.New(auth, aws.USEast)
zoneid := createPublicZone(client, "ovrclk.com")
deleteZone(client, zoneid)
vpc := &route53.VPC{ID: "vpc-df3ab2ba", Region: "us-east-1"}
vpc2 := &route53.VPC{ID: "vpc-6b53d90e", Region: "us-east-1"}
resp := createZone(client, vpc, "example.com")
zone := getHostedZone(client, resp.HostedZone.ID)
ascZone(client, zone.HostedZone.ID, vpc2)
listZones(client)
deleteZone(client, resp.HostedZone.ID)
}
func createZone(client *route53.Route53, vpc *route53.VPC, domain string) *route53.CreateHostedZoneResponse {
req := &route53.CreateHostedZoneRequest{
Name: domain,
Comment: "Testing",
VPC: *vpc,
}
resp, err := client.CreateHostedZone(req)
if err != nil {
log.Fatal(err)
}
log.Println(resp.HostedZone.PrivateZone)
return resp
}
func ascZone(client *route53.Route53, zoneid string, vpc *route53.VPC) {
req := &route53.AssociateVPCWithHostedZoneRequest{VPC: *vpc}
resp, err := client.AssociateVPCWithHostedZone(zoneid, req)
if err != nil {
log.Fatal(err)
}
log.Println(fmt.Sprintf("%T %+v", resp, resp))
zone := getHostedZone(client, zoneid)
log.Println(fmt.Sprintf("Associated to %+v", zone.VPCs))
}
func listZones(client *route53.Route53) {
zones, err := client.ListHostedZones("", 10)
if err != nil {
log.Fatal(err)
}
for _, el := range zones.HostedZones {
log.Println(fmt.Sprintf("Domain: %v | Private: %+v", el.Name, el.PrivateZone))
}
}
func createPublicZone(client *route53.Route53, domain string) string {
pubreq := &route53.CreateHostedZoneRequest{Name: domain, Comment: "Testing"}
pubresp, err := client.CreateHostedZone(pubreq)
if err != nil {
log.Fatal(err)
}
return pubresp.HostedZone.ID
}
func getHostedZone(client *route53.Route53, zoneid string) *route53.GetHostedZoneResponse {
zone, err := client.GetHostedZone(zoneid)
if err != nil {
log.Fatal(err)
}
log.Println(fmt.Sprintf("%T %+v", zone, zone.VPCs))
return zone
}
func deleteZone(client *route53.Route53, zoneid string) {
delresp, err := client.DeleteHostedZone(zoneid)
if err != nil {
log.Fatal(err)
}
log.Println(fmt.Sprintf("%T %+v", delresp, delresp))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment