From 6953aef9a68f6631ee1b4824e331e1acf48bffc4 Mon Sep 17 00:00:00 2001 From: Kobi Samoray Date: Tue, 21 Mar 2023 08:58:46 +0100 Subject: [PATCH] Add ha_mode attribute to T1 gateway Fixes: #852 Signed-off-by: Kobi Samoray --- nsxt/resource_nsxt_policy_tier1_gateway.go | 18 ++++++++++++++++++ .../resource_nsxt_policy_tier1_gateway_test.go | 7 +++++++ .../docs/r/policy_tier1_gateway.html.markdown | 1 + 3 files changed, 26 insertions(+) diff --git a/nsxt/resource_nsxt_policy_tier1_gateway.go b/nsxt/resource_nsxt_policy_tier1_gateway.go index 8f79ebfef..2f84e47ef 100644 --- a/nsxt/resource_nsxt_policy_tier1_gateway.go +++ b/nsxt/resource_nsxt_policy_tier1_gateway.go @@ -43,6 +43,10 @@ var poolAllocationValues = []string{ model.Tier1_POOL_ALLOCATION_LB_XLARGE, } +var t1HaModeValues = []string{ + model.Tier1_HA_MODE_ACTIVE, + model.Tier1_HA_MODE_STANDBY} + func resourceNsxtPolicyTier1Gateway() *schema.Resource { return &schema.Resource{ Create: resourceNsxtPolicyTier1GatewayCreate, @@ -118,6 +122,13 @@ func resourceNsxtPolicyTier1Gateway() *schema.Resource { "ingress_qos_profile_path": getPolicyPathSchema(false, false, "Policy path to gateway QoS profile in ingress direction"), "egress_qos_profile_path": getPolicyPathSchema(false, false, "Policy path to gateway QoS profile in egress direction"), "intersite_config": getGatewayIntersiteConfigSchema(), + "ha_mode": { + Type: schema.TypeString, + Description: "High-availability Mode for Tier-1", + ValidateFunc: validation.StringInSlice(t1HaModeValues, false), + Optional: true, + Default: model.Tier1_HA_MODE_STANDBY, + }, }, } } @@ -378,8 +389,13 @@ func policyTier1GatewayResourceToInfraStruct(d *schema.ResourceData, connector c routeAdvertisementRules := getAdvRulesFromSchema(d) ipv6ProfilePaths := getIpv6ProfilePathsFromSchema(d) dhcpPath := d.Get("dhcp_config_path").(string) + haMode := d.Get("ha_mode").(string) revision := int64(d.Get("revision").(int)) + if haMode == model.Tier1_HA_MODE_ACTIVE && nsxVersionLower("4.0.0") { + return infraStruct, fmt.Errorf("ACTIVE_ACTIVE HA mode is not supported in NSX versions lower than 4.0.0. Use ACTIVE_BACKUP instead") + } + t1Type := "Tier1" obj := model.Tier1{ Id: &id, @@ -396,6 +412,7 @@ func policyTier1GatewayResourceToInfraStruct(d *schema.ResourceData, connector c RouteAdvertisementRules: routeAdvertisementRules, Ipv6ProfilePaths: ipv6ProfilePaths, ResourceType: &t1Type, + HaMode: &haMode, } if dhcpPath != "" { @@ -528,6 +545,7 @@ func resourceNsxtPolicyTier1GatewayRead(d *schema.ResourceData, m interface{}) e d.Set("enable_firewall", !(*obj.DisableFirewall)) d.Set("enable_standby_relocation", obj.EnableStandbyRelocation) d.Set("force_whitelisting", obj.ForceWhitelisting) + d.Set("ha_mode", obj.HaMode) if obj.Tier0Path != nil { d.Set("tier0_path", *obj.Tier0Path) } diff --git a/nsxt/resource_nsxt_policy_tier1_gateway_test.go b/nsxt/resource_nsxt_policy_tier1_gateway_test.go index 731792d2d..bdb76cdfa 100644 --- a/nsxt/resource_nsxt_policy_tier1_gateway_test.go +++ b/nsxt/resource_nsxt_policy_tier1_gateway_test.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model" ) func TestAccResourceNsxtPolicyTier1Gateway_basic(t *testing.T) { @@ -36,6 +37,7 @@ func TestAccResourceNsxtPolicyTier1Gateway_basic(t *testing.T) { resource.TestCheckResourceAttr(testResourceName, "enable_standby_relocation", "true"), resource.TestCheckResourceAttr(testResourceName, "force_whitelisting", "false"), resource.TestCheckResourceAttr(testResourceName, "tier0_path", ""), + resource.TestCheckResourceAttr(testResourceName, "ha_mode", model.Tier1_HA_MODE_STANDBY), resource.TestCheckResourceAttr(testResourceName, "route_advertisement_types.#", "2"), resource.TestCheckResourceAttr(testResourceName, "route_advertisement_rule.#", "0"), resource.TestCheckResourceAttrSet(testResourceName, "ipv6_ndra_profile_path"), @@ -57,6 +59,7 @@ func TestAccResourceNsxtPolicyTier1Gateway_basic(t *testing.T) { resource.TestCheckResourceAttr(testResourceName, "enable_standby_relocation", "false"), resource.TestCheckResourceAttr(testResourceName, "force_whitelisting", "true"), resource.TestCheckResourceAttr(testResourceName, "tier0_path", ""), + resource.TestCheckResourceAttr(testResourceName, "ha_mode", model.Tier1_HA_MODE_STANDBY), resource.TestCheckResourceAttr(testResourceName, "route_advertisement_types.#", "1"), resource.TestCheckResourceAttr(testResourceName, "route_advertisement_rule.#", "0"), resource.TestCheckResourceAttrSet(testResourceName, "ipv6_ndra_profile_path"), @@ -78,6 +81,7 @@ func TestAccResourceNsxtPolicyTier1Gateway_basic(t *testing.T) { resource.TestCheckResourceAttr(testResourceName, "enable_standby_relocation", "false"), resource.TestCheckResourceAttr(testResourceName, "force_whitelisting", "true"), resource.TestCheckResourceAttr(testResourceName, "tier0_path", ""), + resource.TestCheckResourceAttr(testResourceName, "ha_mode", model.Tier1_HA_MODE_STANDBY), resource.TestCheckResourceAttr(testResourceName, "route_advertisement_types.#", "1"), resource.TestCheckResourceAttr(testResourceName, "route_advertisement_rule.#", "0"), resource.TestCheckResourceAttrSet(testResourceName, "ipv6_ndra_profile_path"), @@ -115,6 +119,7 @@ func TestAccResourceNsxtPolicyTier1Gateway_withPoolAllocation(t *testing.T) { resource.TestCheckResourceAttr(testResourceName, "enable_standby_relocation", "true"), resource.TestCheckResourceAttr(testResourceName, "force_whitelisting", "false"), resource.TestCheckResourceAttr(testResourceName, "tier0_path", ""), + resource.TestCheckResourceAttr(testResourceName, "ha_mode", model.Tier1_HA_MODE_STANDBY), resource.TestCheckResourceAttr(testResourceName, "pool_allocation", "ROUTING"), resource.TestCheckResourceAttr(testResourceName, "route_advertisement_types.#", "2"), resource.TestCheckResourceAttr(testResourceName, "route_advertisement_rule.#", "0"), @@ -137,6 +142,7 @@ func TestAccResourceNsxtPolicyTier1Gateway_withPoolAllocation(t *testing.T) { resource.TestCheckResourceAttr(testResourceName, "enable_standby_relocation", "false"), resource.TestCheckResourceAttr(testResourceName, "force_whitelisting", "true"), resource.TestCheckResourceAttr(testResourceName, "tier0_path", ""), + resource.TestCheckResourceAttr(testResourceName, "ha_mode", model.Tier1_HA_MODE_STANDBY), resource.TestCheckResourceAttr(testResourceName, "pool_allocation", "ROUTING"), resource.TestCheckResourceAttr(testResourceName, "route_advertisement_types.#", "1"), resource.TestCheckResourceAttr(testResourceName, "route_advertisement_rule.#", "0"), @@ -160,6 +166,7 @@ func TestAccResourceNsxtPolicyTier1Gateway_withPoolAllocation(t *testing.T) { resource.TestCheckResourceAttr(testResourceName, "enable_standby_relocation", "false"), resource.TestCheckResourceAttr(testResourceName, "force_whitelisting", "true"), resource.TestCheckResourceAttr(testResourceName, "tier0_path", ""), + resource.TestCheckResourceAttr(testResourceName, "ha_mode", model.Tier1_HA_MODE_STANDBY), resource.TestCheckResourceAttr(testResourceName, "route_advertisement_types.#", "1"), resource.TestCheckResourceAttr(testResourceName, "route_advertisement_rule.#", "0"), resource.TestCheckResourceAttrSet(testResourceName, "ipv6_ndra_profile_path"), diff --git a/website/docs/r/policy_tier1_gateway.html.markdown b/website/docs/r/policy_tier1_gateway.html.markdown index e1cee9f8e..085f12d37 100644 --- a/website/docs/r/policy_tier1_gateway.html.markdown +++ b/website/docs/r/policy_tier1_gateway.html.markdown @@ -111,6 +111,7 @@ The following arguments are supported: * `intersite_config` - (Optional) This clause is relevant for Global Manager only. * `transit_subnet` - (Optional) IPv4 subnet for inter-site transit segment connecting service routers across sites for stretched gateway. For IPv6 link local subnet is auto configured. * `primary_site_path` - (Optional) Primary egress site for gateway. +* `ha_mode` - (Optional) High-availability Mode for Tier-1. Valid values are `ACTIVE_ACTIVE` and `ACTIVE_STANDBY`. `ACTIVE_ACTIVE` is supported with NSX version 4.0.0 and above. ## Attributes Reference