Skip to content

Commit

Permalink
Merge pull request #717 from Juniper/feat/548-provider-compatibility-…
Browse files Browse the repository at this point in the history
…check

Add provider version compatibility check
  • Loading branch information
chrismarget-j authored Jul 12, 2024
2 parents 7240766 + 10d656a commit 50a8351
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Third_Party_Code/NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10223,9 +10223,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```

## golang.org/x/exp/constraints
## golang.org/x/exp

* Name: golang.org/x/exp/constraints
* Name: golang.org/x/exp
* Version: v0.0.0-20240707233637-46b078467d37
* License: [BSD-3-Clause](https://cs.opensource.google/go/x/exp/+/46b07846:LICENSE)

Expand Down
File renamed without changes.
33 changes: 22 additions & 11 deletions apstra/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import (
"context"
"errors"
"fmt"
"net/http"
"os"
"runtime"
"strconv"
"strings"
"sync"
"time"

"github.com/Juniper/apstra-go-sdk/apstra"
"github.com/Juniper/terraform-provider-apstra/apstra/compatibility"
"github.com/Juniper/terraform-provider-apstra/apstra/utils"
Expand All @@ -16,13 +24,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"net/http"
"os"
"runtime"
"strconv"
"strings"
"sync"
"time"
"golang.org/x/exp/slices"
)

const (
Expand Down Expand Up @@ -311,9 +313,10 @@ func (p *Provider) Configure(ctx context.Context, req provider.ConfigureRequest,
if err != nil {
var ace apstra.ClientErr
if errors.As(err, &ace) && ace.Type() == apstra.ErrCompatibility {
resp.Diagnostics.AddError("Incompatible Apstra API Version specified.", "Possible explanation: "+
"you may be trying to use an unsupported version of the API. Setting `experimental = true` will "+
"bypass compatibility checks.")
resp.Diagnostics.AddError( // SDK incompatibility detected
err.Error(),
"You may be trying to use an unsupported version of Apstra. Setting `experimental = true` "+
"in the provider configuration block will bypass compatibility checks.")
return
}

Expand All @@ -340,6 +343,14 @@ func (p *Provider) Configure(ctx context.Context, req provider.ConfigureRequest,
return
}

if !slices.Contains(compatibility.SupportedApiVersions(), client.ApiVersion()) {
resp.Diagnostics.AddError( // provider incompatibility detected
fmt.Sprintf("Incompatible Apstra API Version %s", client.ApiVersion()),
"You may be trying to use an unsupported version of Apstra. Setting `experimental = true` "+
"in the provider configuration block will bypass compatibility checks.")
return
}

// Login after client creation so that future parallel
// workflows don't trigger TOO MANY REQUESTS threshold.
err = client.Login(ctx)
Expand Down Expand Up @@ -572,7 +583,7 @@ func (p *Provider) Resources(_ context.Context) []func() resource.Resource {
}
}

func terraformVersionWarnings(ctx context.Context, version string, diags *diag.Diagnostics) {
func terraformVersionWarnings(_ context.Context, version string, diags *diag.Diagnostics) {
const tf150warning = "" +
"You're using Terraform %s. Terraform 1.5.0 has a known issue calculating " +
"plans in certain situations. More info at: https://github.com/hashicorp/terraform/issues/33371"
Expand Down

0 comments on commit 50a8351

Please sign in to comment.