Skip to content

Commit

Permalink
Merge pull request #171 from citrix/new_resources
Browse files Browse the repository at this point in the history
New resources
  • Loading branch information
George Nikolopoulos authored Jun 30, 2021
2 parents 7cc8c1f + b61fc61 commit c9a0d06
Show file tree
Hide file tree
Showing 18 changed files with 1,286 additions and 4 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
## 1.2.0 (Unreleased)
## 1.2.0 (June 30, 2021)

FEATURES

* **New Resource** `citrixadc_iptunnel`
* **New Resource** `citrixadc_lbparameter`
* **New Resource** `citrixadc_vlan`

BUG FIXES

* resource/citrixadc\_cluster: Check `masterstate` instead of `health` for determining when a node has succesfully joined the cluster.

## 1.1.0 (June 7, 2021)

Expand Down
3 changes: 3 additions & 0 deletions citrixadc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ func providerResources() map[string]*schema.Resource {
"citrixadc_appfwprofile_crosssitescripting_binding": resourceCitrixAdcAppfwprofile_crosssitescripting_binding(),
"citrixadc_appfwprofile_sqlinjection_binding": resourceCitrixAdcAppfwprofile_sqlinjection_binding(),
"citrixadc_lbvserver_servicegroup_binding": resourceCitrixAdcLbvserver_servicegroup_binding(),
"citrixadc_lbparameter": resourceCitrixAdcLbparameter(),
"citrixadc_iptunnel": resourceCitrixAdcIptunnel(),
"citrixadc_vlan": resourceCitrixAdcVlan(),
}
}

Expand Down
6 changes: 3 additions & 3 deletions citrixadc/resource_citrixadc_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1641,17 +1641,17 @@ func pollClusterNodeWithid(d *schema.ResourceData, meta interface{}, nodeid int)
}
if val_nodeid == nodeid {
nodeidFound = true
if val["health"] == "UP" {
if val["masterstate"] == "ACTIVE" {
return_state = "node_added"
} else {
log.Printf("[DEBUG] citrixadc-provider: node %v health %v", nodeid, val["health"])
log.Printf("[DEBUG] citrixadc-provider: node masterstate is %s", val["masterstate"])
}
break
}
}
// There is something very wrong
if !nodeidFound {
return nil, "adding_node", fmt.Errorf("Node id %v not in retrived nodes list", nodeid)
return nil, "adding_node", fmt.Errorf("Node id %v not in retrieved nodes list", nodeid)
}
// Node is being added. Wait.
if return_state == "adding_node" {
Expand Down
147 changes: 147 additions & 0 deletions citrixadc/resource_citrixadc_iptunnel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package citrixadc

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

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

"log"
)

func resourceCitrixAdcIptunnel() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
Create: createIptunnelFunc,
Read: readIptunnelFunc,
Delete: deleteIptunnelFunc,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"grepayload": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"ipsecprofilename": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"local": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"ownergroup": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"protocol": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"remote": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"remotesubnetmask": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"vlan": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
},
},
}
}

func createIptunnelFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In createIptunnelFunc")
client := meta.(*NetScalerNitroClient).client
iptunnelName := d.Get("name").(string)

iptunnel := network.Iptunnel{
Grepayload: d.Get("grepayload").(string),
Ipsecprofilename: d.Get("ipsecprofilename").(string),
Local: d.Get("local").(string),
Name: d.Get("name").(string),
Ownergroup: d.Get("ownergroup").(string),
Protocol: d.Get("protocol").(string),
Remote: d.Get("remote").(string),
Remotesubnetmask: d.Get("remotesubnetmask").(string),
Vlan: d.Get("vlan").(int),
}

_, err := client.AddResource(netscaler.Iptunnel.Type(), iptunnelName, &iptunnel)
if err != nil {
return err
}

d.SetId(iptunnelName)

err = readIptunnelFunc(d, meta)
if err != nil {
log.Printf("[ERROR] netscaler-provider: ?? we just created this iptunnel but we can't read it ?? %s", iptunnelName)
return nil
}
return nil
}

func readIptunnelFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In readIptunnelFunc")
client := meta.(*NetScalerNitroClient).client
iptunnelName := d.Id()
log.Printf("[DEBUG] citrixadc-provider: Reading iptunnel state %s", iptunnelName)
data, err := client.FindResource(netscaler.Iptunnel.Type(), iptunnelName)
if err != nil {
log.Printf("[WARN] citrixadc-provider: Clearing iptunnel state %s", iptunnelName)
d.SetId("")
return nil
}
d.Set("grepayload", data["grepayload"])
d.Set("ipsecprofilename", data["ipsecprofilename"])
d.Set("local", data["local"])
d.Set("ownergroup", data["ownergroup"])
d.Set("protocol", data["protocol"])
d.Set("remote", data["remote"])
d.Set("remotesubnetmask", data["remotesubnetmask"])
d.Set("vlan", data["vlan"])

return nil

}

func deleteIptunnelFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In deleteIptunnelFunc")
client := meta.(*NetScalerNitroClient).client
iptunnelName := d.Id()
err := client.DeleteResource(netscaler.Iptunnel.Type(), iptunnelName)
if err != nil {
return err
}

d.SetId("")

return nil
}
120 changes: 120 additions & 0 deletions citrixadc/resource_citrixadc_iptunnel_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
Copyright 2016 Citrix Systems, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package citrixadc

import (
"fmt"
"github.com/chiradeep/go-nitro/netscaler"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"testing"
)

const testAccIptunnel_basic_step1 = `
resource "citrixadc_iptunnel" "tf_iptunnel" {
name = "tf_iptunnel"
remote = "66.0.0.11"
remotesubnetmask = "255.255.255.255"
local = "*"
}
`

const testAccIptunnel_basic_step2 = `
resource "citrixadc_iptunnel" "tf_iptunnel" {
name = "tf_iptunnel"
remote = "66.0.0.10"
remotesubnetmask = "255.255.255.255"
local = "*"
}
`

func TestAccIptunnel_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckIptunnelDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccIptunnel_basic_step1,
Check: resource.ComposeTestCheckFunc(
testAccCheckIptunnelExist("citrixadc_iptunnel.tf_iptunnel", nil),
),
},
resource.TestStep{
Config: testAccIptunnel_basic_step2,
Check: resource.ComposeTestCheckFunc(
testAccCheckIptunnelExist("citrixadc_iptunnel.tf_iptunnel", nil),
),
},
},
})
}

func testAccCheckIptunnelExist(n string, id *string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}

if rs.Primary.ID == "" {
return fmt.Errorf("No iptunnel name is set")
}

if id != nil {
if *id != "" && *id != rs.Primary.ID {
return fmt.Errorf("Resource ID has changed!")
}

*id = rs.Primary.ID
}

nsClient := testAccProvider.Meta().(*NetScalerNitroClient).client
data, err := nsClient.FindResource(netscaler.Iptunnel.Type(), rs.Primary.ID)

if err != nil {
return err
}

if data == nil {
return fmt.Errorf("iptunnel %s not found", n)
}

return nil
}
}

func testAccCheckIptunnelDestroy(s *terraform.State) error {
nsClient := testAccProvider.Meta().(*NetScalerNitroClient).client

for _, rs := range s.RootModule().Resources {
if rs.Type != "citrixadc_iptunnel" {
continue
}

if rs.Primary.ID == "" {
return fmt.Errorf("No name is set")
}

_, err := nsClient.FindResource(netscaler.Iptunnel.Type(), rs.Primary.ID)
if err == nil {
return fmt.Errorf("iptunnel %s still exists", rs.Primary.ID)
}

}

return nil
}
Loading

0 comments on commit c9a0d06

Please sign in to comment.