Skip to content

Commit 5893750

Browse files
committed
Add new argument retry_timeout to export command for configuring retry duration
1 parent 7625a77 commit 5893750

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func main() {
2727
var generateStateFile = flag.Bool("generate_state", false, "[export][experimental] Set this to import the discovered resources into a state file along with the Terraform configuration")
2828
var help = flag.Bool("help", false, "Prints usage options")
2929
var tfVersion = flag.String("tf_version", "0.12", "The version of terraform syntax to generate for configurations. The state file will be written in v0.12 only. The allowed values are :\n * 0.11\n * 0.12")
30+
var retryTimeout = flag.String("retry_timeout", "15s", "[export] The time duration for which API calls will wait and retry operation in case of API errors. By default, the retry timeout duration is 15s")
3031

3132
flag.Parse()
3233
provider.PrintVersion()
@@ -62,6 +63,7 @@ func main() {
6263
OutputDir: outputPath,
6364
GenerateState: *generateStateFile,
6465
TFVersion: &terraformVersion,
66+
RetryTimeout: retryTimeout,
6567
}
6668

6769
if services != nil && *services != "" {

oci/export_compartment.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ type ExportCommandArgs struct {
119119
OutputDir *string
120120
GenerateState bool
121121
TFVersion *TfHclVersion
122+
RetryTimeout *string
122123
}
123124

124125
func RunExportCommand(args *ExportCommandArgs) (error, Status) {
@@ -163,6 +164,19 @@ func RunExportCommand(args *ExportCommandArgs) (error, Status) {
163164

164165
ctx := createResourceDiscoveryContext(clients.(*OracleClients), args, tenancyOcid)
165166

167+
/*
168+
Setting retry timeout to a lower value for resource discovery
169+
This is done to handle the 404 and 500 errors in case
170+
any resource is unavailable in a region or in case the service is down
171+
The time out value is configurable from export command
172+
*/
173+
if args.RetryTimeout != nil && *args.RetryTimeout != "" {
174+
longRetryTime = *getTimeoutDuration(*args.RetryTimeout)
175+
shortRetryTime = longRetryTime
176+
}
177+
178+
log.Printf("[INFO] resource discovery retry timeout duration set to %v", shortRetryTime)
179+
166180
if err := runExportCommand(ctx); err != nil {
167181
return err, StatusFail
168182
}

oci/export_resource_helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ type resourceDiscoveryContext struct {
9090
// Resource discovery Exit status
9191
type Status int
9292

93-
// Exit statuses
9493
const (
94+
// Exit statuses
9595
StatusSuccess Status = iota
9696
StatusFail
9797
StatusPartialSuccess

0 commit comments

Comments
 (0)