From e9a288e8bfce175cdae8bab71cbfbee3d9cad0a3 Mon Sep 17 00:00:00 2001 From: stobias123 Date: Tue, 10 Nov 2020 11:35:02 -0800 Subject: [PATCH] adding hostname when reserve ip --- go.mod | 2 +- go.sum | 5 +++-- resource_ip_address.go | 10 +++++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index ca29f47..8e9707b 100644 --- a/go.mod +++ b/go.mod @@ -7,5 +7,5 @@ require ( github.com/hashicorp/terraform v0.12.29 github.com/hashicorp/terraform-plugin-sdk v1.15.0 github.com/sirupsen/logrus v1.6.0 - github.com/stobias123/gosolar v0.4.0 + github.com/stobias123/gosolar v0.4.2 ) diff --git a/go.sum b/go.sum index 55e3513..6de8ad2 100644 --- a/go.sum +++ b/go.sum @@ -402,8 +402,8 @@ github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb6 github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= -github.com/stobias123/gosolar v0.4.0 h1:pLarMj/edVZDav1TETI37XXFvCad8Hr8FV84JFJI0jM= -github.com/stobias123/gosolar v0.4.0/go.mod h1:DjgQtGiBnBwAb5oKhAAn6oXC5XB1Q9dwPjpf3k6wb/I= +github.com/stobias123/gosolar v0.4.2 h1:HBGtJoFUcSQvL7EWVUtjIWWry33yrtihazd9G8tjIfU= +github.com/stobias123/gosolar v0.4.2/go.mod h1:0+9qw5WGetp5oAs7lpSDR+PcjdR++fiq6tkRgfxT5VU= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= @@ -514,6 +514,7 @@ golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190804053845-51ab0e2deafa h1:KIDDMLT1O0Nr7TSxp8xM5tJcdn8tgyAONntO829og1M= golang.org/x/sys v0.0.0-20190804053845-51ab0e2deafa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So= diff --git a/resource_ip_address.go b/resource_ip_address.go index b4deb43..7245e08 100644 --- a/resource_ip_address.go +++ b/resource_ip_address.go @@ -76,13 +76,21 @@ func resourceIPAddressCreate(d *schema.ResourceData, m interface{}) error { suggestedIP := client.GetFirstAvailableIP(subnet.Address, fmt.Sprintf("%d", subnet.CIDR)) log.Info(suggestedIP) reservedIP := client.ReserveIP(suggestedIP.Address) - client.CommentOnIPNode(suggestedIP.Address, d.Get("hostname").(string)) + + // This is really kind of sloppy, I should be returning err from gosolar. + if len(d.Get("hostname").(string)) > 0 { + ipHostname := client.AddHostnametoIPNode(suggestedIP.Address, d.Get("hostname").(string)) + + log.Info("SetHostname") + log.Info(ipHostname) + } log.Info("Reserved IP") log.Info(reservedIP) log.Info("Suggested IP") log.Info(suggestedIP) + d.Set("vlan", subnet.VLAN) //d.Set("subnet_name", subnet.DisplayName) d.Set("address", suggestedIP.Address)