From 4c17f77ecc55db2d5ac67dfb4cb3824f103d418f Mon Sep 17 00:00:00 2001 From: Ujjwal Kumar Date: Thu, 14 Mar 2024 14:36:24 +0530 Subject: [PATCH] Added a empty string check on ips for endpoint gateway resource --- ...esource_ibm_is_virtual_endpoint_gateway.go | 8 ++- ...ce_ibm_is_virtual_endpoint_gateway_test.go | 60 +++++++++++++++++++ .../is_virtual_endpoint_gateway.html.markdown | 10 ++-- 3 files changed, 71 insertions(+), 7 deletions(-) diff --git a/ibm/service/vpc/resource_ibm_is_virtual_endpoint_gateway.go b/ibm/service/vpc/resource_ibm_is_virtual_endpoint_gateway.go index a680ea0e52b..0f0efd956fd 100644 --- a/ibm/service/vpc/resource_ibm_is_virtual_endpoint_gateway.go +++ b/ibm/service/vpc/resource_ibm_is_virtual_endpoint_gateway.go @@ -622,10 +622,14 @@ func expandIPs(ipsSet []interface{}) (ipsOptions []vpcv1.EndpointGatewayReserved } ipsOpt := &vpcv1.EndpointGatewayReservedIP{ - ID: core.StringPtr(ipsID), - Name: core.StringPtr(ipsName), Subnet: ipsSubnetOpt, } + if ipsID != "" { + ipsOpt.ID = &ipsID + } + if ipsName != "" { + ipsOpt.Name = &ipsName + } ipsOptions = append(ipsOptions, ipsOpt) } return ipsOptions diff --git a/ibm/service/vpc/resource_ibm_is_virtual_endpoint_gateway_test.go b/ibm/service/vpc/resource_ibm_is_virtual_endpoint_gateway_test.go index e0687d2f593..581dee47dfc 100644 --- a/ibm/service/vpc/resource_ibm_is_virtual_endpoint_gateway_test.go +++ b/ibm/service/vpc/resource_ibm_is_virtual_endpoint_gateway_test.go @@ -160,6 +160,37 @@ func TestAccIBMISVirtualEndpointGateway_FullySpecified(t *testing.T) { }, }) } +func TestAccIBMISVirtualEndpointGateway_OptionalName(t *testing.T) { + var monitor string + vpcname1 := fmt.Sprintf("tfvpngw-vpc-%d", acctest.RandIntRange(10, 100)) + subnetname1 := fmt.Sprintf("tfvpngw-subnet-%d", acctest.RandIntRange(10, 100)) + name1 := fmt.Sprintf("tfvpngw-createname-%d", acctest.RandIntRange(10, 100)) + name := "ibm_is_virtual_endpoint_gateway.endpoint_gateway" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + CheckDestroy: testAccCheckisVirtualEndpointGatewayDestroy, + Steps: []resource.TestStep{ + { + ExpectNonEmptyPlan: true, + Config: testAccCheckisVirtualEndpointGatewayConfigOptionalName(vpcname1, subnetname1, name1), + Check: resource.ComposeTestCheckFunc( + testAccCheckisVirtualEndpointGatewayExists(name, &monitor), + resource.TestCheckResourceAttr(name, "name", name1), + resource.TestCheckResourceAttrSet(name, "ips.#"), + resource.TestCheckResourceAttrSet(name, "target.#"), + resource.TestCheckResourceAttrSet(name, "created_at"), + resource.TestCheckResourceAttrSet(name, "crn"), + resource.TestCheckResourceAttr(name, "health_state", "ok"), + resource.TestCheckResourceAttr(name, "lifecycle_state", "stable"), + resource.TestCheckResourceAttrSet(name, "resource_group"), + resource.TestCheckResourceAttrSet(name, "resource_type"), + ), + }, + }, + }) +} func TestAccIBMISVirtualEndpointGateway_CreateAfterManualDestroy(t *testing.T) { t.Skip() @@ -304,6 +335,35 @@ func testAccCheckisVirtualEndpointGatewayConfigAllowDnsResolutionBinding(vpcname }`, vpcname1, enable_hub, name1, allowDnsResolutionBinding) } +func testAccCheckisVirtualEndpointGatewayConfigOptionalName(vpcname1, subnetname1, name1 string) string { + return fmt.Sprintf(` + data "ibm_resource_group" "test_acc" { + is_default = true + } + resource "ibm_is_vpc" "testacc_vpc" { + name = "%[1]s" + resource_group = data.ibm_resource_group.test_acc.id + } + resource "ibm_is_subnet" "testacc_subnet" { + name = "%[2]s" + vpc = ibm_is_vpc.testacc_vpc.id + zone = "%[3]s" + ipv4_cidr_block = "%[4]s" + resource_group = data.ibm_resource_group.test_acc.id + } + resource "ibm_is_virtual_endpoint_gateway" "endpoint_gateway" { + name = "%[5]s" + target { + name = "ibm-dns-server2" + resource_type = "provider_infrastructure_service" + } + vpc = ibm_is_vpc.testacc_vpc.id + ips { + subnet = ibm_is_subnet.testacc_subnet.id + } + resource_group = data.ibm_resource_group.test_acc.id + }`, vpcname1, subnetname1, acc.ISZoneName, acc.ISCIDR, name1) +} func testAccCheckisVirtualEndpointGatewayConfigFullySpecified(vpcname1, subnetname1, name1 string) string { return fmt.Sprintf(` data "ibm_resource_group" "test_acc" { diff --git a/website/docs/r/is_virtual_endpoint_gateway.html.markdown b/website/docs/r/is_virtual_endpoint_gateway.html.markdown index 936a6fcd00f..275cc131c6c 100644 --- a/website/docs/r/is_virtual_endpoint_gateway.html.markdown +++ b/website/docs/r/is_virtual_endpoint_gateway.html.markdown @@ -92,14 +92,14 @@ Review the argument references that you can specify for your resource. -> **NOTE:** `allow_dns_resolution_binding` is a select location availability, invitation only feature. If used in other regions may lead to inconsistencies in state management. - `allow_dns_resolution_binding` - (Optional, bool) Indicates whether to allow this endpoint gateway to participate in DNS resolution bindings with a VPC that has dns.enable_hub set to true. - `name` - (Required, Forces new resource, String) The endpoint gateway name. -- `ips` (Optional, List) The endpoint gateway resource group. +- `ips` (Optional, List) The reserved IPs to bind to this endpoint gateway. At most one reserved IP per zone is allowed. Nested scheme for `ips`: - - `id` - (Optional, String) The endpoint gateway resource group IPs ID. - - `name` - (Optional, String) The endpoint gateway resource group IPs name. - - `subnet` - (Optional, String) The endpoint gateway resource group subnet ID. + - `id` - (Optional, String) The unique identifier for this reserved IP. Conflicts with other properties (**name**, **subnet**) + - `name` - (Optional, String) The name for this reserved IP. The name must not be used by another reserved IP in the subnet. Names starting with ibm- are reserved for provider-owned resources, and are not allowed. If unspecified, the name will be a hyphenated list of randomly-selected words. + - `subnet` - (Optional, String) The subnet in which to create this reserved IP. - ~> **NOTE:** `id` and `subnet` are mutually exclusive. + ~> **NOTE:** `id` and (`name`, `subnet`) are mutually exclusive. - `resource_group` - (Optional, Forces new resource, String) The resource group ID. - `security_groups` - (Optional, list) The security groups to use for this endpoint gateway. If unspecified, the VPC's default security group is used.