diff --git a/stackit/internal/services/postgresflexalpha/instance/resource.go b/stackit/internal/services/postgresflexalpha/instance/resource.go index d07bf546..0c969cb8 100644 --- a/stackit/internal/services/postgresflexalpha/instance/resource.go +++ b/stackit/internal/services/postgresflexalpha/instance/resource.go @@ -7,6 +7,7 @@ import ( "math" "net/http" "strings" + "time" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -241,6 +242,8 @@ func (r *instanceResource) Create( } waitResp, err := wait.CreateInstanceWaitHandler(ctx, r.client.DefaultAPI, projectID, region, *instanceID). + SetTimeout(30 * time.Minute). + SetSleepBeforeWait(10 * time.Second). WaitWithContext(ctx) if err != nil { core.LogAndAddError( diff --git a/stackit/internal/services/postgresflexalpha/postgresflex_acc_test.go b/stackit/internal/services/postgresflexalpha/postgresflex_acc_test.go index 0afc46ad..11b2ac99 100644 --- a/stackit/internal/services/postgresflexalpha/postgresflex_acc_test.go +++ b/stackit/internal/services/postgresflexalpha/postgresflex_acc_test.go @@ -672,8 +672,8 @@ func defaultInstanceTestChecks(testItemID string, data resData) resource.TestChe resource.TestCheckResourceAttrSet(testItemID, "backup_schedule"), resource.TestCheckResourceAttr(testItemID, "backup_schedule", data.BackupSchedule), - resource.TestCheckResourceAttrSet(testItemID, "connection_info"), - resource.TestCheckResourceAttrSet(testItemID, "connection_info.write"), + resource.TestCheckResourceAttr(testItemID, "connection_info.%", "1"), + resource.TestCheckResourceAttr(testItemID, "connection_info.write.%", "2"), resource.TestCheckResourceAttrSet(testItemID, "connection_info.write.host"), resource.TestCheckResourceAttrSet(testItemID, "connection_info.write.port"), @@ -694,10 +694,9 @@ func defaultInstanceTestChecks(testItemID string, data resData) resource.TestChe resource.TestCheckResourceAttrSet(testItemID, "network"), resource.TestCheckResourceAttrSet(testItemID, "network.access_scope"), resource.TestCheckResourceAttr(testItemID, "network.access_scope", data.AccessScope), - resource.TestCheckResourceAttrSet(testItemID, "network.acl"), + // resource.TestCheckResourceAttrSet(testItemID, "network.acl"), resource.TestCheckResourceAttr(testItemID, "network.acl.#", strconv.Itoa(len(data.ACLStrings))), - resource.TestCheckResourceAttrSet(testItemID, "network.instance_address"), - // router address is checken in noenc/ enc + // instance_address and router_address are only checked in enc resource.TestCheckResourceAttrSet(testItemID, "project_id"), resource.TestCheckResourceAttr(testItemID, "project_id", data.ProjectID), diff --git a/stackit/internal/wait/postgresflexalpha/wait.go b/stackit/internal/wait/postgresflexalpha/wait.go index ed945f3d..3d80ffd5 100644 --- a/stackit/internal/wait/postgresflexalpha/wait.go +++ b/stackit/internal/wait/postgresflexalpha/wait.go @@ -171,8 +171,6 @@ func CreateInstanceWaitHandler( return false, nil, nil }, ) - // Sleep before wait is set because sometimes API returns 404 right after creation request - handler.SetTimeout(90 * time.Minute).SetSleepBeforeWait(30 * time.Second) return handler } @@ -222,7 +220,6 @@ func PartialUpdateInstanceWaitHandler( } }, ) - handler.SetTimeout(45 * time.Minute).SetSleepBeforeWait(30 * time.Second) return handler } diff --git a/stackit/internal/wait/postgresflexalpha/wait_test.go b/stackit/internal/wait/postgresflexalpha/wait_test.go index faef6cbf..dff02229 100644 --- a/stackit/internal/wait/postgresflexalpha/wait_test.go +++ b/stackit/internal/wait/postgresflexalpha/wait_test.go @@ -22,6 +22,7 @@ func TestCreateInstanceWaitHandler(t *testing.T) { usersGetErrorStatus int wantErr bool wantRes *v3alpha1api.GetInstanceResponse + timeout time.Duration }{ { desc: "create_succeeded", @@ -56,7 +57,17 @@ func TestCreateInstanceWaitHandler(t *testing.T) { RouterAddress: utils.Ptr("10.0.0.1"), }, wantErr: true, - wantRes: nil, + wantRes: &v3alpha1api.GetInstanceResponse{ + Id: "foo-bar", + Status: InstanceStateFailed, + Network: v3alpha1api.InstanceNetwork{ + AccessScope: nil, + Acl: nil, + InstanceAddress: utils.Ptr("10.0.0.1"), + RouterAddress: utils.Ptr("10.0.0.1"), + }, + }, + timeout: 30 * time.Second, }, { desc: "create_failed_2", @@ -181,9 +192,13 @@ func TestCreateInstanceWaitHandler(t *testing.T) { ListUsersRequestExecuteMock: &listUsersMock, } - handler := CreateInstanceWaitHandler(context.Background(), apiClientMock, "", "", instanceID) + handler := CreateInstanceWaitHandler(context.Background(), apiClientMock, "", "", instanceID). + SetTimeout(10 * time.Millisecond) + if tt.timeout != 0 { + handler.SetTimeout(tt.timeout) + } - gotRes, err := handler.SetTimeout(10 * time.Millisecond).SetSleepBeforeWait(1 * time.Millisecond).WaitWithContext(context.Background()) + gotRes, err := handler.SetSleepBeforeWait(1 * time.Millisecond).WaitWithContext(context.Background()) if (err != nil) != tt.wantErr { t.Fatalf("handler error = %v, wantErr %v", err, tt.wantErr) } @@ -204,6 +219,7 @@ func TestUpdateInstanceWaitHandler(t *testing.T) { instanceNetwork v3alpha1api.InstanceNetwork wantErr bool wantRes *v3alpha1api.GetInstanceResponse + timeout time.Duration }{ { desc: "update_succeeded", @@ -248,6 +264,7 @@ func TestUpdateInstanceWaitHandler(t *testing.T) { RouterAddress: utils.Ptr("10.0.0.1"), }, }, + timeout: 30 * time.Second, }, { desc: "update_failed_2", @@ -316,9 +333,13 @@ func TestUpdateInstanceWaitHandler(t *testing.T) { ListUsersRequestExecuteMock: &listUsersMock, } - handler := PartialUpdateInstanceWaitHandler(context.Background(), apiClientMock, "", "", instanceID) + handler := PartialUpdateInstanceWaitHandler(context.Background(), apiClientMock, "", "", instanceID). + SetTimeout(10 * time.Millisecond) + if tt.timeout > 0 { + handler.SetTimeout(tt.timeout) + } - gotRes, err := handler.SetTimeout(10 * time.Millisecond).WaitWithContext(context.Background()) + gotRes, err := handler.WaitWithContext(context.Background()) if (err != nil) != tt.wantErr { t.Fatalf("handler error = %v, wantErr %v", err, tt.wantErr) }