Skip to content

Commit

Permalink
add version check to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fairclothjm committed Nov 4, 2024
1 parent c9d5a8e commit d8353b8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
5 changes: 4 additions & 1 deletion vault/data_source_kubernetes_auth_backend_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ func kubernetesAuthBackendConfigDataSourceRead(d *schema.ResourceData, meta inte
d.Set(consts.FieldDisableLocalCAJWT, resp.Data[consts.FieldDisableLocalCAJWT])

if provider.IsAPISupported(meta, provider.VaultVersion116) {
d.Set(fieldUseAnnotationsAsAliasMetadata, resp.Data[fieldUseAnnotationsAsAliasMetadata])
err := d.Set(fieldUseAnnotationsAsAliasMetadata, resp.Data[fieldUseAnnotationsAsAliasMetadata])
if err != nil {
return err
}
}

return nil
Expand Down
12 changes: 10 additions & 2 deletions vault/data_source_kubernetes_auth_backend_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

"github.com/hashicorp/terraform-provider-vault/internal/consts"
"github.com/hashicorp/terraform-provider-vault/internal/provider"
"github.com/hashicorp/terraform-provider-vault/testutil"
)

Expand Down Expand Up @@ -91,8 +92,6 @@ func TestAccKubernetesAuthBackendConfigDataSource_full(t *testing.T) {
consts.FieldDisableISSValidation, strconv.FormatBool(disableIssValidation)),
resource.TestCheckResourceAttr("vault_kubernetes_auth_backend_config.config",
consts.FieldDisableLocalCAJWT, strconv.FormatBool(disableLocalCaJwt)),
resource.TestCheckResourceAttr("vault_kubernetes_auth_backend_config.config",
fieldUseAnnotationsAsAliasMetadata, strconv.FormatBool(useAnnotationsAsAliasMetadata)),
),
},
{
Expand All @@ -116,6 +115,15 @@ func TestAccKubernetesAuthBackendConfigDataSource_full(t *testing.T) {
consts.FieldDisableISSValidation, strconv.FormatBool(disableIssValidation)),
resource.TestCheckResourceAttr("vault_kubernetes_auth_backend_config.config",
consts.FieldDisableLocalCAJWT, strconv.FormatBool(disableLocalCaJwt)),
),
},
{
SkipFunc: func() (bool, error) {
meta := testProvider.Meta().(*provider.ProviderMeta)
return !meta.IsAPISupported(provider.VaultVersion116), nil
},
Config: testAccKubernetesAuthBackendConfig_useAnnotations(backend, jwt),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("vault_kubernetes_auth_backend_config.config",
fieldUseAnnotationsAsAliasMetadata, strconv.FormatBool(useAnnotationsAsAliasMetadata)),
),
Expand Down
26 changes: 25 additions & 1 deletion vault/resource_kubernetes_auth_backend_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,15 @@ func TestAccKubernetesAuthBackendConfig_full(t *testing.T) {
resource.TestCheckResourceAttr(testResource, consts.FieldIssuer, "api"),
resource.TestCheckResourceAttr(testResource, consts.FieldDisableISSValidation, strconv.FormatBool(true)),
resource.TestCheckResourceAttr(testResource, consts.FieldDisableLocalCAJWT, strconv.FormatBool(true)),
),
},
{
SkipFunc: func() (bool, error) {
meta := testProvider.Meta().(*provider.ProviderMeta)
return !meta.IsAPISupported(provider.VaultVersion116), nil
},
Config: testAccKubernetesAuthBackendConfig_useAnnotations(backend, jwt),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(testResource, fieldUseAnnotationsAsAliasMetadata, strconv.FormatBool(true)),
),
},
Expand Down Expand Up @@ -421,6 +430,22 @@ resource "vault_kubernetes_auth_backend_config" "config" {
return config + "}"
}

func testAccKubernetesAuthBackendConfig_useAnnotations(backend, jwt string) string {
return fmt.Sprintf(`
resource "vault_auth_backend" "kubernetes" {
type = "kubernetes"
path = "%s"
}
resource "vault_kubernetes_auth_backend_config" "config" {
backend = vault_auth_backend.kubernetes.path
kubernetes_host = "http://example.com:443"
token_reviewer_jwt = %q
use_annotations_as_alias_metadata = true
}
`, backend, jwt)
}

func testAccKubernetesAuthBackendConfigConfig_full(backend, caCert, jwt, issuer string,
disableIssValidation, disableLocalCaJwt, omitCA bool,
) string {
Expand All @@ -444,7 +469,6 @@ resource "vault_kubernetes_auth_backend_config" "config" {
issuer = %q
disable_iss_validation = %t
disable_local_ca_jwt = %t
use_annotations_as_alias_metadata = true
}`, backend, caConfig, jwt, kubernetesPEMfile, issuer, disableIssValidation, disableLocalCaJwt)

return config
Expand Down

0 comments on commit d8353b8

Please sign in to comment.