Skip to content

Commit

Permalink
data bricks workspaces managed service/disk support managed hsm key, …
Browse files Browse the repository at this point in the history
…deprecate xx_key_vault_id for cross subscription support as not required

add deprecate in 5.0 beta
  • Loading branch information
wuxu92 committed Jan 6, 2025
1 parent 76b7ef2 commit 6bab973
Show file tree
Hide file tree
Showing 5 changed files with 876 additions and 503 deletions.
50 changes: 50 additions & 0 deletions internal/customermanagedkeys/key_vault_or_managed_hsm_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ package customermanagedkeys

import (
"fmt"
"strings"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-sdk/sdk/environments"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/parse"
hsmParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/managedhsm/parse"
Expand Down Expand Up @@ -85,6 +87,48 @@ func (k *KeyVaultOrManagedHSMKey) BaseUri() string {
return ""
}

func (k *KeyVaultOrManagedHSMKey) Name() string {
if k.KeyVaultKeyId != nil {
return k.KeyVaultKeyId.Name
}

if k.ManagedHSMKeyId != nil {
return k.ManagedHSMKeyId.KeyName
}

if k.ManagedHSMKeyVersionlessId != nil {
return k.ManagedHSMKeyVersionlessId.KeyName
}

return ""
}

func (k *KeyVaultOrManagedHSMKey) Version() string {
if k.KeyVaultKeyId != nil {
return k.KeyVaultKeyId.Version
}

if k.ManagedHSMKeyId != nil {
return k.ManagedHSMKeyId.KeyVersion
}

return ""
}

// VersionPtr returns a pointer to the version string if it exists, otherwise nil.
// This is useful for resources supporting versioned and versionless keys.
func (k *KeyVaultOrManagedHSMKey) VersionPtr() *string {
if k.KeyVaultKeyId != nil && k.KeyVaultKeyId.Version != "" {
return pointer.To(k.KeyVaultKeyId.Version)
}

if k.ManagedHSMKeyId != nil {
return pointer.To(k.ManagedHSMKeyId.KeyVersion)
}

return nil
}

func parseKeyvaultID(keyRaw string, requireVersion VersionType, _ environments.Api) (*parse.NestedItemId, error) {
keyID, err := parse.ParseOptionallyVersionedNestedKeyID(keyRaw)
if err != nil {
Expand Down Expand Up @@ -197,3 +241,9 @@ func FlattenKeyVaultOrManagedHSMID(id string, hsmEnv environments.Api) (*KeyVaul

return nil, fmt.Errorf("cannot parse given id to key vault key nor managed hsm key: %s", id)
}

func FlattenKeyVaultOrManagedHSMIDByComponents(baseUri, name, version string, hsmEnv environments.Api) (*KeyVaultOrManagedHSMKey, error) {
id := fmt.Sprintf("%s/keys/%s/%s", strings.TrimRight(baseUri, "/"), name, version)
id = strings.TrimSuffix(id, "/")
return FlattenKeyVaultOrManagedHSMID(id, hsmEnv)
}
Loading

0 comments on commit 6bab973

Please sign in to comment.