Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add provider version compatibility check #717

Merged
merged 2 commits into from
Jul 12, 2024
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
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
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
Loading