Skip to content

Commit

Permalink
Merge pull request #134 from citrix/new_attributes
Browse files Browse the repository at this point in the history
New attributes for nstcpprofile, nsip, nsip6, netprofile
  • Loading branch information
sumanth-lingappa authored Feb 5, 2021
2 parents c081b10 + c5fba22 commit 225c2e2
Show file tree
Hide file tree
Showing 12 changed files with 361 additions and 25 deletions.
48 changes: 36 additions & 12 deletions citrixadc/resource_citrixadc_netprofile.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package citrixadc

import (
"github.com/chiradeep/go-nitro/config/network"

"github.com/chiradeep/go-nitro/netscaler"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
Expand All @@ -11,6 +9,20 @@ import (
"log"
)

// netprofile struct is defined here to add proxyProtocolAfterTLSHandshake support.
// Once this attribute available in the main builds, respective go-notro file will be taken care.
type netprofile struct {
Mbf string `json:"mbf,omitempty"`
Name string `json:"name,omitempty"`
Overridelsn string `json:"overridelsn,omitempty"`
Proxyprotocol string `json:"proxyprotocol,omitempty"`
Proxyprotocoltxversion string `json:"proxyprotocoltxversion,omitempty"`
Srcip string `json:"srcip,omitempty"`
Srcippersistency string `json:"srcippersistency,omitempty"`
Td int `json:"td,omitempty"`
Proxyprotocolaftertlshandshake string `json:"proxyprotocolaftertlshandshake,omitempty"`
}

func resourceCitrixAdcNetprofile() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
Expand Down Expand Up @@ -63,6 +75,11 @@ func resourceCitrixAdcNetprofile() *schema.Resource {
Optional: true,
Computed: true,
},
"proxyprotocolaftertlshandshake": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
}
}
Expand All @@ -77,15 +94,16 @@ func createNetprofileFunc(d *schema.ResourceData, meta interface{}) error {
netprofileName = resource.PrefixedUniqueId("tf-netprofile-")
d.Set("name", netprofileName)
}
netprofile := network.Netprofile{
Mbf: d.Get("mbf").(string),
Name: d.Get("name").(string),
Overridelsn: d.Get("overridelsn").(string),
Proxyprotocol: d.Get("proxyprotocol").(string),
Proxyprotocoltxversion: d.Get("proxyprotocoltxversion").(string),
Srcip: d.Get("srcip").(string),
Srcippersistency: d.Get("srcippersistency").(string),
Td: d.Get("td").(int),
netprofile := netprofile{
Mbf: d.Get("mbf").(string),
Name: d.Get("name").(string),
Overridelsn: d.Get("overridelsn").(string),
Proxyprotocol: d.Get("proxyprotocol").(string),
Proxyprotocoltxversion: d.Get("proxyprotocoltxversion").(string),
Srcip: d.Get("srcip").(string),
Srcippersistency: d.Get("srcippersistency").(string),
Td: d.Get("td").(int),
Proxyprotocolaftertlshandshake: d.Get("proxyprotocolaftertlshandshake").(string),
}

_, err := client.AddResource(netscaler.Netprofile.Type(), netprofileName, &netprofile)
Expand Down Expand Up @@ -123,6 +141,7 @@ func readNetprofileFunc(d *schema.ResourceData, meta interface{}) error {
d.Set("srcip", data["srcip"])
d.Set("srcippersistency", data["srcippersistency"])
d.Set("td", data["td"])
d.Set("proxyprotocolaftertlshandshake", data["proxyprotocolaftertlshandshake"])

return nil

Expand All @@ -133,7 +152,7 @@ func updateNetprofileFunc(d *schema.ResourceData, meta interface{}) error {
client := meta.(*NetScalerNitroClient).client
netprofileName := d.Get("name").(string)

netprofile := network.Netprofile{
netprofile := netprofile{
Name: d.Get("name").(string),
}
hasChange := false
Expand Down Expand Up @@ -177,6 +196,11 @@ func updateNetprofileFunc(d *schema.ResourceData, meta interface{}) error {
netprofile.Td = d.Get("td").(int)
hasChange = true
}
if d.HasChange("proxyprotocolaftertlshandshake") {
log.Printf("[DEBUG] citrixadc-provider: Proxyprotocolaftertlshandshake has changed for netprofile %s, starting update", netprofileName)
netprofile.Proxyprotocolaftertlshandshake = d.Get("proxyprotocolaftertlshandshake").(string)
hasChange = true
}

if hasChange {
_, err := client.UpdateResource(netscaler.Netprofile.Type(), netprofileName, &netprofile)
Expand Down
28 changes: 28 additions & 0 deletions citrixadc/resource_citrixadc_netprofile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,34 @@ func TestAccNetprofile_basic(t *testing.T) {
})
}

const testAccNetprofile_proxyprotocolaftertlshandshake = `
resource "citrixadc_netprofile" "tf_netprofile_proxyprotocolaftertlshandshake" {
name = "tf_netprofile2"
proxyprotocol = "ENABLED"
proxyprotocoltxversion = "V2"
proxyprotocolaftertlshandshake = "ENABLED"
}
`

func TestAccNetprofile_proxyprotocolaftertlshandshake(t *testing.T) {
if isCpxRun {
t.Skip("CPX 12.0 is outdated for this resource")
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNetprofileDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccNetprofile_proxyprotocolaftertlshandshake,
Check: resource.ComposeTestCheckFunc(
testAccCheckNetprofileExist("citrixadc_netprofile.tf_netprofile_proxyprotocolaftertlshandshake", nil),
resource.TestCheckResourceAttr("citrixadc_netprofile.tf_netprofile_proxyprotocolaftertlshandshake", "proxyprotocolaftertlshandshake", "ENABLED"),
),
},
},
})
}
func testAccCheckNetprofileExist(n string, id *string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down
74 changes: 69 additions & 5 deletions citrixadc/resource_citrixadc_nsip.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package citrixadc

import (
"github.com/chiradeep/go-nitro/config/ns"

"github.com/chiradeep/go-nitro/netscaler"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
Expand All @@ -11,6 +9,60 @@ import (
"log"
)

// nsip struct is defined here to add MPTCPadvertise support.
// Once this attribute available in the main builds, respective go-notro file will be taken care.
type nsip struct {
Advertiseondefaultpartition string `json:"advertiseondefaultpartition,omitempty"`
Arp string `json:"arp,omitempty"`
Arpowner int `json:"arpowner,omitempty"`
Arpresponse string `json:"arpresponse,omitempty"`
Bgp string `json:"bgp,omitempty"`
Decrementttl string `json:"decrementttl,omitempty"`
Dynamicrouting string `json:"dynamicrouting,omitempty"`
Flags int `json:"flags,omitempty"`
Freeports int `json:"freeports,omitempty"`
Ftp string `json:"ftp,omitempty"`
Gui string `json:"gui,omitempty"`
Hostroute string `json:"hostroute,omitempty"`
Hostrtgw string `json:"hostrtgw,omitempty"`
Hostrtgwact string `json:"hostrtgwact,omitempty"`
Icmp string `json:"icmp,omitempty"`
Icmpresponse string `json:"icmpresponse,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
Iptype interface{} `json:"iptype,omitempty"`
Metric int `json:"metric,omitempty"`
Mgmtaccess string `json:"mgmtaccess,omitempty"`
Netmask string `json:"netmask,omitempty"`
Networkroute string `json:"networkroute,omitempty"`
Operationalarpowner int `json:"operationalarpowner,omitempty"`
Ospf string `json:"ospf,omitempty"`
Ospfarea int `json:"ospfarea,omitempty"`
Ospfareaval int `json:"ospfareaval,omitempty"`
Ospflsatype string `json:"ospflsatype,omitempty"`
Ownerdownresponse string `json:"ownerdownresponse,omitempty"`
Ownernode int `json:"ownernode,omitempty"`
Restrictaccess string `json:"restrictaccess,omitempty"`
Rip string `json:"rip,omitempty"`
Riserhimsgcode int `json:"riserhimsgcode,omitempty"`
Snmp string `json:"snmp,omitempty"`
Ssh string `json:"ssh,omitempty"`
State string `json:"state,omitempty"`
Tag int `json:"tag,omitempty"`
Td int `json:"td,omitempty"`
Telnet string `json:"telnet,omitempty"`
Type string `json:"type,omitempty"`
Viprtadv2bsd bool `json:"viprtadv2bsd,omitempty"`
Vipvsercount int `json:"vipvsercount,omitempty"`
Vipvserdowncount int `json:"vipvserdowncount,omitempty"`
Vipvsrvrrhiactivecount int `json:"vipvsrvrrhiactivecount,omitempty"`
Vipvsrvrrhiactiveupcount int `json:"vipvsrvrrhiactiveupcount,omitempty"`
Vrid int `json:"vrid,omitempty"`
Vserver string `json:"vserver,omitempty"`
Vserverrhilevel string `json:"vserverrhilevel,omitempty"`
Vserverrhimode string `json:"vserverrhimode,omitempty"`
Mptcpadvertise string `json:"mptcpadvertise,omitempty"`
}

func resourceCitrixAdcNsip() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
Expand Down Expand Up @@ -201,6 +253,11 @@ func resourceCitrixAdcNsip() *schema.Resource {
Optional: true,
Computed: true,
},
"mptcpadvertise": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
}
}
Expand All @@ -215,7 +272,7 @@ func createNsipFunc(d *schema.ResourceData, meta interface{}) error {
ipaddress = resource.PrefixedUniqueId("tf-nsip-")
d.Set("ipaddress", ipaddress)
}
nsip := ns.Nsip{
nsip := nsip{
Advertiseondefaultpartition: d.Get("advertiseondefaultpartition").(string),
Arp: d.Get("arp").(string),
Arpresponse: d.Get("arpresponse").(string),
Expand Down Expand Up @@ -251,6 +308,7 @@ func createNsipFunc(d *schema.ResourceData, meta interface{}) error {
Vserver: d.Get("vserver").(string),
Vserverrhilevel: d.Get("vserverrhilevel").(string),
Vserverrhimode: d.Get("vserverrhimode").(string),
Mptcpadvertise: d.Get("mptcpadvertise").(string),
}

_, err := client.AddResource(netscaler.Nsip.Type(), ipaddress, &nsip)
Expand Down Expand Up @@ -315,6 +373,7 @@ func readNsipFunc(d *schema.ResourceData, meta interface{}) error {
d.Set("vserver", data["vserver"])
d.Set("vserverrhilevel", data["vserverrhilevel"])
d.Set("vserverrhimode", data["vserverrhimode"])
d.Set("mptcpadvertise", data["mptcpadvertise"])

return nil

Expand All @@ -325,7 +384,7 @@ func updateNsipFunc(d *schema.ResourceData, meta interface{}) error {
client := meta.(*NetScalerNitroClient).client
ipaddress := d.Get("ipaddress").(string)

nsip := ns.Nsip{
nsip := nsip{
Ipaddress: d.Get("ipaddress").(string),
}
stateChange := false
Expand Down Expand Up @@ -505,6 +564,11 @@ func updateNsipFunc(d *schema.ResourceData, meta interface{}) error {
nsip.Vserverrhimode = d.Get("vserverrhimode").(string)
hasChange = true
}
if d.HasChange("mptcpadvertise") {
log.Printf("[DEBUG] citrixadc-provider: Mptcpadvertise has changed for nsip %s, starting update", ipaddress)
nsip.Mptcpadvertise = d.Get("mptcpadvertise").(string)
hasChange = true
}

if hasChange {
_, err := client.UpdateResource(netscaler.Nsip.Type(), ipaddress, &nsip)
Expand Down Expand Up @@ -541,7 +605,7 @@ func doNsipStateChange(d *schema.ResourceData, client *netscaler.NitroClient) er

// We need a new instance of the struct since
// ActOnResource will fail if we put in superfluous attributes
nsip := ns.Nsip{
nsip := nsip{
Ipaddress: d.Get("ipaddress").(string),
Td: d.Get("td").(int),
}
Expand Down
61 changes: 57 additions & 4 deletions citrixadc/resource_citrixadc_nsip6.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package citrixadc

import (
"github.com/chiradeep/go-nitro/config/ns"

"github.com/chiradeep/go-nitro/netscaler"
"github.com/hashicorp/terraform/helper/schema"

Expand All @@ -12,6 +10,49 @@ import (
"net/url"
)

// nsip6 struct is defined here to add MPTCPadvertise support.
// Once this attribute available in the main builds, respective go-notro file will be taken care.
type nsip6 struct {
Advertiseondefaultpartition string `json:"advertiseondefaultpartition,omitempty"`
Curstate string `json:"curstate,omitempty"`
Decrementhoplimit string `json:"decrementhoplimit,omitempty"`
Dynamicrouting string `json:"dynamicrouting,omitempty"`
Ftp string `json:"ftp,omitempty"`
Gui string `json:"gui,omitempty"`
Hostroute string `json:"hostroute,omitempty"`
Icmp string `json:"icmp,omitempty"`
Ip6hostrtgw string `json:"ip6hostrtgw,omitempty"`
Iptype interface{} `json:"iptype,omitempty"`
Ipv6address string `json:"ipv6address,omitempty"`
Map string `json:"map,omitempty"`
Metric int `json:"metric,omitempty"`
Mgmtaccess string `json:"mgmtaccess,omitempty"`
Nd string `json:"nd,omitempty"`
Networkroute string `json:"networkroute,omitempty"`
Ospf6lsatype string `json:"ospf6lsatype,omitempty"`
Ospfarea int `json:"ospfarea,omitempty"`
Ownerdownresponse string `json:"ownerdownresponse,omitempty"`
Ownernode int `json:"ownernode,omitempty"`
Restrictaccess string `json:"restrictaccess,omitempty"`
Scope string `json:"scope,omitempty"`
Snmp string `json:"snmp,omitempty"`
Ssh string `json:"ssh,omitempty"`
State string `json:"state,omitempty"`
Systemtype string `json:"systemtype,omitempty"`
Tag int `json:"tag,omitempty"`
Td int `json:"td,omitempty"`
Telnet string `json:"telnet,omitempty"`
Type string `json:"type,omitempty"`
Viprtadv2bsd bool `json:"viprtadv2bsd,omitempty"`
Vipvsercount int `json:"vipvsercount,omitempty"`
Vipvserdowncount int `json:"vipvserdowncount,omitempty"`
Vlan int `json:"vlan,omitempty"`
Vrid6 int `json:"vrid6,omitempty"`
Vserver string `json:"vserver,omitempty"`
Vserverrhilevel string `json:"vserverrhilevel,omitempty"`
Mptcpadvertise string `json:"mptcpadvertise,omitempty"`
}

func resourceCitrixAdcNsip6() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
Expand Down Expand Up @@ -182,6 +223,11 @@ func resourceCitrixAdcNsip6() *schema.Resource {
Optional: true,
Computed: true,
},
"mptcpadvertise": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
}
}
Expand All @@ -190,7 +236,7 @@ func createNsip6Func(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In createNsip6Func")
client := meta.(*NetScalerNitroClient).client
ipv6address := d.Get("ipv6address").(string)
nsip6 := ns.Nsip6{
nsip6 := nsip6{
Advertiseondefaultpartition: d.Get("advertiseondefaultpartition").(string),
Decrementhoplimit: d.Get("decrementhoplimit").(string),
Dynamicrouting: d.Get("dynamicrouting").(string),
Expand Down Expand Up @@ -222,6 +268,7 @@ func createNsip6Func(d *schema.ResourceData, meta interface{}) error {
Vrid6: d.Get("vrid6").(int),
Vserver: d.Get("vserver").(string),
Vserverrhilevel: d.Get("vserverrhilevel").(string),
Mptcpadvertise: d.Get("mptcpadvertise").(string),
}

_, err := client.AddResource(netscaler.Nsip6.Type(), ipv6address, &nsip6)
Expand Down Expand Up @@ -304,6 +351,7 @@ func readNsip6Func(d *schema.ResourceData, meta interface{}) error {
d.Set("vrid6", data["vrid6"])
d.Set("vserver", data["vserver"])
d.Set("vserverrhilevel", data["vserverrhilevel"])
d.Set("mptcpadvertise", data["mptcpadvertise"])

return nil

Expand All @@ -314,7 +362,7 @@ func updateNsip6Func(d *schema.ResourceData, meta interface{}) error {
client := meta.(*NetScalerNitroClient).client
ipv6address := d.Get("ipv6address").(string)

nsip6 := ns.Nsip6{
nsip6 := nsip6{
Ipv6address: d.Get("ipv6address").(string),
}
hasChange := false
Expand Down Expand Up @@ -468,6 +516,11 @@ func updateNsip6Func(d *schema.ResourceData, meta interface{}) error {
nsip6.Vserverrhilevel = d.Get("vserverrhilevel").(string)
hasChange = true
}
if d.HasChange("mptcpadvertise") {
log.Printf("[DEBUG] citrixadc-provider: Mptcpadvertise has changed for nsip6 %s, starting update", ipv6address)
nsip6.Mptcpadvertise = d.Get("mptcpadvertise").(string)
hasChange = true
}

if hasChange {
_, err := client.UpdateResource(netscaler.Nsip6.Type(), "", &nsip6)
Expand Down
Loading

0 comments on commit 225c2e2

Please sign in to comment.