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

fix(EGW): avoid tainting endpoint gateway on timeout when the target PPSG has the access policy as review #5752

Merged
merged 5 commits into from
Nov 4, 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
31 changes: 23 additions & 8 deletions ibm/service/vpc/resource_ibm_is_virtual_endpoint_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"log"
"os"
"strings"
"time"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
Expand Down Expand Up @@ -382,17 +383,31 @@ func resourceIBMisVirtualEndpointGatewayCreate(d *schema.ResourceData, meta inte

d.SetId(*endpointGateway.ID)

if d.Get(targetResourceTypeFmt).(string) == "private_path_service_gateway" {
_, err = isWaitForVirtualEndpointGatewayForPPSGAvailable(sess, d.Id(), d.Timeout(schema.TimeoutCreate))
if err != nil {
return err
}
} else {
_, err = isWaitForVirtualEndpointGatewayAvailable(sess, d.Id(), d.Timeout(schema.TimeoutCreate))
if err != nil {
_, err = isWaitForVirtualEndpointGatewayAvailable(sess, d.Id(), d.Timeout(schema.TimeoutCreate))
if err != nil {
if d.Get(targetResourceTypeFmt).(string) == "private_path_service_gateway" {
isAccessPending := false
if strings.Contains(err.Error(), "timeout while waiting for state to become") {
opt := sess.NewGetEndpointGatewayOptions(d.Id())
endpointGateway, response, err := sess.GetEndpointGateway(opt)
if err != nil {
log.Printf("Get Endpoint Gateway failed: %v", response)
return fmt.Errorf("[ERROR] Get Endpoint Gateway failed %s\n%s", err, response)
}
if len(endpointGateway.LifecycleReasons) > 0 {
if endpointGateway.LifecycleReasons[0].Code != nil && strings.Compare(*endpointGateway.LifecycleReasons[0].Code, "access_pending") == 0 {
isAccessPending = true
}
}
}
if !isAccessPending {
return err
}
} else {
return err
}
}

v := os.Getenv("IC_ENV_TAGS")
if _, ok := d.GetOk(isVirtualEndpointGatewayTags); ok || v != "" {
oldList, newList := d.GetChange(isVirtualEndpointGatewayTags)
Expand Down
46 changes: 46 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 @@ -62,6 +62,34 @@ func TestAccIBMISVirtualEndpointGateway_PPSG(t *testing.T) {
},
})
}
func TestAccIBMISVirtualEndpointGateway_PPSG_With_AccessPolicy_Review_And_Timeout(t *testing.T) {
var endpointGateway string
accessPolicy := "review"
vpcname := fmt.Sprintf("tflb-vpc-%d", acctest.RandIntRange(10, 100))
subnetname := fmt.Sprintf("tflb-subnet-name-%d", acctest.RandIntRange(10, 100))
lbname := fmt.Sprintf("tf-test-lb%dd", acctest.RandIntRange(10, 100))
name1 := fmt.Sprintf("tf-test-ppsg%d", acctest.RandIntRange(10, 100))
name := "ibm_is_virtual_endpoint_gateway.endpoint_gateway"
// targetName := fmt.Sprintf("tf-egw-target%d", acctest.RandIntRange(10, 100))
egwName := fmt.Sprintf("tf-egw%d", acctest.RandIntRange(10, 100))
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckisVirtualEndpointGatewayConfigPPSGWithTimeout(vpcname, subnetname, acc.ISZoneName, acc.ISCIDR, lbname, accessPolicy, name1, egwName),
Check: resource.ComposeTestCheckFunc(
testAccCheckisVirtualEndpointGatewayExists(name, &endpointGateway),
resource.TestCheckResourceAttr(name, "name", egwName),
resource.TestCheckResourceAttr(name, "lifecycle_state", "pending"),
resource.TestCheckResourceAttr(name, "lifecycle_reasons.0.code", "access_pending"),
resource.TestCheckResourceAttr(name, "target.0.name", name1),
resource.TestCheckResourceAttr(name, "target.0.resource_type", "private_path_service_gateway"),
),
},
},
})
}
func TestAccIBMISVirtualEndpointGateway_AllowDnsResolutionBinding(t *testing.T) {
var endpointGateway string
vpcname1 := fmt.Sprintf("tfvpngw-vpc-%d", acctest.RandIntRange(10, 100))
Expand Down Expand Up @@ -357,6 +385,24 @@ func testAccCheckisVirtualEndpointGatewayConfigPPSG(vpcname, subnetname, zone, c
resource_group = data.ibm_resource_group.test_acc.id
}`, egwName)
}
func testAccCheckisVirtualEndpointGatewayConfigPPSGWithTimeout(vpcname, subnetname, zone, cidr, lbname, accessPolicy, name, egwName string) string {
return testAccCheckIBMIsPrivatePathServiceGatewayConfigBasic(vpcname, subnetname, acc.ISZoneName, acc.ISCIDR, lbname, accessPolicy, name) + fmt.Sprintf(`
data "ibm_resource_group" "test_acc" {
is_default=true
}
resource "ibm_is_virtual_endpoint_gateway" "endpoint_gateway" {
name = "%s"
target {
crn = ibm_is_private_path_service_gateway.is_private_path_service_gateway.crn
resource_type = "private_path_service_gateway"
}
vpc = ibm_is_vpc.testacc_vpc.id
resource_group = data.ibm_resource_group.test_acc.id
timeouts {
create = "3m"
}
}`, egwName)
}
func testAccCheckisVirtualEndpointGatewayConfigAllowDnsResolutionBinding(vpcname1, name1 string, enable_hub, allowDnsResolutionBinding bool) string {
return fmt.Sprintf(`
resource "ibm_is_vpc" "testacc_vpc" {
Expand Down
Loading