From 91e4dbafcf48272ca25d7e0e3fa5c0674de2fd43 Mon Sep 17 00:00:00 2001 From: Chris Marget Date: Fri, 12 Jul 2024 12:48:34 -0400 Subject: [PATCH 1/2] add provider version check --- apstra/provider.go | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/apstra/provider.go b/apstra/provider.go index 4fd14efc..8fcb8353 100644 --- a/apstra/provider.go +++ b/apstra/provider.go @@ -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" @@ -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 ( @@ -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 } @@ -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) @@ -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" From 10d656af4dc18467fd397e50ef85ef166b343f21 Mon Sep 17 00:00:00 2001 From: Chris Marget Date: Fri, 12 Jul 2024 12:52:44 -0400 Subject: [PATCH 2/2] compliance update --- Third_Party_Code/NOTICES.md | 4 ++-- Third_Party_Code/golang.org/x/exp/{constraints => }/LICENSE | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename Third_Party_Code/golang.org/x/exp/{constraints => }/LICENSE (100%) diff --git a/Third_Party_Code/NOTICES.md b/Third_Party_Code/NOTICES.md index cc6d50e4..49d4dfb9 100644 --- a/Third_Party_Code/NOTICES.md +++ b/Third_Party_Code/NOTICES.md @@ -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) diff --git a/Third_Party_Code/golang.org/x/exp/constraints/LICENSE b/Third_Party_Code/golang.org/x/exp/LICENSE similarity index 100% rename from Third_Party_Code/golang.org/x/exp/constraints/LICENSE rename to Third_Party_Code/golang.org/x/exp/LICENSE