99 "regexp"
1010 "strings"
1111 "sync"
12+ "time"
1213
1314 "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/rest/logging"
1415 "github.com/dynatrace/dynatrace-configuration-as-code-core/api/rest"
@@ -47,15 +48,19 @@ func createPlatformRestClient(u string, httpClient *http.Client) (*rest.Client,
4748 return nil , fmt .Errorf ("failed to parse URL %q: %w" , u , err )
4849 }
4950
50- opts := []rest.Option {rest .WithHTTPListener (logging .HTTPListener ("plat/tok" ))}
51+ opts := []rest.Option {
52+ rest .WithHTTPListener (logging .HTTPListener ("plat/tok" )),
53+ rest .WithRateLimiter (),
54+ rest .WithRetryOptions (& rest.RetryOptions {MaxRetries : 30 , DelayAfterRetry : 10 * time .Second , ShouldRetryFunc : rest .RetryIfTooManyRequests }),
55+ }
5156
5257 restClient := rest .NewClient (parsedURL , httpClient , opts ... )
5358 restClient .SetHeader ("User-Agent" , "Dynatrace Terraform Provider" )
5459
5560 return restClient , nil
5661}
5762
58- func platformClient (platformURL string , credentials * Credentials ) (* rest.Client , error ) {
63+ func platformClient (ctx context. Context , platformURL string , credentials * Credentials ) (* rest.Client , error ) {
5964 clientID := credentials .OAuth .ClientID
6065 clientSecret := credentials .OAuth .ClientSecret
6166
@@ -72,11 +77,13 @@ func platformClient(platformURL string, credentials *Credentials) (*rest.Client,
7277 client , err = createPlatformRestClient (platformURL , NewBearerTokenBasedClient (credentials .OAuth .PlatformToken ))
7378 } else if credentials .ContainsOAuth () {
7479 factory := clients .Factory ()
80+ factory = factory .WithRetryOptions (& rest.RetryOptions {MaxRetries : 30 , DelayAfterRetry : 10 * time .Second , ShouldRetryFunc : rest .RetryIfTooManyRequests })
81+ factory = factory .WithRateLimiter (true )
7582 factory = factory .WithUserAgent ("Dynatrace Terraform Provider" )
7683 factory = factory .WithPlatformURL (platformURL )
7784 factory = factory .WithHTTPListener (logging .HTTPListener ("platform" ))
7885 factory = factory .WithOAuthCredentials (clientcredentials.Config {ClientID : clientID , ClientSecret : clientSecret , TokenURL : evalTokenURL (platformURL )})
79- client , err = factory .CreatePlatformClient (context . Background () )
86+ client , err = factory .CreatePlatformClient (ctx )
8087 } else {
8188 return nil , errors .New ("neither oauth credentials nor platform token present" )
8289 }
@@ -98,7 +105,7 @@ func (me *platform_request) Finish(optionalTarget ...any) error {
98105
99106 platformURL := me .evalPlatformURL ()
100107
101- client , err := platformClient (platformURL , me .client .Credentials ())
108+ client , err := platformClient (me . ctx , platformURL , me .client .Credentials ())
102109 if err != nil {
103110 return err
104111 }
0 commit comments