Skip to content

Commit 8b59eca

Browse files
ganbarassagarp337
authored andcommitted
Enabling API Custom Timeout through parameter
1 parent 12d800d commit 8b59eca

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

main.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"flag"
99
"log"
1010
"os"
11+
"strconv"
1112
"strings"
1213

1314
"github.com/hashicorp/terraform-plugin-framework/providerserver"
@@ -48,6 +49,7 @@ func main() {
4849
var parallelism = flag.Int("parallelism", 1, "The number of threads to use for resource discovery. By default the value is 1")
4950
var varsResourceLevel = flag.String("variables_resource_level", "", "[export] List of top-level attributes to be export as variable following format resourceType.attribute, if attribute is present in variables_global_level, it will be excluded for this resourceType")
5051
var varsGlobalLevel = flag.String("variables_global_level", "", "[export] List of top-level attributes to be export as variable following format attribute1,attribute2, if attribute present in variables_resource_level, it will be excluded for this resourceType")
52+
var customApiTimeout = flag.String("custom_api_timeout", "", "[export] The time duration for which API calls will wait for response from the service. By default, we rely on timeout set by SDK")
5153

5254
flag.Parse()
5355
globalvar.PrintVersion()
@@ -141,6 +143,27 @@ func main() {
141143
args.Filters = filterFlag
142144
}
143145

146+
if customApiTimeout != nil && *customApiTimeout != "" {
147+
if timeInSeconds, err := strconv.Atoi(*customApiTimeout); err != nil || timeInSeconds < 0 {
148+
log.Printf("[WARNING]: Custom API timeout - %s - found but could not be converted to a postive integer", *customApiTimeout)
149+
} else {
150+
log.Printf("[DEBUG]:Setting custom API timeout of %d seconds as ENV variable OCI_CUSTOM_CLIENT_TIMEOUT", timeInSeconds)
151+
err := os.Setenv("OCI_CUSTOM_CLIENT_TIMEOUT", strconv.Itoa(timeInSeconds))
152+
if err != nil {
153+
log.Printf("[ERROR]: Error while setting custom API Timeout as ENV variable OCI_CUSTOM_CLIENT_TIMEOUT- %s", err)
154+
} else {
155+
log.Printf("[DEBUG]: Success setting custom API Timeout as ENV variable OCI_CUSTOM_CLIENT_TIMEOUT- %s", os.Getenv("OCI_CUSTOM_CLIENT_TIMEOUT"))
156+
}
157+
}
158+
} else {
159+
err := os.Setenv("OCI_CUSTOM_CLIENT_TIMEOUT", "")
160+
if err != nil {
161+
log.Printf("[ERROR]: Error while setting default API Timeout as ENV variable OCI_CUSTOM_CLIENT_TIMEOUT to empty string - %s", err)
162+
} else {
163+
log.Printf("[DEBUG]: Success setting default API Timeout as ENV variable OCI_CUSTOM_CLIENT_TIMEOUT to empty string - %s", os.Getenv("OCI_CUSTOM_CLIENT_TIMEOUT"))
164+
}
165+
}
166+
144167
err, status := resourcediscovery.RunExportCommand(args)
145168
if err != nil {
146169
color.Red("%v", err)

website/docs/guides/resource_discovery.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ Make sure the `output_path` is empty before running resource discovery
120120
* `output_path` - Absolute path to output generated configurations and state files of the exported compartment
121121
* `parallelism` - The number of threads to use for resource discovery. By default the value is 1
122122
* `retry_timeout` - 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
123+
* `custom_api_timeout` - Specifies the maximum duration an API call will wait for a response before timing out. The default value is 60 seconds.
123124
* `services` - Comma-separated list of service resources to export. If not specified, all resources within the given compartment (which excludes identity resources) are exported. The following values can be specified:
124125
* `adm` - Discovers adm resources within the specified compartment
125126
* `ai_data_platform` - Discovers ai_data_platform resources within the specified compartment

0 commit comments

Comments
 (0)