11package security_test
22
33import (
4+ "context"
45 "encoding/json"
56 "fmt"
67 "reflect"
@@ -9,11 +10,14 @@ import (
910 "github.com/elastic/terraform-provider-elasticstack/internal/acctest"
1011 "github.com/elastic/terraform-provider-elasticstack/internal/clients"
1112 "github.com/elastic/terraform-provider-elasticstack/internal/models"
13+ "github.com/hashicorp/go-version"
1214 sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
1315 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1416 "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1517)
1618
19+ var apiKeyVersionLimit = version .Must (version .NewVersion ("8.0.0" )) // Enabled in 8.0
20+
1721func TestAccResourceSecuritApiKey (t * testing.T ) {
1822 // generate a random name
1923 apiKeyName := sdkacctest .RandStringFromCharSet (10 , sdkacctest .CharSetAlphaNum )
@@ -55,6 +59,7 @@ func TestAccResourceSecuritApiKey(t *testing.T) {
5559 resource .TestCheckResourceAttrSet ("elasticstack_elasticsearch_security_api_key.test" , "api_key" ),
5660 resource .TestCheckResourceAttrSet ("elasticstack_elasticsearch_security_api_key.test" , "encoded" ),
5761 ),
62+ SkipFunc : checkIfVersionIsUnsupported ,
5863 },
5964 },
6065 })
@@ -105,3 +110,16 @@ func checkResourceSecurityApiKeyDestroy(s *terraform.State) error {
105110 }
106111 return nil
107112}
113+
114+ func checkIfVersionIsUnsupported () (bool , error ) {
115+ client , err := clients .NewAcceptanceTestingClient ()
116+ if err != nil {
117+ return false , err
118+ }
119+ serverVersion , diags := client .ServerVersion (context .Background ())
120+ if diags .HasError () {
121+ return false , fmt .Errorf ("failed to parse the elasticsearch version %v" , diags )
122+ }
123+
124+ return serverVersion .LessThan (apiKeyVersionLimit ), nil
125+ }
0 commit comments