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

enhancement(endpoint_gateway): added support for service endpoints #4514

Merged
merged 1 commit into from
Apr 18, 2023
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
11 changes: 11 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_virtual_endpoint_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ func DataSourceIBMISEndpointGateway() *schema.Resource {
Computed: true,
Description: "Endpoint gateway created date and time",
},
isVirtualEndpointGatewayServiceEndpoints: {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "The fully qualified domain names for the target service. A fully qualified domain name for the target service",
},
isVirtualEndpointGatewayHealthState: {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -165,6 +173,9 @@ func dataSourceIBMISEndpointGatewayRead(
d.Set(isVirtualEndpointGatewayTarget, flattenEndpointGatewayTarget(
result.Target.(*vpcv1.EndpointGatewayTarget)))
d.Set(isVirtualEndpointGatewayVpcID, result.VPC.ID)
if len(result.ServiceEndpoints) > 0 {
d.Set(isVirtualEndpointGatewayServiceEndpoints, result.ServiceEndpoints)
}
tags, err := flex.GetGlobalTagsUsingCRN(meta, *result.CRN, "", isUserTagType)
if err != nil {
log.Printf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,35 @@ func testAccCheckIBMISVirtualEndpointGatewayDataSourceConfig(vpcname1, subnetnam
name = ibm_is_virtual_endpoint_gateway.endpoint_gateway.name
}`)
}

// service endpoints
func TestAccIBMISVirtualEndpointGatewayDataSource_service_endpoints(t *testing.T) {
resName := "data.ibm_is_virtual_endpoint_gateway.data_test"
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))
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckisVirtualEndpointGatewayDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMISVirtualEndpointGatewayDataSourceServiceEndpointsConfig(vpcname1, subnetname1, name1),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
resName, "name", name1),
resource.TestCheckResourceAttrSet(
resName, "service_endpoints.#"),
),
},
},
})
}

func testAccCheckIBMISVirtualEndpointGatewayDataSourceServiceEndpointsConfig(vpcname1, subnetname1, name1 string) string {
// status filter defaults to empty
return testAccCheckisVirtualEndpointGatewayConfigServiceEndpoints(vpcname1, subnetname1, name1) + fmt.Sprintf(`
data "ibm_is_virtual_endpoint_gateway" "data_test" {
name = ibm_is_virtual_endpoint_gateway.endpoint_gateway.name
}`)
}
11 changes: 11 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_virtual_endpoint_gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ func DataSourceIBMISEndpointGateways() *schema.Resource {
Computed: true,
Description: "Endpoint gateway health state",
},
isVirtualEndpointGatewayServiceEndpoints: {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "The fully qualified domain names for the target service. A fully qualified domain name for the target service",
},
isVirtualEndpointGatewayLifecycleState: {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -209,6 +217,9 @@ func dataSourceIBMISEndpointGatewaysRead(d *schema.ResourceData, meta interface{
endpointGatewayOutput[isVirtualEndpointGatewaySecurityGroups] =
flattenDataSourceSecurityGroups(endpointGateway.SecurityGroups)
}
if len(endpointGateway.ServiceEndpoints) > 0 {
endpointGatewayOutput[isVirtualEndpointGatewayServiceEndpoints] = endpointGateway.ServiceEndpoints
}
endpointGatewayOutput[isVirtualEndpointGatewayIPs] =
flattenDataSourceIPs(endpointGateway.Ips)
tags, err := flex.GetGlobalTagsUsingCRN(meta, *endpointGateway.CRN, "", isUserTagType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,38 @@ func testAccCheckIBMISVirtualEndpointGatewaysDataSourceConfig(vpcname1, subnetna
// status filter defaults to empty
return testAccCheckisVirtualEndpointGatewayConfigBasic(vpcname1, subnetname1, name1) + fmt.Sprintf(`
data "ibm_is_virtual_endpoint_gateways" "test1" {

depends_on = [ibm_is_virtual_endpoint_gateway.endpoint_gateway]
}`)
}

// service endpoints

func TestAccIBMISVirtualEndpointGatewaysDataSource_service_endpoints(t *testing.T) {
resName := "data.ibm_is_virtual_endpoint_gateways.test1"
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))
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMISVirtualEndpointGatewaysDataSourceServiceEndpointsConfig(vpcname1, subnetname1, name1),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
resName, "virtual_endpoint_gateways.0.name"),
resource.TestCheckResourceAttrSet(
resName, "virtual_endpoint_gateways.0.service_endpoints.#"),
),
},
},
})
}

func testAccCheckIBMISVirtualEndpointGatewaysDataSourceServiceEndpointsConfig(vpcname1, subnetname1, name1 string) string {
// status filter defaults to empty
return testAccCheckisVirtualEndpointGatewayConfigServiceEndpoints(vpcname1, subnetname1, name1) + fmt.Sprintf(`
data "ibm_is_virtual_endpoint_gateways" "test1" {
depends_on = [ibm_is_virtual_endpoint_gateway.endpoint_gateway]
}`)
}
12 changes: 12 additions & 0 deletions ibm/service/vpc/resource_ibm_is_virtual_endpoint_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const (
isVirtualEndpointGatewayVpcID = "vpc"
isVirtualEndpointGatewayTags = "tags"
isVirtualEndpointGatewaySecurityGroups = "security_groups"
isVirtualEndpointGatewayServiceEndpoints = "service_endpoints"
isVirtualEndpointGatewayAccessTags = "access_tags"
)

Expand Down Expand Up @@ -102,6 +103,14 @@ func ResourceIBMISEndpointGateway() *schema.Resource {
Computed: true,
Description: "Endpoint gateway created date and time",
},
isVirtualEndpointGatewayServiceEndpoints: {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "The fully qualified domain names for the target service. A fully qualified domain name for the target service",
},
isVirtualEndpointGatewayHealthState: {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -482,6 +491,9 @@ func resourceIBMisVirtualEndpointGatewayRead(d *schema.ResourceData, meta interf
d.Set(isVirtualEndpointGatewayResourceGroupID, endpointGateway.ResourceGroup.ID)
d.Set(isVirtualEndpointGatewayTarget,
flattenEndpointGatewayTarget(endpointGateway.Target.(*vpcv1.EndpointGatewayTarget)))
if len(endpointGateway.ServiceEndpoints) > 0 {
d.Set(isVirtualEndpointGatewayServiceEndpoints, endpointGateway.ServiceEndpoints)
}
d.Set(isVirtualEndpointGatewayVpcID, endpointGateway.VPC.ID)
if endpointGateway.SecurityGroups != nil {
d.Set(isVirtualEndpointGatewaySecurityGroups, flattenDataSourceSecurityGroups(endpointGateway.SecurityGroups))
Expand Down
55 changes: 53 additions & 2 deletions ibm/service/vpc/resource_ibm_is_virtual_endpoint_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ func testAccCheckisVirtualEndpointGatewayConfigFullySpecified(vpcname1, subnetna
resource "ibm_is_virtual_endpoint_gateway" "endpoint_gateway" {
name = "%[5]s"
target {
name = "ibm-dns-server2"
resource_type = "provider_infrastructure_service"
name = "ibm-dns-server2"
resource_type = "provider_infrastructure_service"
}
vpc = ibm_is_vpc.testacc_vpc.id
ips {
Expand Down Expand Up @@ -315,3 +315,54 @@ func testAccCheckisVirtualEndpointGatewayConfigBasicSecurityGroups(vpcname1, sub
security_groups = [ibm_is_security_group.testacc_security_group.id]
}`, vpcname1, subnetname1, acc.ISZoneName, acc.ISCIDR, sgname1, name1)
}

// for service endpoints
func testAccCheckisVirtualEndpointGatewayConfigServiceEndpoints(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-ntp-server"
resource_type = "provider_infrastructure_service"
}
vpc = ibm_is_vpc.testacc_vpc.id
resource_group = data.ibm_resource_group.test_acc.id
}`, vpcname1, subnetname1, acc.ISZoneName, acc.ISCIDR, name1)
}

func TestAccIBMISVirtualEndpointGateway_ServiceEndpoints(t *testing.T) {
var endpointGateway 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,
Steps: []resource.TestStep{
{
Config: testAccCheckisVirtualEndpointGatewayConfigServiceEndpoints(vpcname1, subnetname1, name1),
Check: resource.ComposeTestCheckFunc(
testAccCheckisVirtualEndpointGatewayExists(name, &endpointGateway),
resource.TestCheckResourceAttr(name, "name", name1),
resource.TestCheckResourceAttrSet(
name, "service_endpoints.#"),
),
},
},
})
}
1 change: 1 addition & 0 deletions website/docs/d/is_virtual_endpoint_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ In addition to the argument reference list, you can access the following attribu
- `resource_type` - (String) The resource type of the subnet reserved IP.
- `vpc` - (String) The VPC ID.
- `security_groups` (List) - The security groups to use for this endpoint gateway.
- `service_endpoints`- (Array of Strings) The fully qualified domain names for the target service. A fully qualified domain name for the target service


1 change: 1 addition & 0 deletions website/docs/d/is_virtual_endpoint_gateways.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ In addition to the argument reference list, you can access the following attribu
- `resource_type` - (String) The endpoint gateway target resource type.
- `vpc` - (String) The VPC ID.
- `security_groups` (List) - The security groups to use for this endpoint gateway.
- `service_endpoints`- (Array of Strings) The fully qualified domain names for the target service. A fully qualified domain name for the target service
1 change: 1 addition & 0 deletions website/docs/r/is_virtual_endpoint_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ In addition to all argument reference list, you can access the following attribu

- `lifecycle_state` - (String) The lifecycle state of the endpoint gateway.
- `resource_type` - (String) The endpoint gateway resource type.
- `service_endpoints`- (Array of Strings) The fully qualified domain names for the target service. A fully qualified domain name for the target service

## Import
The `ibm_is_virtual_endpoint_gateway` resource can be imported by using virtual endpoint gateway ID.
Expand Down