Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

SP-8946 Update test_interval_in_seconds type #110

Merged
merged 14 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions docs/resources/uri.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ resource "swo_uri" "test" {
```

<!-- schema generated by tfplugindocs -->

## Schema

### Required
Expand All @@ -79,15 +80,16 @@ resource "swo_uri" "test" {
- `id` (String) The Id of the resource provided by the backend.

<a id="nestedatt--options"></a>

### Nested Schema for `options`

Required:

- `is_ping_enabled` (Boolean) Whether or not to enable ping monitoring.
- `is_tcp_enabled` (Boolean) Whether or not to enable tcp monitoring.


<a id="nestedatt--test_definitions"></a>

### Nested Schema for `test_definitions`

Required:
Expand All @@ -98,18 +100,19 @@ Required:
Optional:

- `platform_options` (Attributes) The platform options for this Uri check. (see [below for nested schema](#nestedatt--test_definitions--platform_options))
- `test_interval_in_seconds` (Number) The interval to test in seconds. Default is `900`.
- `test_interval_in_seconds` (Number) The interval to test in seconds. Default is `900`. Valid values are `60, 300, 600, 900, 1800, 3600, 7200, 14400`

<a id="nestedatt--test_definitions--location_options"></a>

### Nested Schema for `test_definitions.location_options`

Required:

- `type` (String) The Website availability monitoring location option type. Valid values are [`REGION`|`COUNTRY`|`CITY`].
- `value` (String) The Website availability monitoring location option value.


<a id="nestedatt--test_definitions--platform_options"></a>

### Nested Schema for `test_definitions.platform_options`

Required:
Expand All @@ -120,9 +123,8 @@ Optional:

- `platforms` (Set of String) The platforms to test from. Valid values are [`AWS`, `AZURE`].



<a id="nestedatt--tcp_options"></a>

### Nested Schema for `tcp_options`

Required:
Expand Down
19 changes: 11 additions & 8 deletions docs/resources/website.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ resource "swo_website" "test_website" {
```

<!-- schema generated by tfplugindocs -->

## Schema

### Required
Expand All @@ -93,6 +94,7 @@ resource "swo_website" "test_website" {
- `id` (String) The Id of the resource provided by the backend.

<a id="nestedatt--monitoring"></a>

### Nested Schema for `monitoring`

Required:
Expand All @@ -106,6 +108,7 @@ Optional:
- `options` (Attributes, Deprecated) The Website monitoring options. (see [below for nested schema](#nestedatt--monitoring--options))

<a id="nestedatt--monitoring--availability"></a>

### Nested Schema for `monitoring.availability`

Required:
Expand All @@ -114,41 +117,42 @@ Required:
- `platform_options` (Attributes) The Website availability monitoring platform options. (see [below for nested schema](#nestedatt--monitoring--availability--platform_options))
- `protocols` (List of String) The Website availability monitoring protocols.
- `test_from_location` (String) The Website availability monitoring test from location. Valid values are [`REGION`|`COUNTRY`|`CITY`].
- `test_interval_in_seconds` (Number) The Website availability monitoring test interval in seconds.
- `test_interval_in_seconds` (Number) The Website availability monitoring test interval in seconds. Valid values are `60, 300, 600, 900, 1800, 3600, 7200, 14400`

Optional:

- `check_for_string` (Attributes) The Website availability monitoring check for string settings. (see [below for nested schema](#nestedatt--monitoring--availability--check_for_string))
- `ssl` (Attributes) The Website availability monitoring SSL settings. (see [below for nested schema](#nestedatt--monitoring--availability--ssl))

<a id="nestedatt--monitoring--availability--location_options"></a>

### Nested Schema for `monitoring.availability.location_options`

Required:

- `type` (String) The Website availability monitoring location option type. Valid values are [`REGION`|`COUNTRY`|`CITY`].
- `value` (String) The Website availability monitoring location option value.


<a id="nestedatt--monitoring--availability--platform_options"></a>

### Nested Schema for `monitoring.availability.platform_options`

Required:

- `platforms` (List of String) The Website availability monitoring platform options. Valid values are [AWS, AZURE].
- `test_from_all` (Boolean) Test from all platforms?


<a id="nestedatt--monitoring--availability--check_for_string"></a>

### Nested Schema for `monitoring.availability.check_for_string`

Required:

- `operator` (String) The Website availability monitoring check for string operator.
- `value` (String) The Website availability monitoring check for string value.


<a id="nestedatt--monitoring--availability--ssl"></a>

### Nested Schema for `monitoring.availability.ssl`

Required:
Expand All @@ -157,18 +161,17 @@ Required:
- `enabled` (Boolean) Is SSL monitoring enabled?
- `ignore_intermediate_certificates` (Boolean) Ignore intermediate certificates?



<a id="nestedatt--monitoring--custom_headers"></a>

### Nested Schema for `monitoring.custom_headers`

Required:

- `name` (String) The Website custom header name.
- `value` (String) The Website custom header value.


<a id="nestedatt--monitoring--rum"></a>

### Nested Schema for `monitoring.rum`

Required:
Expand All @@ -180,8 +183,8 @@ Read-Only:

- `snippet` (String) The Website RUM monitoring code snippet (provided by the server).


<a id="nestedatt--monitoring--options"></a>

### Nested Schema for `monitoring.options`

Required:
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ go 1.23
toolchain go1.23.0

require (
github.com/cenkalti/backoff/v5 v5.0.0
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/hashicorp/terraform-plugin-docs v0.20.1
github.com/hashicorp/terraform-plugin-framework v1.13.0
github.com/hashicorp/terraform-plugin-framework-validators v0.16.0
github.com/hashicorp/terraform-plugin-go v0.25.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.35.0
github.com/solarwinds/swo-client-go v0.0.9
github.com/solarwinds/swo-client-go v0.0.11
golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819
)

Expand All @@ -23,7 +24,7 @@ require (

require (
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/Khan/genqlient v0.6.0 // indirect
github.com/Khan/genqlient v0.7.0 // indirect
github.com/Kunde21/markdownfmt/v3 v3.1.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
Expand Down
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/Khan/genqlient v0.6.0 h1:Bwb1170ekuNIVIwTJEqvO8y7RxBxXu639VJOkKSrwAk=
github.com/Khan/genqlient v0.6.0/go.mod h1:rvChwWVTqXhiapdhLDV4bp9tz/Xvtewwkon4DpWWCRM=
github.com/Khan/genqlient v0.7.0 h1:GZ1meyRnzcDTK48EjqB8t3bcfYvHArCUUvgOwpz1D4w=
github.com/Khan/genqlient v0.7.0/go.mod h1:HNyy3wZvuYwmW3Y7mkoQLZsa/R5n5yIRajS1kPBvSFM=
github.com/Kunde21/markdownfmt/v3 v3.1.0 h1:KiZu9LKs+wFFBQKhrZJrFZwtLnCCWJahL+S+E/3VnM0=
github.com/Kunde21/markdownfmt/v3 v3.1.0/go.mod h1:tPXN1RTyOzJwhfHoon9wUr4HGYmWgVxSQN6VBJDkrVc=
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
Expand Down Expand Up @@ -31,6 +31,8 @@ github.com/bmatcuk/doublestar/v4 v4.7.1 h1:fdDeAqgT47acgwd9bd9HxJRDmc9UAmPpc+2m0
github.com/bmatcuk/doublestar/v4 v4.7.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
github.com/cenkalti/backoff/v5 v5.0.0 h1:4ziwFuaVJicDO1ah1Nz1aXXV1caM28PFgf1V5TTFXew=
github.com/cenkalti/backoff/v5 v5.0.0/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=
Expand Down Expand Up @@ -182,8 +184,8 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A=
github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo=
github.com/solarwinds/swo-client-go v0.0.9 h1:OZtFlqGxKxhE5U9UusYNVfcLR/jz4oOluEYGRlk1ub0=
github.com/solarwinds/swo-client-go v0.0.9/go.mod h1:2JrbtEpyD7sSLaT3Os/49M0okBiCMESEzSxw8+3e5Mk=
github.com/solarwinds/swo-client-go v0.0.11 h1:0vmqJ3HY2H55rRLKdwE6nsEMbbAVhyy7lEAXyh2a4F4=
github.com/solarwinds/swo-client-go v0.0.11/go.mod h1:qwmAfdCcUbpX1euHV2DziKwgGVnGw8obvOb8/JCStqM=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=
github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU=
Expand Down
43 changes: 42 additions & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package provider

import (
"context"
"errors"
"fmt"
"net/http"
"time"

"github.com/cenkalti/backoff/v5"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/provider"
Expand All @@ -18,7 +20,8 @@ import (

// Ensure SwoProvider satisfies various provider interfaces.
var (
_ provider.Provider = &swoProvider{}
_ provider.Provider = &swoProvider{}
ErrNonMatchingEntites = errors.New("updated entity properties don't match")
)

var resources = []func() resource.Resource{
Expand All @@ -33,6 +36,13 @@ var resources = []func() resource.Resource{

var dataSources = []func() datasource.DataSource{}

const (
expBackoffMaxInterval = 30 * time.Second
expBackoffMaxElapsed = 2 * time.Minute
)

type ReadOperation[T any] func(context.Context, string) (T, error)

// swoProvider defines the provider implementation.
type swoProvider struct {
// Version is set to the provider version on release, "dev" when the
Expand Down Expand Up @@ -144,3 +154,34 @@ func New(version string, transport http.RoundTripper) func() provider.Provider {
}
}
}

func BackoffRetry[T any](operation backoff.Operation[T]) (T, error) {
expBackoff := backoff.NewExponentialBackOff()
expBackoff.MaxInterval = expBackoffMaxInterval

return backoff.Retry(context.Background(), operation, backoff.WithBackOff(expBackoff), backoff.WithMaxElapsedTime(expBackoffMaxElapsed))
}

func ReadRetry[T any](ctx context.Context, id string, operation ReadOperation[T]) (T, error) {
var entity T
// Uri, and Website Creates and Updates are eventually consistant. Retry until the entity id is returned.
entity, err := BackoffRetry(func() (T, error) {
entity, err := operation(ctx, id)
if err != nil {
// The entity is still being created, retry
if errors.Is(err, swoClient.ErrEntityIdNil) {
return entity, swoClient.ErrEntityIdNil
}

return entity, backoff.Permanent(err)
}

return entity, nil
})

if err != nil {
return entity, err
}

return entity, nil
}
Loading
Loading