Skip to content

Commit

Permalink
Merge pull request #856 from ksamoray/t1_ha_mode
Browse files Browse the repository at this point in the history
Add ha_mode attribute to T1 gateway
  • Loading branch information
ksamoray authored Apr 18, 2023
2 parents c2b2b3d + 3359b50 commit 2f7c29d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
23 changes: 23 additions & 0 deletions nsxt/resource_nsxt_policy_tier1_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
},
},
}
}
Expand Down Expand Up @@ -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,
Expand All @@ -398,6 +414,10 @@ func policyTier1GatewayResourceToInfraStruct(d *schema.ResourceData, connector c
ResourceType: &t1Type,
}

if nsxVersionHigherOrEqual("3.2.0") {
obj.HaMode = &haMode
}

if dhcpPath != "" {
dhcpPaths := []string{dhcpPath}
obj.DhcpConfigPaths = dhcpPaths
Expand Down Expand Up @@ -528,6 +548,9 @@ 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)
if nsxVersionHigherOrEqual("3.2.0") {
d.Set("ha_mode", obj.HaMode)
}
if obj.Tier0Path != nil {
d.Set("tier0_path", *obj.Tier0Path)
}
Expand Down
7 changes: 7 additions & 0 deletions nsxt/resource_nsxt_policy_tier1_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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"),
Expand All @@ -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"),
Expand All @@ -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"),
Expand Down Expand Up @@ -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"),
Expand All @@ -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"),
Expand All @@ -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"),
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/policy_tier1_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2f7c29d

Please sign in to comment.