forked from yandex-cloud/terraform-provider-yandex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull request #1233: change project structure in yandex-framework pkg …
…\ remove utils package \ change yandex-framework test structure Merge in CLOUD/terraform-provider-yandex-mirror from terraform-provider-framework-resources-refactor to master Squashed commit of the following: commit 9a8260d50c024a197d7a60102df6994349c5f7f5 Author: Mikhail Smolin <[email protected]> Date: Mon May 13 15:52:42 2024 +0200 add todo for min func commit 74b531c010aca4e24e910925b5f6afb6edb428bd Author: Mikhail Smolin <[email protected]> Date: Mon Apr 29 19:19:34 2024 +0200 change project structure in yandex-framework pkg \ remove utils package \ change yandex-framework test structure
- Loading branch information
Mikhail Smolin
committed
May 15, 2024
1 parent
726c614
commit c938f03
Showing
55 changed files
with
682 additions
and
654 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package math | ||
|
||
// TODO (miksmolin) will have been replaced with function from std package after go 1.21 update | ||
func Min(a, b int) int { | ||
if a < b { | ||
return a | ||
} | ||
return b | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package resourceid | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func Construct(clusterID string, resourceName string) string { | ||
return fmt.Sprintf("%s:%s", clusterID, resourceName) | ||
} | ||
|
||
func Deconstruct(resourceID string) (string, string, error) { | ||
parts := strings.SplitN(resourceID, ":", 2) | ||
if len(parts) != 2 { | ||
return "", "", fmt.Errorf("Invalid resource id format: %q", resourceID) | ||
} | ||
|
||
clusterID := parts[0] | ||
resourceName := parts[1] | ||
return clusterID, resourceName, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package retry | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"regexp" | ||
|
||
"github.com/hashicorp/terraform-plugin-log/tflog" | ||
"github.com/yandex-cloud/go-genproto/yandex/cloud/operation" | ||
ycsdk "github.com/yandex-cloud/go-sdk" | ||
sdkoperation "github.com/yandex-cloud/go-sdk/operation" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
func ConflictingOperation(ctx context.Context, sdk *ycsdk.SDK, action func() (*operation.Operation, error)) (*sdkoperation.Operation, error) { | ||
for { | ||
op, err := sdk.WrapOperation(action()) | ||
if err == nil { | ||
return op, nil | ||
} | ||
|
||
operationID := "" | ||
message := status.Convert(err).Message() | ||
submatchGoApi := regexp.MustCompile(`conflicting operation "(.+)" detected`).FindStringSubmatch(message) | ||
submatchPyApi := regexp.MustCompile(`Conflicting operation (.+) detected`).FindStringSubmatch(message) | ||
if len(submatchGoApi) > 0 { | ||
operationID = submatchGoApi[1] | ||
} else if len(submatchPyApi) > 0 { | ||
operationID = submatchPyApi[1] | ||
} else { | ||
return op, err | ||
} | ||
|
||
tflog.Debug(ctx, fmt.Sprintf("Waiting for conflicting operation %q to complete", operationID)) | ||
req := &operation.GetOperationRequest{OperationId: operationID} | ||
op, err = sdk.WrapOperation(sdk.Operation().Get(ctx, req)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
_ = op.Wait(ctx) | ||
tflog.Debug(ctx, fmt.Sprintf("Conflicting operation %q has completed. Going to retry initial action.", operationID)) | ||
} | ||
} |
5 changes: 2 additions & 3 deletions
5
...ndex-billing-cloud-binding/data_source.go → ...framework/services/billing/data_source.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...work/yandex-billing-cloud-binding/util.go → yandex-framework/services/billing/util.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package yandex_billing_cloud_binding | ||
package billing | ||
|
||
import ( | ||
"context" | ||
|
5 changes: 3 additions & 2 deletions
5
...andex-datasphere/community/data_source.go → ...vices/datasphere/community/data_source.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...andex-datasphere/community/iam_binding.go → ...vices/datasphere/community/iam_binding.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ork/yandex-datasphere/community/models.go → ...k/services/datasphere/community/models.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.