Skip to content

Commit

Permalink
Add support for appliance.gateway.suspend
Browse files Browse the repository at this point in the history
  • Loading branch information
mandopaloooza committed Jan 12, 2024
1 parent ab138c2 commit 60d4e15
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
22 changes: 19 additions & 3 deletions appgate/resource_appgate_appliance.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,11 @@ func resourceAppgateAppliance() *schema.Resource {
Optional: true,
Default: false,
},
"suspended": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"vpn": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -1451,7 +1456,7 @@ the root of Appliance when this interface is removed.`,
}

if v, ok := d.GetOk("gateway"); ok {
gw, err := readGatewayFromConfig(v.([]interface{}))
gw, err := readGatewayFromConfig(v.([]interface{}), currentVersion)
if err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -2120,6 +2125,12 @@ func flatttenApplianceGateway(in openapi.ApplianceAllOfGateway, currentVersion *
gateway["enabled"] = v
}

if currentVersion.GreaterThanOrEqual(Appliance61Version) {
if v, ok := in.GetSuspendedOk(); ok {
gateway["suspended"] = v
}
}

if v, ok := in.GetVpnOk(); ok {
vpn := make(map[string]interface{})
if v, ok := v.GetWeightOk(); ok {
Expand Down Expand Up @@ -2796,7 +2807,7 @@ func resourceAppgateApplianceUpdate(ctx context.Context, d *schema.ResourceData,

if d.HasChange("gateway") {
_, v := d.GetChange("gateway")
gw, err := readGatewayFromConfig(v.([]interface{}))
gw, err := readGatewayFromConfig(v.([]interface{}), currentVersion)
if err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -3173,13 +3184,18 @@ func readControllerFromConfig(controllers []interface{}) (openapi.ApplianceAllOf
return val, nil
}

func readGatewayFromConfig(gateways []interface{}) (openapi.ApplianceAllOfGateway, error) {
func readGatewayFromConfig(gateways []interface{}, currentVersion *version.Version) (openapi.ApplianceAllOfGateway, error) {
val := openapi.ApplianceAllOfGateway{}
for _, ctrl := range gateways {
r := ctrl.(map[string]interface{})
if v, ok := r["enabled"]; ok {
val.SetEnabled(v.(bool))
}
if currentVersion.GreaterThanOrEqual(Appliance61Version) {
if v, ok := r["suspended"]; ok {
val.SetSuspended(v.(bool))
}
}
if v := r["vpn"].([]interface{}); len(v) > 0 {
vpn := openapi.ApplianceAllOfGatewayVpn{}
for _, s := range v {
Expand Down
8 changes: 6 additions & 2 deletions appgate/resource_appgate_appliance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4473,8 +4473,9 @@ func TestAccApplianceBasicGateway6(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "controller.0.enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "customization", ""),
resource.TestCheckResourceAttr(resourceName, "gateway.#", "1"),
resource.TestCheckResourceAttr(resourceName, "gateway.0.%", "2"),
resource.TestCheckResourceAttr(resourceName, "gateway.0.%", "3"),
resource.TestCheckResourceAttr(resourceName, "gateway.0.enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "gateway.0.suspended", "false"),
resource.TestCheckResourceAttr(resourceName, "gateway.0.vpn.#", "1"),
resource.TestCheckResourceAttr(resourceName, "gateway.0.vpn.0.%", "3"),
resource.TestCheckResourceAttr(resourceName, "gateway.0.vpn.0.allow_destinations.#", "1"),
Expand Down Expand Up @@ -4640,7 +4641,7 @@ func TestAccApplianceBasicGateway6(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "controller.0.enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "customization", ""),
resource.TestCheckResourceAttr(resourceName, "gateway.#", "1"),
resource.TestCheckResourceAttr(resourceName, "gateway.0.%", "2"),
resource.TestCheckResourceAttr(resourceName, "gateway.0.%", "3"),
resource.TestCheckResourceAttr(resourceName, "gateway.0.enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "gateway.0.vpn.#", "1"),
resource.TestCheckResourceAttr(resourceName, "gateway.0.vpn.0.%", "3"),
Expand Down Expand Up @@ -5206,6 +5207,8 @@ func TestAccAppliance61(t *testing.T) {

resource.TestCheckResourceAttr(resourceName, "gateway.#", "1"),
resource.TestCheckResourceAttr(resourceName, "gateway.0.vpn.#", "1"),
resource.TestCheckResourceAttr(resourceName, "gateway.0.enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "gateway.0.suspended", "false"),
resource.TestCheckResourceAttr(resourceName, "gateway.0.vpn.0.allow_destinations.#", "1"),
resource.TestCheckResourceAttr(resourceName, "gateway.0.vpn.0.allow_destinations.0.address", "0.0.0.0"),
resource.TestCheckResourceAttr(resourceName, "gateway.0.vpn.0.allow_destinations.0.netmask", "0"),
Expand Down Expand Up @@ -5277,6 +5280,7 @@ resource "appgatesdp_appliance" "appliancev61" {
}
gateway {
enabled = true
suspended = false
vpn {
weight = 100
allow_destinations {
Expand Down

0 comments on commit 60d4e15

Please sign in to comment.