Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a empty string check on ips for endpoint gateway resource #5201

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions ibm/service/vpc/resource_ibm_is_virtual_endpoint_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 60 additions & 0 deletions ibm/service/vpc/resource_ibm_is_virtual_endpoint_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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" {
Expand Down
10 changes: 5 additions & 5 deletions website/docs/r/is_virtual_endpoint_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading