Skip to content

Commit c20d70f

Browse files
authored
[IR-3175] Enforce minimum Terraform version of 1.0 (#172)
1 parent 412b9ee commit c20d70f

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

provider/provider.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1010
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/meta"
12+
goversion "github.com/hashicorp/go-version"
1213
"github.com/rootlyhq/terraform-provider-rootly/v2/client"
1314
)
1415

@@ -31,6 +32,7 @@ func init() {
3132
func New(version string) func() *schema.Provider {
3233
return func() *schema.Provider {
3334
p := &schema.Provider{
35+
TerraformVersion: "1.0",
3436
Schema: map[string]*schema.Schema{
3537
"api_host": {
3638
Description: "The Rootly API host. Defaults to https://api.rootly.com. Can also be sourced from the `ROOTLY_API_URL` environment variable.",
@@ -326,6 +328,15 @@ func configure(version string, p *schema.Provider) func(context.Context, *schema
326328
// Warning or errors can be collected in a slice type
327329
var diags diag.Diagnostics
328330

331+
if goversion.Must(goversion.NewVersion(p.TerraformVersion)).LessThan(goversion.Must(goversion.NewVersion("1.0"))) {
332+
diags = append(diags, diag.Diagnostic{
333+
Severity: diag.Error,
334+
Summary: "Unsupported Terraform Version",
335+
Detail: "Please upgrade Terraform to at least version 1.0.",
336+
})
337+
return nil, diags
338+
}
339+
329340
cli, err := client.NewClient(host, token, RootlyUserAgent(version))
330341
if err != nil {
331342
diags = append(diags, diag.Diagnostic{

tools/generate-provider-tpl.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1212
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1313
"github.com/hashicorp/terraform-plugin-sdk/v2/meta"
14+
goversion "github.com/hashicorp/go-version"
1415
"github.com/rootlyhq/terraform-provider-rootly/v2/client"
1516
)
1617
@@ -33,6 +34,7 @@ func init() {
3334
func New(version string) func() *schema.Provider {
3435
return func() *schema.Provider {
3536
p := &schema.Provider{
37+
TerraformVersion: "1.0",
3638
Schema: map[string]*schema.Schema {
3739
"api_host": {
3840
Description: "The Rootly API host. Defaults to https://api.rootly.com. Can also be sourced from the \`ROOTLY_API_URL\` environment variable.",
@@ -122,6 +124,15 @@ func configure(version string, p *schema.Provider) func(context.Context, *schema
122124
// Warning or errors can be collected in a slice type
123125
var diags diag.Diagnostics
124126
127+
if goversion.Must(goversion.NewVersion(p.TerraformVersion)).LessThan(goversion.Must(goversion.NewVersion("1.0"))) {
128+
diags = append(diags, diag.Diagnostic{
129+
Severity: diag.Error,
130+
Summary: "Unsupported Terraform Version",
131+
Detail: "Please upgrade Terraform to at least version 1.0.",
132+
})
133+
return nil, diags
134+
}
135+
125136
cli, err := client.NewClient(host, token, RootlyUserAgent(version))
126137
if err != nil {
127138
diags = append(diags, diag.Diagnostic{

0 commit comments

Comments
 (0)