Skip to content

Commit 6232d62

Browse files
committed
Fixed #629
1 parent 633d7a6 commit 6232d62

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

dynatrace/api/builtin/monitoring/slo/service.go

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"fmt"
2525
"net/url"
2626
"strings"
27+
"time"
2728

2829
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api"
2930
slo "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/builtin/monitoring/slo/settings"
@@ -66,14 +67,25 @@ func (me *service) Create(ctx context.Context, v *slo.Settings) (*api.Stub, erro
6667
}
6768
stub.LegacyID = &stub.ID
6869

69-
if stubs, err := me.List(ctx); err == nil {
70-
for _, listStub := range stubs {
71-
if listStub.Name == stub.Name {
72-
stub.ID = listStub.ID
70+
retries := 12
71+
for i := 1; i <= retries; i++ {
72+
if stubs, err := me.List(ctx); err == nil {
73+
for _, listStub := range stubs {
74+
if listStub.Name == stub.Name {
75+
stub.ID = listStub.ID
76+
}
7377
}
7478
}
75-
} else {
76-
return nil, err
79+
if len(stub.ID) > 0 {
80+
break
81+
}
82+
time.Sleep(5 * time.Second)
83+
}
84+
if len(stub.ID) == 0 {
85+
if err := service.Delete(ctx, *stub.LegacyID); err != nil {
86+
return nil, err
87+
}
88+
return nil, errors.New("SLO creation failed, unable to retrieve ID. Please create a GitHub issue.")
7789
}
7890

7991
return stub, nil
@@ -128,7 +140,14 @@ func (me *service) Get(ctx context.Context, id string, v *slo.Settings) error {
128140
err := me.get(ctx, id, v)
129141
if err != nil {
130142
if err.Error() == "Cannot access a disabled SLO." {
131-
return errors.New("inaccessible")
143+
settingsObject := settings20.SettingsObject{}
144+
req := me.client.Get(ctx, fmt.Sprintf("/api/v2/settings/objects/%s", id), 200)
145+
if err = req.Finish(&settingsObject); err != nil {
146+
return err
147+
}
148+
if err = json.Unmarshal(settingsObject.Value, v); err != nil {
149+
return err
150+
}
132151
}
133152
return err
134153
}

templates/resources/slo.md.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ description: |-
88
99
# dynatrace_slo (Resource)
1010
11+
!> This resource API endpoint has been deprecated, please use [dynatrace_slo_v2](https://registry.terraform.io/providers/dynatrace-oss/dynatrace/latest/docs/resources/slo_v2) instead.
12+
1113
-> This resource requires the API token scopes **Read SLO** (`slo.read`) and **Write SLO** (`slo.write`)
1214
1315
## Dynatrace Documentation

templates/resources/slo_v2.md.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description: |-
88
99
# dynatrace_slo_v2 (Resource)
1010
11-
-> This resource requires the API token scopes **Read settings** (`settings.read`) and **Write settings** (`settings.write`)
11+
-> This resource requires the API token scopes **Read SLO** (`slo.read`), **Write SLO** (`slo.write`), **Read settings** (`settings.read`) and **Write settings** (`settings.write`)
1212
1313
## Dynatrace Documentation
1414

0 commit comments

Comments
 (0)