-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #171 from citrix/new_resources
New resources
- Loading branch information
Showing
18 changed files
with
1,286 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.