From 29c873ef0af954f7cead21d5faae8f4cc3acf7c2 Mon Sep 17 00:00:00 2001 From: Anna Khmelnitsky Date: Fri, 24 Jan 2025 17:41:49 -0800 Subject: [PATCH] Avoid recreating gateway when locale service added This change removes ForceNew from nsx_id attribute in locale service schema, in order to avoid recreating the gateway when locale service is added. Without this fix, adding locale_service within the gateway would trigger recreation even when nsx_id is not specified, since nsx_is is defined as Computed. Signed-off-by: Anna Khmelnitsky --- nsxt/gateway_common.go | 4 +- ...resource_nsxt_policy_tier1_gateway_test.go | 44 ++++++++++++++++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/nsxt/gateway_common.go b/nsxt/gateway_common.go index b4ba76d69..578c584d0 100644 --- a/nsxt/gateway_common.go +++ b/nsxt/gateway_common.go @@ -95,7 +95,7 @@ func getPolicyLocaleServiceSchema(isTier1 bool) *schema.Schema { } elemSchema := map[string]*schema.Schema{ - "nsx_id": getNsxIDSchema(), + "nsx_id": getFlexNsxIDSchema(false), "edge_cluster_path": { Type: schema.TypeString, Description: "The path of the edge cluster connected to this gateway", @@ -205,7 +205,7 @@ func getGatewayIntersiteConfigSchema() *schema.Schema { Type: schema.TypeList, Optional: true, Computed: true, - Description: "Locale Service for the gateway", + Description: "Intersite config for the gateway", MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ diff --git a/nsxt/resource_nsxt_policy_tier1_gateway_test.go b/nsxt/resource_nsxt_policy_tier1_gateway_test.go index eb18d15d9..356966501 100644 --- a/nsxt/resource_nsxt_policy_tier1_gateway_test.go +++ b/nsxt/resource_nsxt_policy_tier1_gateway_test.go @@ -238,7 +238,13 @@ func TestAccResourceNsxtPolicyTier1Gateway_withEdgeCluster(t *testing.T) { edgeClusterName := getEdgeClusterName() resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccOnlyLocalManager(t); testAccPreCheck(t) }, + PreCheck: func() { + testAccOnlyLocalManager(t) + testAccPreCheck(t) + // NSX pre-4.0.0 sends wrong revision, therefore we can't validate + // the gateway is not recreated + testAccNSXVersion(t, "4.0.0") + }, Providers: testAccProviders, CheckDestroy: func(state *terraform.State) error { return testAccNsxtPolicyTier1CheckDestroy(state, updateName) @@ -252,6 +258,7 @@ func TestAccResourceNsxtPolicyTier1Gateway_withEdgeCluster(t *testing.T) { resource.TestCheckResourceAttr(testResourceName, "description", "Acceptance Test"), resource.TestCheckResourceAttrSet(testResourceName, "edge_cluster_path"), resource.TestCheckResourceAttr(testResourceName, "tier0_path", ""), + resource.TestCheckResourceAttr(testResourceName, "revision", "0"), resource.TestCheckResourceAttr(realizationResourceName, "state", "REALIZED"), ), }, @@ -263,6 +270,22 @@ func TestAccResourceNsxtPolicyTier1Gateway_withEdgeCluster(t *testing.T) { resource.TestCheckResourceAttr(testResourceName, "description", "Acceptance Test"), resource.TestCheckResourceAttrSet(testResourceName, "edge_cluster_path"), resource.TestCheckResourceAttr(testResourceName, "tier0_path", ""), + // verify gateway was not recreated + resource.TestCheckResourceAttr(testResourceName, "revision", "1"), + resource.TestCheckResourceAttr(realizationResourceName, "state", "REALIZED"), + ), + }, + { + Config: testAccNsxtPolicyTier1CreateWithLocaleServiceTemplate(updateName, edgeClusterName), + Check: resource.ComposeTestCheckFunc( + testAccNsxtPolicyTier1Exists(testResourceName), + resource.TestCheckResourceAttr(testResourceName, "display_name", updateName), + resource.TestCheckResourceAttr(testResourceName, "description", "Acceptance Test"), + resource.TestCheckResourceAttr(testResourceName, "locale_service.#", "1"), + resource.TestCheckResourceAttrSet(testResourceName, "locale_service.0.edge_cluster_path"), + resource.TestCheckResourceAttr(testResourceName, "tier0_path", ""), + // verify gateway was not recreated + resource.TestCheckResourceAttr(testResourceName, "revision", "2"), resource.TestCheckResourceAttr(realizationResourceName, "state", "REALIZED"), ), }, @@ -710,6 +733,25 @@ data "nsxt_policy_realization_info" "realization_info" { }`, edgeClusterName, name) } +func testAccNsxtPolicyTier1CreateWithLocaleServiceTemplate(name string, edgeClusterName string) string { + return fmt.Sprintf(` +data "nsxt_policy_edge_cluster" "EC" { + display_name = "%s" +} + +resource "nsxt_policy_tier1_gateway" "test" { + display_name = "%s" + description = "Acceptance Test" + locale_service { + edge_cluster_path = data.nsxt_policy_edge_cluster.EC.path + } +} + +data "nsxt_policy_realization_info" "realization_info" { + path = nsxt_policy_tier1_gateway.test.path +}`, edgeClusterName, name) +} + func testAccNsxtPolicyTier1CreateWithTier0Template(name string, tier0Name string, failoverMode string) string { return fmt.Sprintf(` data "nsxt_policy_tier0_gateway" "T0" {